MCPcopy
hub / github.com/directus/directus / toRelativePath

Function toRelativePath

app/src/composables/use-safe-redirect.ts:19–37  ·  view source on GitHub ↗
(resolved: string | null)

Source from the content-addressed store, hash-verified

17 }
18
19 function toRelativePath(resolved: string | null): string | null {
20 if (!resolved) return null;
21
22 // Only attempt conversion for absolute URLs
23 if (/^https?:\/\//.test(resolved) === false) return resolved;
24
25 try {
26 const resolvedUrl = new URL(resolved);
27 const publicBase = new URL(getPublicURL());
28
29 if (resolvedUrl.protocol === publicBase.protocol && resolvedUrl.host === publicBase.host) {
30 return extractPath(resolvedUrl.toString());
31 }
32 } catch {
33 // Not a valid URL, return as-is
34 }
35
36 return resolved;
37 }
38
39 return { redirect, resolveRedirect };
40}

Callers 1

resolveRedirectFunction · 0.85

Calls 3

getPublicURLFunction · 0.90
extractPathFunction · 0.90
toStringMethod · 0.45

Tested by

no test coverage detected