mirror of
https://github.com/immich-app/immich.git
synced 2025-12-24 01:11:32 +03:00
refactor: split maintenance dto for integrity checks
This commit is contained in:
@@ -4,10 +4,10 @@ import { NextFunction, Response } from 'express';
|
||||
import { Endpoint, HistoryBuilder } from 'src/decorators';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import {
|
||||
MaintenanceGetIntegrityReportDto,
|
||||
MaintenanceIntegrityReportResponseDto,
|
||||
MaintenanceIntegrityReportSummaryResponseDto,
|
||||
} from 'src/dtos/maintenance.dto';
|
||||
IntegrityGetReportDto,
|
||||
IntegrityReportResponseDto,
|
||||
IntegrityReportSummaryResponseDto,
|
||||
} from 'src/dtos/integrity.dto';
|
||||
import { ApiTag, Permission } from 'src/enum';
|
||||
import { Auth, Authenticated, FileResponse } from 'src/middleware/auth.guard';
|
||||
import { LoggingRepository } from 'src/repositories/logging.repository';
|
||||
@@ -30,7 +30,7 @@ export class IntegrityController {
|
||||
history: new HistoryBuilder().added('v9.9.9').alpha('v9.9.9'),
|
||||
})
|
||||
@Authenticated({ permission: Permission.Maintenance, admin: true })
|
||||
getIntegrityReportSummary(): Promise<MaintenanceIntegrityReportSummaryResponseDto> {
|
||||
getIntegrityReportSummary(): Promise<IntegrityReportSummaryResponseDto> {
|
||||
return this.service.getIntegrityReportSummary();
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ export class IntegrityController {
|
||||
history: new HistoryBuilder().added('v9.9.9').alpha('v9.9.9'),
|
||||
})
|
||||
@Authenticated({ permission: Permission.Maintenance, admin: true })
|
||||
getIntegrityReport(@Body() dto: MaintenanceGetIntegrityReportDto): Promise<MaintenanceIntegrityReportResponseDto> {
|
||||
getIntegrityReport(@Body() dto: IntegrityGetReportDto): Promise<IntegrityReportResponseDto> {
|
||||
return this.service.getIntegrityReport(dto);
|
||||
}
|
||||
|
||||
|
||||
40
server/src/dtos/integrity.dto.ts
Normal file
40
server/src/dtos/integrity.dto.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IntegrityReportType } from 'src/enum';
|
||||
import { ValidateEnum } from 'src/validation';
|
||||
|
||||
export class IntegrityReportSummaryResponseDto {
|
||||
@ApiProperty({ type: 'integer' })
|
||||
[IntegrityReportType.ChecksumFail]!: number;
|
||||
@ApiProperty({ type: 'integer' })
|
||||
[IntegrityReportType.MissingFile]!: number;
|
||||
@ApiProperty({ type: 'integer' })
|
||||
[IntegrityReportType.OrphanFile]!: number;
|
||||
}
|
||||
|
||||
export class IntegrityGetReportDto {
|
||||
@ValidateEnum({ enum: IntegrityReportType, name: 'IntegrityReportType' })
|
||||
type!: IntegrityReportType;
|
||||
|
||||
// todo: paginate
|
||||
// @IsInt()
|
||||
// @Min(1)
|
||||
// @Type(() => Number)
|
||||
// @Optional()
|
||||
// page?: number;
|
||||
}
|
||||
|
||||
export class IntegrityDeleteReportDto {
|
||||
@ValidateEnum({ enum: IntegrityReportType, name: 'IntegrityReportType' })
|
||||
type!: IntegrityReportType;
|
||||
}
|
||||
|
||||
class IntegrityReportDto {
|
||||
id!: string;
|
||||
@ValidateEnum({ enum: IntegrityReportType, name: 'IntegrityReportType' })
|
||||
type!: IntegrityReportType;
|
||||
path!: string;
|
||||
}
|
||||
|
||||
export class IntegrityReportResponseDto {
|
||||
items!: IntegrityReportDto[];
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IntegrityReportType, MaintenanceAction } from 'src/enum';
|
||||
import { MaintenanceAction } from 'src/enum';
|
||||
import { ValidateEnum, ValidateString } from 'src/validation';
|
||||
|
||||
export class SetMaintenanceModeDto {
|
||||
@@ -15,40 +14,3 @@ export class MaintenanceLoginDto {
|
||||
export class MaintenanceAuthDto {
|
||||
username!: string;
|
||||
}
|
||||
|
||||
export class MaintenanceIntegrityReportSummaryResponseDto {
|
||||
@ApiProperty({ type: 'integer' })
|
||||
[IntegrityReportType.ChecksumFail]!: number;
|
||||
@ApiProperty({ type: 'integer' })
|
||||
[IntegrityReportType.MissingFile]!: number;
|
||||
@ApiProperty({ type: 'integer' })
|
||||
[IntegrityReportType.OrphanFile]!: number;
|
||||
}
|
||||
|
||||
export class MaintenanceGetIntegrityReportDto {
|
||||
@ValidateEnum({ enum: IntegrityReportType, name: 'IntegrityReportType' })
|
||||
type!: IntegrityReportType;
|
||||
|
||||
// todo: paginate
|
||||
// @IsInt()
|
||||
// @Min(1)
|
||||
// @Type(() => Number)
|
||||
// @Optional()
|
||||
// page?: number;
|
||||
}
|
||||
|
||||
export class MaintenanceDeleteIntegrityReportDto {
|
||||
@ValidateEnum({ enum: IntegrityReportType, name: 'IntegrityReportType' })
|
||||
type!: IntegrityReportType;
|
||||
}
|
||||
|
||||
class MaintenanceIntegrityReportDto {
|
||||
id!: string;
|
||||
@ValidateEnum({ enum: IntegrityReportType, name: 'IntegrityReportType' })
|
||||
type!: IntegrityReportType;
|
||||
path!: string;
|
||||
}
|
||||
|
||||
export class MaintenanceIntegrityReportResponseDto {
|
||||
items!: MaintenanceIntegrityReportDto[];
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import { newTestService, ServiceMocks } from 'test/utils';
|
||||
|
||||
describe(IntegrityService.name, () => {
|
||||
let sut: IntegrityService;
|
||||
// impl. pending
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
let mocks: ServiceMocks;
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -10,10 +10,10 @@ import { StorageCore } from 'src/cores/storage.core';
|
||||
import { OnEvent, OnJob } from 'src/decorators';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import {
|
||||
MaintenanceGetIntegrityReportDto,
|
||||
MaintenanceIntegrityReportResponseDto,
|
||||
MaintenanceIntegrityReportSummaryResponseDto,
|
||||
} from 'src/dtos/maintenance.dto';
|
||||
IntegrityGetReportDto,
|
||||
IntegrityReportResponseDto,
|
||||
IntegrityReportSummaryResponseDto,
|
||||
} from 'src/dtos/integrity.dto';
|
||||
import {
|
||||
AssetStatus,
|
||||
CacheControl,
|
||||
@@ -154,11 +154,11 @@ export class IntegrityService extends BaseService {
|
||||
});
|
||||
}
|
||||
|
||||
getIntegrityReportSummary(): Promise<MaintenanceIntegrityReportSummaryResponseDto> {
|
||||
getIntegrityReportSummary(): Promise<IntegrityReportSummaryResponseDto> {
|
||||
return this.integrityRepository.getIntegrityReportSummary();
|
||||
}
|
||||
|
||||
async getIntegrityReport(dto: MaintenanceGetIntegrityReportDto): Promise<MaintenanceIntegrityReportResponseDto> {
|
||||
async getIntegrityReport(dto: IntegrityGetReportDto): Promise<IntegrityReportResponseDto> {
|
||||
return {
|
||||
items: await this.integrityRepository.getIntegrityReports(dto.type),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user