Fix links

This commit is contained in:
SepehrYahyaee
2026-06-13 17:24:25 +03:30
parent 3e5e9852ad
commit 6426233350
9 changed files with 78 additions and 20 deletions

View File

@@ -9,6 +9,7 @@ import {
} from "./outer-damage-parts";
import { ClaimVehicleTypeV2 } from "src/static/outer-car-parts-catalog";
import { canonicalizeResendDocumentKey } from "./claim-resend-document-keys";
import { resolveStoredFileUrl } from "./urlCreator";
export type ExpertResendCarPartV2 = {
id?: number | null;
@@ -161,8 +162,7 @@ export function mapExpertResendCarPartsForClient(
const capturedFromStore =
typeof stored.captured === "boolean" ? stored.captured : undefined;
const url =
cap?.url ||
(cap?.path && options.buildUrl ? options.buildUrl(cap.path) : undefined);
resolveStoredFileUrl(cap);
return {
id: sp.id,

View File

@@ -1,9 +1,38 @@
type StoredFileCapture = {
url?: string;
path?: string;
};
/**
* Build a public file URL from a relative storage path (e.g. `files/...`).
* Uses the current `URL` env so deployments with custom routing stay correct.
*/
export function buildFileLink(path: string): string {
const baseUrl = process.env.URL;
if(process.env.NODE_ENV === 'local'){
return baseUrl + "/" + path;
}else{
return baseUrl + "/api/" + path;
const normalized = String(path ?? "").trim();
if (!normalized) return normalized;
if (/^https?:\/\//i.test(normalized)) {
return normalized;
}
const baseUrl = (process.env.URL ?? "").replace(/\/+$/, "");
const relativePath = normalized.replace(/^\/+/, "");
if (process.env.NODE_ENV === "local") {
return `${baseUrl}/${relativePath}`;
}
return `${baseUrl}/api/${relativePath}`;
}
/**
* Resolve a file URL from persisted capture metadata.
* Prefer rebuilding from `path` so stale baked-in URLs (e.g. user-portal prefix)
* do not leak into expert/other API responses.
*/
export function resolveStoredFileUrl(
stored?: StoredFileCapture | null,
): string | undefined {
const path = stored?.path?.trim();
if (path) {
return buildFileLink(path);
}
return stored?.url;
}