Files
immich/server/src/controllers/server.controller.ts

194 lines
6.4 KiB
TypeScript
Raw Normal View History

import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Put } from '@nestjs/common';
2025-11-13 08:18:43 -05:00
import { ApiNotFoundResponse, ApiTags } from '@nestjs/swagger';
import { Endpoint, HistoryBuilder } from 'src/decorators';
import { LicenseKeyDto, LicenseResponseDto } from 'src/dtos/license.dto';
import {
ServerAboutResponseDto,
ServerApkLinksDto,
ServerConfigDto,
ServerFeaturesDto,
ServerMediaTypesResponseDto,
ServerPingResponse,
ServerStatsResponseDto,
ServerStorageResponseDto,
ServerThemeDto,
2024-10-01 13:33:58 -04:00
ServerVersionHistoryResponseDto,
ServerVersionResponseDto,
} from 'src/dtos/server.dto';
2025-05-27 16:33:23 +02:00
import { VersionCheckStateResponseDto } from 'src/dtos/system-metadata.dto';
2025-11-11 17:01:14 -05:00
import { ApiTag, Permission } from 'src/enum';
import { Authenticated } from 'src/middleware/auth.guard';
import { ServerService } from 'src/services/server.service';
2025-05-27 16:33:23 +02:00
import { SystemMetadataService } from 'src/services/system-metadata.service';
import { VersionService } from 'src/services/version.service';
2025-11-11 17:01:14 -05:00
@ApiTags(ApiTag.Server)
@Controller('server')
export class ServerController {
constructor(
private service: ServerService,
2025-05-27 16:33:23 +02:00
private systemMetadataService: SystemMetadataService,
private versionService: VersionService,
) {}
@Get('about')
@Authenticated({ permission: Permission.ServerAbout })
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Get server information',
description: 'Retrieve a list of information about the server.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
getAboutInfo(): Promise<ServerAboutResponseDto> {
return this.service.getAboutInfo();
}
@Get('apk-links')
@Authenticated({ permission: Permission.ServerApkLinks })
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Get APK links',
description: 'Retrieve links to the APKs for the current server version.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
getApkLinks(): ServerApkLinksDto {
return this.service.getApkLinks();
}
@Get('storage')
@Authenticated({ permission: Permission.ServerStorage })
2025-11-13 08:18:43 -05:00
@Endpoint({
2025-11-11 17:01:14 -05:00
summary: 'Get storage',
description: 'Retrieve the current storage utilization information of the server.',
2025-11-13 08:18:43 -05:00
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
2025-11-11 17:01:14 -05:00
})
getStorage(): Promise<ServerStorageResponseDto> {
return this.service.getStorage();
}
@Get('ping')
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Ping',
description: 'Pong',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
pingServer(): ServerPingResponse {
return this.service.ping();
}
@Get('version')
2025-11-13 08:18:43 -05:00
@Endpoint({
2025-11-11 17:01:14 -05:00
summary: 'Get server version',
description: 'Retrieve the current server version in semantic versioning (semver) format.',
2025-11-13 08:18:43 -05:00
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
2025-11-11 17:01:14 -05:00
})
getServerVersion(): ServerVersionResponseDto {
return this.versionService.getVersion();
}
2024-10-01 13:33:58 -04:00
@Get('version-history')
2025-11-13 08:18:43 -05:00
@Endpoint({
2025-11-11 17:01:14 -05:00
summary: 'Get version history',
description: 'Retrieve a list of past versions the server has been on.',
2025-11-13 08:18:43 -05:00
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
2025-11-11 17:01:14 -05:00
})
2024-10-01 13:33:58 -04:00
getVersionHistory(): Promise<ServerVersionHistoryResponseDto[]> {
return this.versionService.getVersionHistory();
}
@Get('features')
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Get features',
description: 'Retrieve available features supported by this server.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
getServerFeatures(): Promise<ServerFeaturesDto> {
return this.service.getFeatures();
}
@Get('theme')
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Get theme',
description: 'Retrieve the custom CSS, if existent.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
getTheme(): Promise<ServerThemeDto> {
return this.service.getTheme();
}
@Get('config')
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Get config',
description: 'Retrieve the current server configuration.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
getServerConfig(): Promise<ServerConfigDto> {
return this.service.getSystemConfig();
}
@Get('statistics')
@Authenticated({ permission: Permission.ServerStatistics, admin: true })
2025-11-13 08:18:43 -05:00
@Endpoint({
2025-11-11 17:01:14 -05:00
summary: 'Get statistics',
description: 'Retrieve statistics about the entire Immich instance such as asset counts.',
2025-11-13 08:18:43 -05:00
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
2025-11-11 17:01:14 -05:00
})
getServerStatistics(): Promise<ServerStatsResponseDto> {
return this.service.getStatistics();
}
@Get('media-types')
2025-11-13 08:18:43 -05:00
@Endpoint({
2025-11-11 17:01:14 -05:00
summary: 'Get supported media types',
description: 'Retrieve all media types supported by the server.',
2025-11-13 08:18:43 -05:00
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
2025-11-11 17:01:14 -05:00
})
getSupportedMediaTypes(): ServerMediaTypesResponseDto {
return this.service.getSupportedMediaTypes();
}
@Get('license')
@Authenticated({ permission: Permission.ServerLicenseRead, admin: true })
@ApiNotFoundResponse()
2025-11-13 08:18:43 -05:00
@Endpoint({
2025-11-11 17:01:14 -05:00
summary: 'Get product key',
description: 'Retrieve information about whether the server currently has a product key registered.',
2025-11-13 08:18:43 -05:00
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
2025-11-11 17:01:14 -05:00
})
getServerLicense(): Promise<LicenseResponseDto> {
return this.service.getLicense();
}
@Put('license')
@Authenticated({ permission: Permission.ServerLicenseUpdate, admin: true })
2025-11-13 08:18:43 -05:00
@Endpoint({
2025-11-11 17:01:14 -05:00
summary: 'Set server product key',
description: 'Validate and set the server product key if successful.',
2025-11-13 08:18:43 -05:00
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
2025-11-11 17:01:14 -05:00
})
setServerLicense(@Body() license: LicenseKeyDto): Promise<LicenseResponseDto> {
return this.service.setLicense(license);
}
@Delete('license')
@Authenticated({ permission: Permission.ServerLicenseDelete, admin: true })
@HttpCode(HttpStatus.NO_CONTENT)
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Delete server product key',
description: 'Delete the currently set server product key.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
deleteServerLicense(): Promise<void> {
return this.service.deleteLicense();
}
2025-05-27 16:33:23 +02:00
@Get('version-check')
@Authenticated({ permission: Permission.ServerVersionCheck })
2025-11-13 08:18:43 -05:00
@Endpoint({
2025-11-11 17:01:14 -05:00
summary: 'Get version check status',
description: 'Retrieve information about the last time the version check ran.',
2025-11-13 08:18:43 -05:00
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
2025-11-11 17:01:14 -05:00
})
2025-05-27 16:33:23 +02:00
getVersionCheck(): Promise<VersionCheckStateResponseDto> {
return this.systemMetadataService.getVersionCheckState();
}
}