MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / resolveVaultRelativeAssetPath

Function resolveVaultRelativeAssetPath

apps/desktop/src/preload/index.ts:141–154  ·  view source on GitHub ↗
(notePath: string, href: string)

Source from the content-addressed store, hash-verified

139}
140
141function resolveVaultRelativeAssetPath(notePath: string, href: string): string | null {
142 const trimmed = href.trim()
143 if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith('//')) return null
144 if (/^[a-zA-Z][a-zA-Z\d+.-]*:/.test(trimmed)) return null
145
146 const normalizedNotePath = notePath.split(path.sep).join('/')
147 const noteDir = path.posix.dirname(normalizedNotePath)
148 const decodedHref = decodeHrefPath(trimmed)
149 const relativeTarget = decodedHref.startsWith('/')
150 ? decodedHref.replace(/^\/+/, '')
151 : path.posix.normalize(path.posix.join(noteDir === '.' ? '' : noteDir, decodedHref))
152 if (relativeTarget === '..' || relativeTarget.startsWith('../')) return null
153 return relativeTarget
154}
155
156function remoteAssetUrl(assetPath: string): string | null {
157 if (remoteWorkspaceInfo?.mode !== 'remote' || !remoteWorkspaceInfo.baseUrl) return null

Callers 1

index.tsFile · 0.85

Calls 1

decodeHrefPathFunction · 0.70

Tested by

no test coverage detected