2025-11-20 15:31:35 +00:00
|
|
|
import { BadRequestException, Body, Controller, Delete, Get, Param, Post, Res } from '@nestjs/common';
|
2025-11-17 17:15:44 +00:00
|
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
|
|
|
import { Response } from 'express';
|
|
|
|
|
import { Endpoint, HistoryBuilder } from 'src/decorators';
|
|
|
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
2025-11-19 15:54:44 +00:00
|
|
|
import {
|
|
|
|
|
MaintenanceAuthDto,
|
2025-11-20 15:31:35 +00:00
|
|
|
MaintenanceListBackupsResponseDto,
|
2025-11-19 15:54:44 +00:00
|
|
|
MaintenanceLoginDto,
|
|
|
|
|
MaintenanceStatusResponseDto,
|
|
|
|
|
SetMaintenanceModeDto,
|
|
|
|
|
} from 'src/dtos/maintenance.dto';
|
2025-11-17 17:15:44 +00:00
|
|
|
import { ApiTag, ImmichCookie, MaintenanceAction, Permission } from 'src/enum';
|
|
|
|
|
import { Auth, Authenticated, GetLoginDetails } from 'src/middleware/auth.guard';
|
|
|
|
|
import { LoginDetails } from 'src/services/auth.service';
|
|
|
|
|
import { MaintenanceService } from 'src/services/maintenance.service';
|
|
|
|
|
import { respondWithCookie } from 'src/utils/response';
|
2025-11-20 15:31:35 +00:00
|
|
|
import { FilenameParamDto } from 'src/validation';
|
2025-11-17 17:15:44 +00:00
|
|
|
|
|
|
|
|
@ApiTags(ApiTag.Maintenance)
|
|
|
|
|
@Controller('admin/maintenance')
|
|
|
|
|
export class MaintenanceController {
|
|
|
|
|
constructor(private service: MaintenanceService) {}
|
|
|
|
|
|
2025-11-19 15:54:44 +00:00
|
|
|
@Get('admin/maintenance/status')
|
|
|
|
|
@Endpoint({
|
|
|
|
|
summary: 'Get maintenance mode status',
|
|
|
|
|
description: 'Fetch information about the currently running maintenance action.',
|
|
|
|
|
history: new HistoryBuilder().added('v9.9.9').alpha('v9.9.9'),
|
|
|
|
|
})
|
|
|
|
|
maintenanceStatus(): MaintenanceStatusResponseDto {
|
2025-11-20 15:24:48 +00:00
|
|
|
return {
|
|
|
|
|
action: MaintenanceAction.End,
|
|
|
|
|
};
|
2025-11-19 15:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-17 17:15:44 +00:00
|
|
|
@Post('login')
|
|
|
|
|
@Endpoint({
|
|
|
|
|
summary: 'Log into maintenance mode',
|
|
|
|
|
description: 'Login with maintenance token or cookie to receive current information and perform further actions.',
|
|
|
|
|
history: new HistoryBuilder().added('v2.3.0').alpha('v2.3.0'),
|
|
|
|
|
})
|
|
|
|
|
maintenanceLogin(@Body() _dto: MaintenanceLoginDto): MaintenanceAuthDto {
|
|
|
|
|
throw new BadRequestException('Not in maintenance mode');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post()
|
|
|
|
|
@Endpoint({
|
|
|
|
|
summary: 'Set maintenance mode',
|
|
|
|
|
description: 'Put Immich into or take it out of maintenance mode',
|
|
|
|
|
history: new HistoryBuilder().added('v2.3.0').alpha('v2.3.0'),
|
|
|
|
|
})
|
|
|
|
|
@Authenticated({ permission: Permission.Maintenance, admin: true })
|
|
|
|
|
async setMaintenanceMode(
|
|
|
|
|
@Auth() auth: AuthDto,
|
|
|
|
|
@Body() dto: SetMaintenanceModeDto,
|
|
|
|
|
@GetLoginDetails() loginDetails: LoginDetails,
|
|
|
|
|
@Res({ passthrough: true }) res: Response,
|
|
|
|
|
): Promise<void> {
|
2025-11-18 17:28:03 +00:00
|
|
|
if (dto.action !== MaintenanceAction.End) {
|
|
|
|
|
const { jwt } = await this.service.startMaintenance(dto, auth.user.name);
|
2025-11-17 17:15:44 +00:00
|
|
|
return respondWithCookie(res, undefined, {
|
|
|
|
|
isSecure: loginDetails.isSecure,
|
|
|
|
|
values: [{ key: ImmichCookie.MaintenanceToken, value: jwt }],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-20 15:31:35 +00:00
|
|
|
|
|
|
|
|
@Get('admin/maintenance/backups/list')
|
|
|
|
|
@Endpoint({
|
|
|
|
|
summary: 'List backups',
|
|
|
|
|
description: 'Get the list of the successful and failed backups',
|
|
|
|
|
history: new HistoryBuilder().added('v9.9.9').alpha('v9.9.9'),
|
|
|
|
|
})
|
|
|
|
|
@Authenticated({ permission: Permission.Maintenance, admin: true })
|
|
|
|
|
listBackups(): Promise<MaintenanceListBackupsResponseDto> {
|
|
|
|
|
return this.service.listBackups();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete('admin/maintenance/backups/:filename')
|
|
|
|
|
@Endpoint({
|
|
|
|
|
summary: 'Delete backup',
|
|
|
|
|
description: 'Delete a backup by its filename',
|
|
|
|
|
history: new HistoryBuilder().added('v9.9.9').alpha('v9.9.9'),
|
|
|
|
|
})
|
|
|
|
|
@Authenticated({ permission: Permission.Maintenance, admin: true })
|
|
|
|
|
async deleteBackup(@Param() { filename }: FilenameParamDto): Promise<void> {
|
|
|
|
|
return this.service.deleteBackup(filename);
|
|
|
|
|
}
|
2025-11-17 17:15:44 +00:00
|
|
|
}
|