From 833a78181b40aab345f037029d4ac13435b45fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Ho=C3=A0ng=20=C4=90=E1=BB=A9c?= Date: Sun, 28 Apr 2024 01:56:13 +0700 Subject: [PATCH] fix(server): asset count on meta tag of shared links (#9107) * fix asset count on meta tag of shared links * fix lint * fix style * add e2e tests --- e2e/src/api/specs/shared-link.e2e-spec.ts | 27 +++++++++++++++++++++- e2e/src/utils.ts | 1 + server/src/services/shared-link.service.ts | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/e2e/src/api/specs/shared-link.e2e-spec.ts b/e2e/src/api/specs/shared-link.e2e-spec.ts index 3c3fd79269..c446fe9cdb 100644 --- a/e2e/src/api/specs/shared-link.e2e-spec.ts +++ b/e2e/src/api/specs/shared-link.e2e-spec.ts @@ -9,7 +9,7 @@ import { } from '@immich/sdk'; import { createUserDto, uuidDto } from 'src/fixtures'; import { errorDto } from 'src/responses'; -import { app, asBearerAuth, utils } from 'src/utils'; +import { app, asBearerAuth, shareUrl, utils } from 'src/utils'; import request from 'supertest'; import { beforeAll, describe, expect, it } from 'vitest'; @@ -89,6 +89,31 @@ describe('/shared-link', () => { await deleteUser({ id: user2.userId, deleteUserDto: {} }, { headers: asBearerAuth(admin.accessToken) }); }); + describe('GET /share/${key}', () => { + it('should have correct asset count in meta tag for non-empty album', async () => { + const resp = await request(shareUrl).get(`/${linkWithMetadata.key}`); + expect(resp.status).toBe(200); + expect(resp.header['content-type']).toContain('text/html'); + expect(resp.text).toContain( + ``, + ); + }); + + it('should have correct asset count in meta tag for empty album', async () => { + const resp = await request(shareUrl).get(`/${linkWithAlbum.key}`); + expect(resp.status).toBe(200); + expect(resp.header['content-type']).toContain('text/html'); + expect(resp.text).toContain(``); + }); + + it('should have correct asset count in meta tag for shared asset', async () => { + const resp = await request(shareUrl).get(`/${linkWithAssets.key}`); + expect(resp.status).toBe(200); + expect(resp.header['content-type']).toContain('text/html'); + expect(resp.text).toContain(``); + }); + }); + describe('GET /shared-link', () => { it('should require authentication', async () => { const { status, body } = await request(app).get('/shared-link'); diff --git a/e2e/src/utils.ts b/e2e/src/utils.ts index ee4dad654d..5772b60217 100644 --- a/e2e/src/utils.ts +++ b/e2e/src/utils.ts @@ -53,6 +53,7 @@ type AssetData = { bytes?: Buffer; filename: string }; const dbUrl = 'postgres://postgres:postgres@127.0.0.1:5433/immich'; const baseUrl = 'http://127.0.0.1:2283'; +export const shareUrl = `${baseUrl}/share`; export const app = `${baseUrl}/api`; // TODO move test assets into e2e/assets export const testAssetDir = path.resolve(`./../server/test/assets/`); diff --git a/server/src/services/shared-link.service.ts b/server/src/services/shared-link.service.ts index cea0e84143..28c29594c2 100644 --- a/server/src/services/shared-link.service.ts +++ b/server/src/services/shared-link.service.ts @@ -185,7 +185,7 @@ export class SharedLinkService { const sharedLink = await this.findOrFail(auth.sharedLink.userId, auth.sharedLink.id); const assetId = sharedLink.album?.albumThumbnailAssetId || sharedLink.assets[0]?.id; - const assetCount = sharedLink.assets.length ?? sharedLink.album?.assets.length ?? 0; + const assetCount = sharedLink.assets.length > 0 ? sharedLink.assets.length : sharedLink.album?.assets.length || 0; return { title: sharedLink.album ? sharedLink.album.albumName : 'Public Share',