Files
edr-platform/apps/edr-freight-web/portal/src/constants/apiConfig.ts
2026-09-04 22:54:25 +03:00

24 lines
1.0 KiB
TypeScript

export const API_BASE_URL = import.meta.env.VITE_BASE_API_URL;
/**
* URL that streams an uploaded file through the API by its UUID. Routes the
* bytes through `GET /api/files/:id` (served from MinIO with backend
* credentials) instead of a presigned MinIO URL — the latter is not reachable
* from the browser and breaks on the minio-js port-443 signature quirk. Serves
* inline for preview by default; pass `download` to force a save dialog.
*/
export function fileViewUrl(fileId: string, download = false): string {
const base = `${API_BASE_URL}/api/files/${fileId}`;
return download ? `${base}?download=1` : base;
}
/**
* URL that streams a public publication's file through the API by its UUID.
* Same reasoning as `fileViewUrl`: a presigned MinIO URL is not reachable from
* the browser here, so the bytes are streamed through the API instead.
*/
export function publicationFileUrl(id: string, download = false): string {
const base = `${API_BASE_URL}/api/publications/${id}/file`;
return download ? `${base}?download=1` : base;
}