mirror of
https://github.com/samsonjs/immich.git
synced 2026-04-27 15:07:45 +00:00
fix(web): properly encode shared link slug (#25564)
This commit is contained in:
parent
7cedb5ea04
commit
212c03ceff
2 changed files with 25 additions and 2 deletions
21
web/src/lib/services/shared-link.service.spec.ts
Normal file
21
web/src/lib/services/shared-link.service.spec.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { asUrl } from '$lib/services/shared-link.service';
|
||||||
|
import type { ServerConfigDto } from '@immich/sdk';
|
||||||
|
import { sharedLinkFactory } from '@test-data/factories/shared-link-factory';
|
||||||
|
|
||||||
|
describe('SharedLinkService', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
vi.mock(import('$lib/managers/server-config-manager.svelte'), () => ({
|
||||||
|
serverConfigManager: {
|
||||||
|
value: { externalDomain: 'http://localhost:2283' } as ServerConfigDto,
|
||||||
|
init: vi.fn(),
|
||||||
|
loadServerConfig: vi.fn(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('asUrl', () => {
|
||||||
|
it('should properly encode characters in slug', () => {
|
||||||
|
expect(asUrl(sharedLinkFactory.build({ slug: 'foo/bar' }))).toBe('http://localhost:2283/s/foo%2Fbar');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -60,8 +60,10 @@ export const getSharedLinkActions = ($t: MessageFormatter, sharedLink: SharedLin
|
||||||
return { Edit, Delete, Copy, ViewQrCode };
|
return { Edit, Delete, Copy, ViewQrCode };
|
||||||
};
|
};
|
||||||
|
|
||||||
const asUrl = (sharedLink: SharedLinkResponseDto) => {
|
export const asUrl = (sharedLink: SharedLinkResponseDto) => {
|
||||||
const path = sharedLink.slug ? `s/${sharedLink.slug}` : `share/${sharedLink.key}`;
|
const path = sharedLink.slug
|
||||||
|
? `s/${encodeURIComponent(sharedLink.slug)}`
|
||||||
|
: `share/${encodeURIComponent(sharedLink.key)}`;
|
||||||
return new URL(path, serverConfigManager.value.externalDomain || globalThis.location.origin).href;
|
return new URL(path, serverConfigManager.value.externalDomain || globalThis.location.origin).href;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue