Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.
TypeScript albumsexif-extractiongeocodinglive-photomotion-photophoto-galleryphoto-sharingwebgl-viewer
refactor(social-links): share duplicate identity logic
Ahmet Ömer69554d42d98d
diff --git a/packages/console/app/pages/dashboard/settings/general.vue b/packages/console/app/pages/dashboard/settings/general.vueindex 259c3169..cee731f8 100644--- a/packages/console/app/pages/dashboard/settings/general.vue+++ b/packages/console/app/pages/dashboard/settings/general.vue@@ -2,9 +2,9 @@import { settingsFieldCommitKey } from '#console/composables/useSettingsForm'import {MAX_SOCIAL_LINKS,- parseSocialLink,parseSocialLinks,resolveSocialPlatform,+ socialLinkIdentity,SocialLinkError,} from '@chronoframe/contracts/social-links'@@ -60,8 +60,7 @@ const socialErrors = computed(() => {return socialDraft.value.map((value) => {if (!value.trim()) return ''try {- const url = parseSocialLink(value.trim())- const identity = `${url.origin}${url.pathname.replace(/\/+$/, '')}`+ const identity = socialLinkIdentity(value.trim())if (seen.has(identity)) return t('settings.app.socialLinks.duplicate')seen.add(identity)return ''diff --git a/packages/contracts/src/social-links.ts b/packages/contracts/src/social-links.tsindex 2d9527f4..937bcab5 100644--- a/packages/contracts/src/social-links.ts+++ b/packages/contracts/src/social-links.ts@@ -70,6 +70,11 @@ export function parseSocialLink(value: unknown): URL {return url}+export function socialLinkIdentity(value: unknown): string {+ const url = parseSocialLink(value)+ return `${url.origin}${url.pathname.replace(/\/+$/, '')}`+}+export function parseSocialLinks(value: unknown): string[] {if (!value ||@@ -88,9 +93,7 @@ export function parseSocialLinks(value: unknown): string[] {const seen = new Set<string>()return links.map((link) => {- const url = parseSocialLink(link)- const path = url.pathname.replace(/\/+$/, '')- const identity = `${url.origin}${path}`+ const identity = socialLinkIdentity(link)if (seen.has(identity))throw new SocialLinkError('duplicate', 'Duplicate social link')seen.add(identity)diff --git a/tests/social-links.test.ts b/tests/social-links.test.tsindex f07001a6..514ea3c1 100644--- a/tests/social-links.test.ts+++ b/tests/social-links.test.ts@@ -3,6 +3,7 @@ import test from 'node:test'import {parseSocialLinks,resolveSocialPlatform,+ socialLinkIdentity,} from '@chronoframe/contracts/social-links'import { validateSettingWrite } from '@chronoframe/core'@@ -47,6 +48,23 @@ test('rejects unsafe, malformed and duplicate social links', () => {)})+test('duplicate identity ignores query, fragment and trailing slash but keeps the hostname', () => {+ const first = 'https://example.com/a?x=1#top'+ const queryVariant = 'https://example.com/a/?x=2#bottom'+ const withWww = 'https://www.example.com/a'++ assert.equal(socialLinkIdentity(first), socialLinkIdentity(queryVariant))+ assert.notEqual(socialLinkIdentity(first), socialLinkIdentity(withWww))+ assert.throws(+ () => parseSocialLinks({ links: [first, queryVariant] }),+ /duplicate/i,+ )+ assert.deepEqual(parseSocialLinks({ links: [first, withWww] }), [+ first,+ withWww,+ ])+})+test('settings write validation enforces the social-link contract', () => {const input = {namespace: 'app',