Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix(contracts): keep DOM types out of core compilation

Ahmet Ömer9461c9c70add
diff --git a/packages/contracts/src/social-links.ts b/packages/contracts/src/social-links.ts
index b4a60026..f5e63ec4 100644
--- a/packages/contracts/src/social-links.ts
+++ b/packages/contracts/src/social-links.ts
@@ -1,7 +1,17 @@
-/// <reference lib="dom" />
-
export const MAX_SOCIAL_LINKS = 4
+type ParsedSocialLinkUrl = {
+ href: string
+ protocol: string
+ username: string
+ password: string
+ hostname: string
+ origin: string
+ pathname: string
+}
+
+declare const URL: new (value: string) => ParsedSocialLinkUrl
+
export type SocialLinkErrorCode = 'shape' | 'limit' | 'invalid' | 'duplicate'
export function isSocialLinkErrorCode(
@@ -26,7 +36,11 @@ export class SocialLinkError extends Error {
}
/** Validate HTTPS profile URL syntax without checking host reachability. */
-export function parseSocialLink(value: unknown): URL {
+export function parseSocialLink(value: unknown): string {
+ return parseSocialLinkUrl(value).href
+}
+
+function parseSocialLinkUrl(value: unknown): ParsedSocialLinkUrl {
if (
typeof value !== 'string' ||
value.length === 0 ||
@@ -40,7 +54,7 @@ export function parseSocialLink(value: unknown): URL {
throw new SocialLinkError('invalid', 'Enter a valid HTTPS URL')
}
- let url: URL
+ let url: ParsedSocialLinkUrl
try {
url = new URL(value)
} catch {
@@ -71,7 +85,7 @@ export function parseSocialLink(value: unknown): URL {
}
export function socialLinkIdentity(value: unknown): string {
- const url = parseSocialLink(value)
+ const url = parseSocialLinkUrl(value)
return `${url.origin}${url.pathname.replace(/\/+$/, '')}`
}
@@ -178,7 +192,7 @@ export function resolveSocialPlatform(value: string): {
} {
let hostname: string
try {
- hostname = parseSocialLink(value).hostname
+ hostname = parseSocialLinkUrl(value).hostname
} catch {
return { label: 'Link', icon: 'tabler:link' }
}
diff --git a/tests/social-links.test.ts b/tests/social-links.test.ts
index a381aaef..afaba198 100644
--- a/tests/social-links.test.ts
+++ b/tests/social-links.test.ts
@@ -55,7 +55,7 @@ test('validates HTTPS URL syntax without requiring a reachable public host', ()
'https://example.example/profile',
'https://foo.onion/profile',
]) {
- assert.equal(parseSocialLink(link).href, link)
+ assert.equal(parseSocialLink(link), link)
}
})