High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
fix(server): handle 5 digit years (#6457)
Jason Rasmussen6f291006e4d4
diff --git a/server/e2e/api/specs/asset.e2e-spec.ts b/server/e2e/api/specs/asset.e2e-spec.tsindex 1aafea39dc..bd3d0a8a39 100644--- a/server/e2e/api/specs/asset.e2e-spec.ts+++ b/server/e2e/api/specs/asset.e2e-spec.ts@@ -1073,6 +1073,16 @@ describe(`${AssetController.name} (e2e)`, () => {expect(body).toEqual(errorStub.unauthorized);});+ it('should handle 5 digit years', async () => {+ const { status, body } = await request(server)+ .get('/asset/time-bucket')+ .query({ size: TimeBucketSize.MONTH, timeBucket: '+012345-01-01T00:00:00.000Z' })+ .set('Authorization', `Bearer ${user1.accessToken}`);++ expect(status).toBe(200);+ expect(body).toEqual([]);+ });+// it('should fail if time bucket is invalid', async () => {// const { status, body } = await request(server)// .get('/asset/time-bucket')diff --git a/server/src/infra/repositories/asset.repository.ts b/server/src/infra/repositories/asset.repository.tsindex edff22e4a7..f24c587571 100644--- a/server/src/infra/repositories/asset.repository.ts+++ b/server/src/infra/repositories/asset.repository.ts@@ -687,7 +687,7 @@ export class AssetRepository implements IAssetRepository {const truncated = dateTrunc(options);return (this.getBuilder(options)- .andWhere(`${truncated} = :timeBucket`, { timeBucket })+ .andWhere(`${truncated} = :timeBucket`, { timeBucket: timeBucket.replace(/^[+-]/, '') })// First sort by the day in localtime (put it in the right bucket).orderBy(truncated, 'DESC')// and then sort by the actual time@@ -757,10 +757,7 @@ export class AssetRepository implements IAssetRepository {private getBuilder(options: AssetBuilderOptions) {const { isArchived, isFavorite, isTrashed, albumId, personId, userIds, withStacked, exifInfo, assetType } = options;- let builder = this.repository- .createQueryBuilder('asset')- .where('asset.isVisible = true')- .andWhere('asset.fileCreatedAt < NOW()');+ let builder = this.repository.createQueryBuilder('asset').where('asset.isVisible = true');if (assetType !== undefined) {builder = builder.andWhere('asset.type = :assetType', { assetType });}diff --git a/server/src/infra/sql/asset.repository.sql b/server/src/infra/sql/asset.repository.sqlindex 16e13208ea..3459092730 100644--- a/server/src/infra/sql/asset.repository.sql+++ b/server/src/infra/sql/asset.repository.sql@@ -553,10 +553,7 @@ FROMLEFT JOIN "assets" "stack" ON "stack"."stackParentId" = "asset"."id"AND ("stack"."deletedAt" IS NULL)WHERE- (- "asset"."isVisible" = true- AND "asset"."fileCreatedAt" < NOW()- )+ ("asset"."isVisible" = true)AND ("asset"."deletedAt" IS NULL)GROUP BY(@@ -668,7 +665,6 @@ FROMWHERE("asset"."isVisible" = true- AND "asset"."fileCreatedAt" < NOW()AND (date_trunc('month',@@ -708,7 +704,6 @@ FROMWHERE("asset"."isVisible" = true- AND "asset"."fileCreatedAt" < NOW()AND "asset"."type" = $2AND "asset"."ownerId" IN ($3)AND "asset"."isArchived" = $4@@ -739,7 +734,6 @@ FROMWHERE("asset"."isVisible" = true- AND "asset"."fileCreatedAt" < NOW()AND "asset"."type" = $2AND "asset"."ownerId" IN ($3)AND "asset"."isArchived" = $4@@ -761,7 +755,6 @@ FROMWHERE("asset"."isVisible" = true- AND "asset"."fileCreatedAt" < NOW()AND "asset"."ownerId" IN ($1)AND "asset"."isArchived" = $2AND (