diff --git a/mobile/openapi/README.md b/mobile/openapi/README.md index 81827a9079..36f442fd88 100644 Binary files a/mobile/openapi/README.md and b/mobile/openapi/README.md differ diff --git a/mobile/openapi/lib/api.dart b/mobile/openapi/lib/api.dart index 8be4402980..6fb7478d04 100644 Binary files a/mobile/openapi/lib/api.dart and b/mobile/openapi/lib/api.dart differ diff --git a/mobile/openapi/lib/api/server_api.dart b/mobile/openapi/lib/api/server_api.dart index bde8d595b6..7a832ad61a 100644 Binary files a/mobile/openapi/lib/api/server_api.dart and b/mobile/openapi/lib/api/server_api.dart differ diff --git a/mobile/openapi/lib/api_client.dart b/mobile/openapi/lib/api_client.dart index 9e38eaf30a..c1025b0bd4 100644 Binary files a/mobile/openapi/lib/api_client.dart and b/mobile/openapi/lib/api_client.dart differ diff --git a/mobile/openapi/lib/model/server_version_history_response_dto.dart b/mobile/openapi/lib/model/server_version_history_response_dto.dart new file mode 100644 index 0000000000..c81cb0e8b9 Binary files /dev/null and b/mobile/openapi/lib/model/server_version_history_response_dto.dart differ diff --git a/open-api/immich-openapi-specs.json b/open-api/immich-openapi-specs.json index 665b50420c..d28effd6c5 100644 --- a/open-api/immich-openapi-specs.json +++ b/open-api/immich-openapi-specs.json @@ -5088,6 +5088,30 @@ ] } }, + "/server/version-history": { + "get": { + "operationId": "getVersionHistory", + "parameters": [], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "items": { + "$ref": "#/components/schemas/ServerVersionHistoryResponseDto" + }, + "type": "array" + } + } + }, + "description": "" + } + }, + "tags": [ + "Server" + ] + } + }, "/sessions": { "delete": { "operationId": "deleteAllSessions", @@ -11042,6 +11066,26 @@ ], "type": "object" }, + "ServerVersionHistoryResponseDto": { + "properties": { + "createdAt": { + "format": "date-time", + "type": "string" + }, + "id": { + "type": "string" + }, + "version": { + "type": "string" + } + }, + "required": [ + "createdAt", + "id", + "version" + ], + "type": "object" + }, "ServerVersionResponseDto": { "properties": { "major": { diff --git a/open-api/typescript-sdk/src/fetch-client.ts b/open-api/typescript-sdk/src/fetch-client.ts index 40328718bb..4f5eed0d13 100644 --- a/open-api/typescript-sdk/src/fetch-client.ts +++ b/open-api/typescript-sdk/src/fetch-client.ts @@ -1000,6 +1000,11 @@ export type ServerVersionResponseDto = { minor: number; patch: number; }; +export type ServerVersionHistoryResponseDto = { + createdAt: string; + id: string; + version: string; +}; export type SessionResponseDto = { createdAt: string; current: boolean; @@ -2667,6 +2672,14 @@ export function getServerVersion(opts?: Oazapfts.RequestOpts) { ...opts })); } +export function getVersionHistory(opts?: Oazapfts.RequestOpts) { + return oazapfts.ok(oazapfts.fetchJson<{ + status: 200; + data: ServerVersionHistoryResponseDto[]; + }>("/server/version-history", { + ...opts + })); +} export function deleteAllSessions(opts?: Oazapfts.RequestOpts) { return oazapfts.ok(oazapfts.fetchText("/sessions", { ...opts, diff --git a/server/src/controllers/server.controller.ts b/server/src/controllers/server.controller.ts index 8fcd93946e..8327ff6d1d 100644 --- a/server/src/controllers/server.controller.ts +++ b/server/src/controllers/server.controller.ts @@ -10,6 +10,7 @@ import { ServerStatsResponseDto, ServerStorageResponseDto, ServerThemeDto, + ServerVersionHistoryResponseDto, ServerVersionResponseDto, } from 'src/dtos/server.dto'; import { Authenticated } from 'src/middleware/auth.guard'; @@ -46,6 +47,11 @@ export class ServerController { return this.versionService.getVersion(); } + @Get('version-history') + getVersionHistory(): Promise { + return this.versionService.getVersionHistory(); + } + @Get('features') getServerFeatures(): Promise { return this.service.getFeatures(); diff --git a/server/src/dtos/server.dto.ts b/server/src/dtos/server.dto.ts index 3d21987ccf..e540483351 100644 --- a/server/src/dtos/server.dto.ts +++ b/server/src/dtos/server.dto.ts @@ -68,6 +68,12 @@ export class ServerVersionResponseDto { } } +export class ServerVersionHistoryResponseDto { + id!: string; + createdAt!: Date; + version!: string; +} + export class UsageByUserDto { @ApiProperty({ type: 'string' }) userId!: string; diff --git a/server/src/entities/index.ts b/server/src/entities/index.ts index 0b7ca8c3bd..7425ee67d8 100644 --- a/server/src/entities/index.ts +++ b/server/src/entities/index.ts @@ -25,6 +25,7 @@ import { SystemMetadataEntity } from 'src/entities/system-metadata.entity'; import { TagEntity } from 'src/entities/tag.entity'; import { UserMetadataEntity } from 'src/entities/user-metadata.entity'; import { UserEntity } from 'src/entities/user.entity'; +import { VersionHistoryEntity } from 'src/entities/version-history.entity'; export const entities = [ ActivityEntity, @@ -54,4 +55,5 @@ export const entities = [ UserMetadataEntity, SessionEntity, LibraryEntity, + VersionHistoryEntity, ]; diff --git a/server/src/entities/version-history.entity.ts b/server/src/entities/version-history.entity.ts new file mode 100644 index 0000000000..edccd9aed6 --- /dev/null +++ b/server/src/entities/version-history.entity.ts @@ -0,0 +1,13 @@ +import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm'; + +@Entity('version_history') +export class VersionHistoryEntity { + @PrimaryGeneratedColumn('uuid') + id!: string; + + @CreateDateColumn({ type: 'timestamptz' }) + createdAt!: Date; + + @Column() + version!: string; +} diff --git a/server/src/interfaces/database.interface.ts b/server/src/interfaces/database.interface.ts index 51b39b95a8..e388f354f2 100644 --- a/server/src/interfaces/database.interface.ts +++ b/server/src/interfaces/database.interface.ts @@ -17,6 +17,7 @@ export enum DatabaseLock { Migrations = 200, SystemFileMounts = 300, StorageTemplateMigration = 420, + VersionHistory = 500, CLIPDimSize = 512, LibraryWatch = 1337, GetSystemConfig = 69, diff --git a/server/src/interfaces/version-history.interface.ts b/server/src/interfaces/version-history.interface.ts new file mode 100644 index 0000000000..6733706220 --- /dev/null +++ b/server/src/interfaces/version-history.interface.ts @@ -0,0 +1,9 @@ +import { VersionHistoryEntity } from 'src/entities/version-history.entity'; + +export const IVersionHistoryRepository = 'IVersionHistoryRepository'; + +export interface IVersionHistoryRepository { + create(version: Omit): Promise; + getAll(): Promise; + getLatest(): Promise; +} diff --git a/server/src/migrations/1727797340951-AddVersionHistory.ts b/server/src/migrations/1727797340951-AddVersionHistory.ts new file mode 100644 index 0000000000..7eb731d1a3 --- /dev/null +++ b/server/src/migrations/1727797340951-AddVersionHistory.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddVersionHistory1727797340951 implements MigrationInterface { + name = 'AddVersionHistory1727797340951' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE "version_history" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "version" character varying NOT NULL, CONSTRAINT "PK_5db259cbb09ce82c0d13cfd1b23" PRIMARY KEY ("id"))`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "version_history"`); + } + +} diff --git a/server/src/repositories/index.ts b/server/src/repositories/index.ts index fac250d667..5da4f678d3 100644 --- a/server/src/repositories/index.ts +++ b/server/src/repositories/index.ts @@ -32,6 +32,7 @@ import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interf import { ITagRepository } from 'src/interfaces/tag.interface'; import { ITrashRepository } from 'src/interfaces/trash.interface'; import { IUserRepository } from 'src/interfaces/user.interface'; +import { IVersionHistoryRepository } from 'src/interfaces/version-history.interface'; import { IViewRepository } from 'src/interfaces/view.interface'; import { AccessRepository } from 'src/repositories/access.repository'; import { ActivityRepository } from 'src/repositories/activity.repository'; @@ -67,6 +68,7 @@ import { SystemMetadataRepository } from 'src/repositories/system-metadata.repos import { TagRepository } from 'src/repositories/tag.repository'; import { TrashRepository } from 'src/repositories/trash.repository'; import { UserRepository } from 'src/repositories/user.repository'; +import { VersionHistoryRepository } from 'src/repositories/version-history.repository'; import { ViewRepository } from 'src/repositories/view-repository'; export const repositories = [ @@ -104,5 +106,6 @@ export const repositories = [ { provide: ITagRepository, useClass: TagRepository }, { provide: ITrashRepository, useClass: TrashRepository }, { provide: IUserRepository, useClass: UserRepository }, + { provide: IVersionHistoryRepository, useClass: VersionHistoryRepository }, { provide: IViewRepository, useClass: ViewRepository }, ]; diff --git a/server/src/repositories/version-history.repository.ts b/server/src/repositories/version-history.repository.ts new file mode 100644 index 0000000000..26c638bd76 --- /dev/null +++ b/server/src/repositories/version-history.repository.ts @@ -0,0 +1,25 @@ +import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { VersionHistoryEntity } from 'src/entities/version-history.entity'; +import { IVersionHistoryRepository } from 'src/interfaces/version-history.interface'; +import { Instrumentation } from 'src/utils/instrumentation'; +import { Repository } from 'typeorm'; + +@Instrumentation() +@Injectable() +export class VersionHistoryRepository implements IVersionHistoryRepository { + constructor(@InjectRepository(VersionHistoryEntity) private repository: Repository) {} + + async getAll(): Promise { + return this.repository.find({ order: { createdAt: 'DESC' } }); + } + + async getLatest(): Promise { + const results = await this.repository.find({ order: { createdAt: 'DESC' }, take: 1 }); + return results[0] || null; + } + + create(version: Omit): Promise { + return this.repository.save(version); + } +} diff --git a/server/src/services/version.service.spec.ts b/server/src/services/version.service.spec.ts index 02dfe7588f..a611ae5ecc 100644 --- a/server/src/services/version.service.spec.ts +++ b/server/src/services/version.service.spec.ts @@ -1,17 +1,21 @@ import { DateTime } from 'luxon'; import { serverVersion } from 'src/constants'; import { SystemMetadataKey } from 'src/enum'; +import { IDatabaseRepository } from 'src/interfaces/database.interface'; import { IEventRepository } from 'src/interfaces/event.interface'; import { IJobRepository, JobName, JobStatus } from 'src/interfaces/job.interface'; import { ILoggerRepository } from 'src/interfaces/logger.interface'; import { IServerInfoRepository } from 'src/interfaces/server-info.interface'; import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface'; +import { IVersionHistoryRepository } from 'src/interfaces/version-history.interface'; import { VersionService } from 'src/services/version.service'; +import { newDatabaseRepositoryMock } from 'test/repositories/database.repository.mock'; import { newEventRepositoryMock } from 'test/repositories/event.repository.mock'; import { newJobRepositoryMock } from 'test/repositories/job.repository.mock'; import { newLoggerRepositoryMock } from 'test/repositories/logger.repository.mock'; import { newServerInfoRepositoryMock } from 'test/repositories/server-info.repository.mock'; import { newSystemMetadataRepositoryMock } from 'test/repositories/system-metadata.repository.mock'; +import { newVersionHistoryRepositoryMock } from 'test/repositories/version-history.repository.mock'; import { Mocked } from 'vitest'; const mockRelease = (version: string) => ({ @@ -26,26 +30,47 @@ const mockRelease = (version: string) => ({ describe(VersionService.name, () => { let sut: VersionService; + let databaseMock: Mocked; let eventMock: Mocked; let jobMock: Mocked; let serverMock: Mocked; let systemMock: Mocked; + let versionMock: Mocked; let loggerMock: Mocked; beforeEach(() => { + databaseMock = newDatabaseRepositoryMock(); eventMock = newEventRepositoryMock(); jobMock = newJobRepositoryMock(); serverMock = newServerInfoRepositoryMock(); systemMock = newSystemMetadataRepositoryMock(); + versionMock = newVersionHistoryRepositoryMock(); loggerMock = newLoggerRepositoryMock(); - sut = new VersionService(eventMock, jobMock, serverMock, systemMock, loggerMock); + sut = new VersionService(databaseMock, eventMock, jobMock, serverMock, systemMock, versionMock, loggerMock); }); it('should work', () => { expect(sut).toBeDefined(); }); + describe('onBootstrap', () => { + it('should record a new version', async () => { + await expect(sut.onBootstrap()).resolves.toBeUndefined(); + expect(versionMock.create).toHaveBeenCalledWith({ version: expect.any(String) }); + }); + + it('should skip a duplicate version', async () => { + versionMock.getLatest.mockResolvedValue({ + id: 'version-1', + createdAt: new Date(), + version: serverVersion.toString(), + }); + await expect(sut.onBootstrap()).resolves.toBeUndefined(); + expect(versionMock.create).not.toHaveBeenCalled(); + }); + }); + describe('getVersion', () => { it('should respond the server version', () => { expect(sut.getVersion()).toEqual({ @@ -56,6 +81,14 @@ describe(VersionService.name, () => { }); }); + describe('getVersionHistory', () => { + it('should respond the server version history', async () => { + const upgrade = { id: 'upgrade-1', createdAt: new Date(), version: '1.0.0' }; + versionMock.getAll.mockResolvedValue([upgrade]); + await expect(sut.getVersionHistory()).resolves.toEqual([upgrade]); + }); + }); + describe('handQueueVersionCheck', () => { it('should queue a version check job', async () => { await expect(sut.handleQueueVersionCheck()).resolves.toBeUndefined(); diff --git a/server/src/services/version.service.ts b/server/src/services/version.service.ts index 0479faaed0..92bbb3c06d 100644 --- a/server/src/services/version.service.ts +++ b/server/src/services/version.service.ts @@ -6,11 +6,13 @@ import { OnEvent } from 'src/decorators'; import { ReleaseNotification, ServerVersionResponseDto } from 'src/dtos/server.dto'; import { VersionCheckMetadata } from 'src/entities/system-metadata.entity'; import { SystemMetadataKey } from 'src/enum'; +import { DatabaseLock, IDatabaseRepository } from 'src/interfaces/database.interface'; import { ArgOf, IEventRepository } from 'src/interfaces/event.interface'; import { IJobRepository, JobName, JobStatus } from 'src/interfaces/job.interface'; import { ILoggerRepository } from 'src/interfaces/logger.interface'; import { IServerInfoRepository } from 'src/interfaces/server-info.interface'; import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface'; +import { IVersionHistoryRepository } from 'src/interfaces/version-history.interface'; import { BaseService } from 'src/services/base.service'; const asNotification = ({ checkedAt, releaseVersion }: VersionCheckMetadata): ReleaseNotification => { @@ -25,10 +27,12 @@ const asNotification = ({ checkedAt, releaseVersion }: VersionCheckMetadata): Re @Injectable() export class VersionService extends BaseService { constructor( + @Inject(IDatabaseRepository) private databaseRepository: IDatabaseRepository, @Inject(IEventRepository) private eventRepository: IEventRepository, @Inject(IJobRepository) private jobRepository: IJobRepository, @Inject(IServerInfoRepository) private repository: IServerInfoRepository, @Inject(ISystemMetadataRepository) systemMetadataRepository: ISystemMetadataRepository, + @Inject(IVersionHistoryRepository) private versionRepository: IVersionHistoryRepository, @Inject(ILoggerRepository) logger: ILoggerRepository, ) { super(systemMetadataRepository, logger); @@ -38,12 +42,25 @@ export class VersionService extends BaseService { @OnEvent({ name: 'app.bootstrap' }) async onBootstrap(): Promise { await this.handleVersionCheck(); + + await this.databaseRepository.withLock(DatabaseLock.VersionHistory, async () => { + const latest = await this.versionRepository.getLatest(); + const current = serverVersion.toString(); + if (!latest || latest.version !== current) { + this.logger.log(`Version has changed, adding ${current} to history`); + await this.versionRepository.create({ version: current }); + } + }); } getVersion() { return ServerVersionResponseDto.fromSemVer(serverVersion); } + getVersionHistory() { + return this.versionRepository.getAll(); + } + async handleQueueVersionCheck() { await this.jobRepository.queue({ name: JobName.VERSION_CHECK, data: {} }); } diff --git a/server/test/repositories/version-history.repository.mock.ts b/server/test/repositories/version-history.repository.mock.ts new file mode 100644 index 0000000000..7c35e316d3 --- /dev/null +++ b/server/test/repositories/version-history.repository.mock.ts @@ -0,0 +1,10 @@ +import { IVersionHistoryRepository } from 'src/interfaces/version-history.interface'; +import { Mocked, vitest } from 'vitest'; + +export const newVersionHistoryRepositoryMock = (): Mocked => { + return { + getAll: vitest.fn().mockResolvedValue([]), + getLatest: vitest.fn(), + create: vitest.fn(), + }; +}; diff --git a/web/src/lib/components/shared-components/server-about-modal.svelte b/web/src/lib/components/shared-components/server-about-modal.svelte index d347170033..6a524331c2 100644 --- a/web/src/lib/components/shared-components/server-about-modal.svelte +++ b/web/src/lib/components/shared-components/server-about-modal.svelte @@ -1,19 +1,19 @@ -
+
{/if} + +
+ +
    + {#each versions.slice(0, 5) as item (item.id)} + {@const createdAt = DateTime.fromISO(item.createdAt)} +
  • + + {$t('version_history_item', { + values: { + version: item.version, + date: createdAt.toLocaleString({ + month: 'short', + day: 'numeric', + year: 'numeric', + }), + }, + })} + +
  • + {/each} +
+
diff --git a/web/src/lib/components/shared-components/side-bar/server-status.svelte b/web/src/lib/components/shared-components/side-bar/server-status.svelte index 83ed98584a..f07835a957 100644 --- a/web/src/lib/components/shared-components/side-bar/server-status.svelte +++ b/web/src/lib/components/shared-components/side-bar/server-status.svelte @@ -4,7 +4,12 @@ import { requestServerInfo } from '$lib/utils/auth'; import { onMount } from 'svelte'; import { t } from 'svelte-i18n'; - import { getAboutInfo, type ServerAboutResponseDto } from '@immich/sdk'; + import { + getAboutInfo, + getVersionHistory, + type ServerAboutResponseDto, + type ServerVersionHistoryResponseDto, + } from '@immich/sdk'; const { serverVersion, connected } = websocketStore; @@ -12,16 +17,17 @@ $: version = $serverVersion ? `v${$serverVersion.major}.${$serverVersion.minor}.${$serverVersion.patch}` : null; - let aboutInfo: ServerAboutResponseDto; + let info: ServerAboutResponseDto; + let versions: ServerVersionHistoryResponseDto[] = []; onMount(async () => { await requestServerInfo(); - aboutInfo = await getAboutInfo(); + [info, versions] = await Promise.all([getAboutInfo(), getVersionHistory()]); }); {#if isOpen} - (isOpen = false)} info={aboutInfo} /> + (isOpen = false)} {info} {versions} /> {/if}
- import ServerAboutModal from '$lib/components/shared-components/server-about-modal.svelte'; import { locale } from '$lib/stores/preferences.store'; import { serverInfo } from '$lib/stores/server-info.store'; import { user } from '$lib/stores/user.store'; @@ -8,18 +7,14 @@ import { t } from 'svelte-i18n'; import { getByteUnitString } from '../../../utils/byte-units'; import LoadingSpinner from '../loading-spinner.svelte'; - import { getAboutInfo, type ServerAboutResponseDto } from '@immich/sdk'; let usageClasses = ''; - let isOpen = false; $: hasQuota = $user?.quotaSizeInBytes !== null; $: availableBytes = (hasQuota ? $user?.quotaSizeInBytes : $serverInfo?.diskSizeRaw) || 0; $: usedBytes = (hasQuota ? $user?.quotaUsageInBytes : $serverInfo?.diskUseRaw) || 0; $: usedPercentage = Math.min(Math.round((usedBytes / availableBytes) * 100), 100); - let aboutInfo: ServerAboutResponseDto; - const onUpdate = () => { usageClasses = getUsageClass(); }; @@ -42,14 +37,9 @@ onMount(async () => { await requestServerInfo(); - aboutInfo = await getAboutInfo(); }); -{#if isOpen} - (isOpen = false)} info={aboutInfo} /> -{/if} -