2025-11-21 12:52:27 +00:00
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Delete,
|
|
|
|
|
FileTypeValidator,
|
|
|
|
|
Get,
|
|
|
|
|
Param,
|
|
|
|
|
ParseFilePipe,
|
|
|
|
|
Post,
|
|
|
|
|
Req,
|
|
|
|
|
Res,
|
|
|
|
|
UploadedFile,
|
|
|
|
|
UseInterceptors,
|
|
|
|
|
} from '@nestjs/common';
|
|
|
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
2025-11-17 17:15:44 +00:00
|
|
|
import { Request, Response } from 'express';
|
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 { ServerConfigDto } from 'src/dtos/server.dto';
|
2025-11-20 15:24:48 +00:00
|
|
|
import { ImmichCookie } from 'src/enum';
|
2025-11-17 17:15:44 +00:00
|
|
|
import { MaintenanceRoute } from 'src/maintenance/maintenance-auth.guard';
|
|
|
|
|
import { MaintenanceWorkerService } from 'src/maintenance/maintenance-worker.service';
|
|
|
|
|
import { GetLoginDetails } from 'src/middleware/auth.guard';
|
|
|
|
|
import { LoginDetails } from 'src/services/auth.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
|
|
|
|
|
|
|
|
@Controller()
|
|
|
|
|
export class MaintenanceWorkerController {
|
|
|
|
|
constructor(private service: MaintenanceWorkerService) {}
|
|
|
|
|
|
|
|
|
|
@Get('server/config')
|
2025-11-20 17:05:22 +00:00
|
|
|
getServerConfig(): ServerConfigDto {
|
2025-11-17 17:15:44 +00:00
|
|
|
return this.service.getSystemConfig();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-19 15:54:44 +00:00
|
|
|
@Get('admin/maintenance/status')
|
|
|
|
|
maintenanceStatus(@Req() request: Request): Promise<MaintenanceStatusResponseDto> {
|
|
|
|
|
return this.service.status(request.cookies[ImmichCookie.MaintenanceToken]);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-17 17:15:44 +00:00
|
|
|
@Post('admin/maintenance/login')
|
|
|
|
|
async maintenanceLogin(
|
|
|
|
|
@Req() request: Request,
|
|
|
|
|
@Body() dto: MaintenanceLoginDto,
|
|
|
|
|
@GetLoginDetails() loginDetails: LoginDetails,
|
|
|
|
|
@Res({ passthrough: true }) res: Response,
|
|
|
|
|
): Promise<MaintenanceAuthDto> {
|
|
|
|
|
const token = dto.token ?? request.cookies[ImmichCookie.MaintenanceToken];
|
|
|
|
|
const auth = await this.service.login(token);
|
|
|
|
|
return respondWithCookie(res, auth, {
|
|
|
|
|
isSecure: loginDetails.isSecure,
|
|
|
|
|
values: [{ key: ImmichCookie.MaintenanceToken, value: token }],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('admin/maintenance')
|
|
|
|
|
@MaintenanceRoute()
|
2025-11-20 15:36:17 +00:00
|
|
|
setMaintenanceMode(@Body() dto: SetMaintenanceModeDto): void {
|
|
|
|
|
void this.service.setAction(dto);
|
2025-11-17 17:15:44 +00:00
|
|
|
}
|
2025-11-20 15:31:35 +00:00
|
|
|
|
|
|
|
|
@Get('admin/maintenance/backups/list')
|
|
|
|
|
@MaintenanceRoute()
|
|
|
|
|
listBackups(): Promise<MaintenanceListBackupsResponseDto> {
|
|
|
|
|
return this.service.listBackups();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-21 14:47:11 +00:00
|
|
|
@Get('admin/maintenance/backups/:filename')
|
|
|
|
|
@MaintenanceRoute()
|
|
|
|
|
async downloadBackup(@Param() { filename }: FilenameParamDto, @Res() res: Response) {
|
|
|
|
|
res.header('Content-Disposition', 'attachment');
|
|
|
|
|
res.sendFile(this.service.getBackupPath(filename));
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-20 15:31:35 +00:00
|
|
|
@Delete('admin/maintenance/backups/:filename')
|
|
|
|
|
@MaintenanceRoute()
|
|
|
|
|
async deleteBackup(@Param() { filename }: FilenameParamDto): Promise<void> {
|
|
|
|
|
return this.service.deleteBackup(filename);
|
|
|
|
|
}
|
2025-11-21 12:52:27 +00:00
|
|
|
|
|
|
|
|
@Post('admin/maintenance/backups/upload')
|
|
|
|
|
@MaintenanceRoute()
|
|
|
|
|
@UseInterceptors(FileInterceptor('file'))
|
|
|
|
|
uploadBackup(
|
|
|
|
|
@UploadedFile(new ParseFilePipe({ validators: [new FileTypeValidator({ fileType: 'application/gzip' })] }))
|
|
|
|
|
file: Express.Multer.File,
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
return this.service.uploadBackup(file);
|
|
|
|
|
}
|
2025-11-17 17:15:44 +00:00
|
|
|
}
|