mirror of
https://github.com/immich-app/immich.git
synced 2025-06-16 21:38:28 +02:00
feat: version check endpoint (#18572)
This commit is contained in:
parent
ef060e97b6
commit
5268dc4ee2
13 changed files with 338 additions and 1 deletions
server/src
|
@ -1,5 +1,6 @@
|
|||
import { ServerController } from 'src/controllers/server.controller';
|
||||
import { ServerService } from 'src/services/server.service';
|
||||
import { SystemMetadataService } from 'src/services/system-metadata.service';
|
||||
import { VersionService } from 'src/services/version.service';
|
||||
import request from 'supertest';
|
||||
import { ControllerContext, controllerSetup, mockBaseService } from 'test/utils';
|
||||
|
@ -7,11 +8,13 @@ import { ControllerContext, controllerSetup, mockBaseService } from 'test/utils'
|
|||
describe(ServerController.name, () => {
|
||||
let ctx: ControllerContext;
|
||||
const serverService = mockBaseService(ServerService);
|
||||
const systemMetadataService = mockBaseService(SystemMetadataService);
|
||||
const versionService = mockBaseService(VersionService);
|
||||
|
||||
beforeAll(async () => {
|
||||
ctx = await controllerSetup(ServerController, [
|
||||
{ provide: ServerService, useValue: serverService },
|
||||
{ provide: SystemMetadataService, useValue: systemMetadataService },
|
||||
{ provide: VersionService, useValue: versionService },
|
||||
]);
|
||||
return () => ctx.close();
|
||||
|
|
|
@ -13,8 +13,10 @@ import {
|
|||
ServerVersionHistoryResponseDto,
|
||||
ServerVersionResponseDto,
|
||||
} from 'src/dtos/server.dto';
|
||||
import { VersionCheckStateResponseDto } from 'src/dtos/system-metadata.dto';
|
||||
import { Authenticated } from 'src/middleware/auth.guard';
|
||||
import { ServerService } from 'src/services/server.service';
|
||||
import { SystemMetadataService } from 'src/services/system-metadata.service';
|
||||
import { VersionService } from 'src/services/version.service';
|
||||
|
||||
@ApiTags('Server')
|
||||
|
@ -22,6 +24,7 @@ import { VersionService } from 'src/services/version.service';
|
|||
export class ServerController {
|
||||
constructor(
|
||||
private service: ServerService,
|
||||
private systemMetadataService: SystemMetadataService,
|
||||
private versionService: VersionService,
|
||||
) {}
|
||||
|
||||
|
@ -96,4 +99,10 @@ export class ServerController {
|
|||
getServerLicense(): Promise<LicenseResponseDto> {
|
||||
return this.service.getLicense();
|
||||
}
|
||||
|
||||
@Get('version-check')
|
||||
@Authenticated()
|
||||
getVersionCheck(): Promise<VersionCheckStateResponseDto> {
|
||||
return this.systemMetadataService.getVersionCheckState();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import { Body, Controller, Get, HttpCode, HttpStatus, Post } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { AdminOnboardingUpdateDto, ReverseGeocodingStateResponseDto } from 'src/dtos/system-metadata.dto';
|
||||
import {
|
||||
AdminOnboardingUpdateDto,
|
||||
ReverseGeocodingStateResponseDto,
|
||||
VersionCheckStateResponseDto,
|
||||
} from 'src/dtos/system-metadata.dto';
|
||||
import { Permission } from 'src/enum';
|
||||
import { Authenticated } from 'src/middleware/auth.guard';
|
||||
import { SystemMetadataService } from 'src/services/system-metadata.service';
|
||||
|
@ -28,4 +32,10 @@ export class SystemMetadataController {
|
|||
getReverseGeocodingState(): Promise<ReverseGeocodingStateResponseDto> {
|
||||
return this.service.getReverseGeocodingState();
|
||||
}
|
||||
|
||||
@Get('version-check-state')
|
||||
@Authenticated({ permission: Permission.SYSTEM_METADATA_READ, admin: true })
|
||||
getVersionCheckState(): Promise<VersionCheckStateResponseDto> {
|
||||
return this.service.getVersionCheckState();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,3 +13,8 @@ export class ReverseGeocodingStateResponseDto {
|
|||
lastUpdate!: string | null;
|
||||
lastImportFileName!: string | null;
|
||||
}
|
||||
|
||||
export class VersionCheckStateResponseDto {
|
||||
checkedAt!: string | null;
|
||||
releaseVersion!: string | null;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import {
|
|||
AdminOnboardingResponseDto,
|
||||
AdminOnboardingUpdateDto,
|
||||
ReverseGeocodingStateResponseDto,
|
||||
VersionCheckStateResponseDto,
|
||||
} from 'src/dtos/system-metadata.dto';
|
||||
import { SystemMetadataKey } from 'src/enum';
|
||||
import { BaseService } from 'src/services/base.service';
|
||||
|
@ -24,4 +25,9 @@ export class SystemMetadataService extends BaseService {
|
|||
const value = await this.systemMetadataRepository.get(SystemMetadataKey.REVERSE_GEOCODING_STATE);
|
||||
return { lastUpdate: null, lastImportFileName: null, ...value };
|
||||
}
|
||||
|
||||
async getVersionCheckState(): Promise<VersionCheckStateResponseDto> {
|
||||
const value = await this.systemMetadataRepository.get(SystemMetadataKey.VERSION_CHECK_STATE);
|
||||
return { checkedAt: null, releaseVersion: null, ...value };
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue