import { baseUrl } from "@/config/env" const ABSOLUTE_URL_RE = /^https?:\/\//i const isAbsoluteUrl = (path) => ABSOLUTE_URL_RE.test(path) || path.startsWith("blob:") || path.startsWith("data:") const getApiBase = () => (baseUrl || "").replace(/\/+$/, "") /** * ȥ�� VITE_BASE_URL ����ǰ׺��֧���ظ�ǰ׺�����õ�������·������ /profile/2026/... */ export const toRelativeFilePath = (path) => { if (!path) return "" if (isAbsoluteUrl(path)) return path const prefix = getApiBase() let p = path.startsWith("/") ? path : `/${path}` if (prefix) { const normalizedPrefix = prefix.startsWith("/") ? prefix : `/${prefix}` while (p === normalizedPrefix || p.startsWith(`${normalizedPrefix}/`)) { p = p.slice(normalizedPrefix.length) || "/" if (!p.startsWith("/")) p = `/${p}` } } return p } /** * ƴ��Ϊǰ�˿ɷ���·�����ݵȣ����ظ����ã����� uploader ���ԣ� */ export const toFullFileUrl = (path) => { if (!path) return "" if (isAbsoluteUrl(path)) return path const prefix = getApiBase() const relative = toRelativeFilePath(path) if (!prefix) return relative return prefix + relative }