2025-11-05 14:39:34 +00:00
|
|
|
import { BadRequestException, Body, Controller, Post, Res } from '@nestjs/common';
|
2025-10-31 17:28:57 +00:00
|
|
|
import { ApiTags } from '@nestjs/swagger';
|
2025-11-05 12:27:10 +00:00
|
|
|
import { Response } from 'express';
|
2025-11-05 13:44:43 +00:00
|
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
2025-11-05 14:39:34 +00:00
|
|
|
import { MaintenanceLoginDto, MaintenanceModeResponseDto } from 'src/dtos/maintenance.dto';
|
2025-11-05 12:27:10 +00:00
|
|
|
import { ImmichCookie, Permission } from 'src/enum';
|
2025-11-05 13:44:43 +00:00
|
|
|
import { Auth, Authenticated } from 'src/middleware/auth.guard';
|
2025-11-05 14:10:30 +00:00
|
|
|
import { MaintenanceRepository } from 'src/repositories/maintenance.repository';
|
2025-10-31 17:28:57 +00:00
|
|
|
import { MaintenanceService } from 'src/services/maintenance.service';
|
|
|
|
|
|
|
|
|
|
@ApiTags('Maintenance (admin)')
|
|
|
|
|
@Controller('admin/maintenance')
|
|
|
|
|
export class MaintenanceController {
|
2025-11-05 14:10:30 +00:00
|
|
|
constructor(private service: MaintenanceService) {}
|
2025-10-31 17:28:57 +00:00
|
|
|
|
2025-11-05 14:39:34 +00:00
|
|
|
@Post('login')
|
|
|
|
|
async maintenanceLogin(@Body() _dto: MaintenanceLoginDto): Promise<void> {
|
|
|
|
|
throw new BadRequestException('Not in maintenance mode');
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-31 17:28:57 +00:00
|
|
|
@Post('start')
|
2025-11-05 11:28:34 +00:00
|
|
|
@Authenticated({ permission: Permission.Maintenance, admin: true })
|
2025-11-05 13:44:43 +00:00
|
|
|
async startMaintenance(
|
|
|
|
|
@Auth() auth: AuthDto,
|
|
|
|
|
@Res({ passthrough: true }) response: Response,
|
|
|
|
|
): Promise<MaintenanceModeResponseDto> {
|
|
|
|
|
const { token } = await this.service.startMaintenance();
|
2025-11-05 14:10:30 +00:00
|
|
|
const jwt = MaintenanceRepository.createJwt(token, {
|
|
|
|
|
username: auth.user.name,
|
|
|
|
|
});
|
2025-11-05 13:44:43 +00:00
|
|
|
|
|
|
|
|
response.cookie(ImmichCookie.MaintenanceToken, jwt);
|
2025-11-05 11:28:34 +00:00
|
|
|
return { isMaintenanceMode: true };
|
2025-10-31 17:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('end')
|
2025-11-05 11:28:34 +00:00
|
|
|
@Authenticated({ permission: Permission.Maintenance, admin: true })
|
|
|
|
|
endMaintenance(): Promise<MaintenanceModeResponseDto> {
|
|
|
|
|
throw new BadRequestException('Not in maintenance mode');
|
2025-10-31 17:28:57 +00:00
|
|
|
}
|
|
|
|
|
}
|