2024-05-20 18:09:10 -04:00
|
|
|
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Post, Put } from '@nestjs/common';
|
2025-11-11 17:01:14 -05:00
|
|
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
2023-09-20 13:16:33 +02:00
|
|
|
import {
|
2024-03-20 19:32:04 +01:00
|
|
|
CreateLibraryDto,
|
|
|
|
|
LibraryResponseDto,
|
2023-09-20 13:16:33 +02:00
|
|
|
LibraryStatsResponseDto,
|
2024-03-20 19:32:04 +01:00
|
|
|
UpdateLibraryDto,
|
2024-02-20 16:53:12 +01:00
|
|
|
ValidateLibraryDto,
|
|
|
|
|
ValidateLibraryResponseDto,
|
2024-03-20 23:53:07 +01:00
|
|
|
} from 'src/dtos/library.dto';
|
2025-11-11 17:01:14 -05:00
|
|
|
import { ApiTag, Permission } from 'src/enum';
|
2024-05-09 13:58:44 -04:00
|
|
|
import { Authenticated } from 'src/middleware/auth.guard';
|
2024-03-21 00:07:30 +01:00
|
|
|
import { LibraryService } from 'src/services/library.service';
|
2024-03-20 15:04:03 -05:00
|
|
|
import { UUIDParamDto } from 'src/validation';
|
2023-09-20 13:16:33 +02:00
|
|
|
|
2025-11-11 17:01:14 -05:00
|
|
|
@ApiTags(ApiTag.Libraries)
|
2024-05-22 13:24:57 -04:00
|
|
|
@Controller('libraries')
|
2023-09-20 13:16:33 +02:00
|
|
|
export class LibraryController {
|
|
|
|
|
constructor(private service: LibraryService) {}
|
|
|
|
|
|
|
|
|
|
@Get()
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.LibraryRead, admin: true })
|
2025-11-11 17:01:14 -05:00
|
|
|
@ApiOperation({
|
|
|
|
|
summary: 'Retrieve libraries',
|
|
|
|
|
description: 'Retrieve a list of external libraries.',
|
|
|
|
|
})
|
2024-05-20 18:09:10 -04:00
|
|
|
getAllLibraries(): Promise<LibraryResponseDto[]> {
|
|
|
|
|
return this.service.getAll();
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post()
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.LibraryCreate, admin: true })
|
2025-11-11 17:01:14 -05:00
|
|
|
@ApiOperation({
|
|
|
|
|
summary: 'Create a library',
|
|
|
|
|
description: 'Create a new external library.',
|
|
|
|
|
})
|
2024-03-20 19:32:04 +01:00
|
|
|
createLibrary(@Body() dto: CreateLibraryDto): Promise<LibraryResponseDto> {
|
2024-03-18 15:59:53 -05:00
|
|
|
return this.service.create(dto);
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':id')
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.LibraryRead, admin: true })
|
2025-11-11 17:01:14 -05:00
|
|
|
@ApiOperation({
|
|
|
|
|
summary: 'Retrieve a library',
|
|
|
|
|
description: 'Retrieve an external library by its ID.',
|
|
|
|
|
})
|
2024-03-20 19:32:04 +01:00
|
|
|
getLibrary(@Param() { id }: UUIDParamDto): Promise<LibraryResponseDto> {
|
2024-03-18 15:59:53 -05:00
|
|
|
return this.service.get(id);
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 08:50:14 -04:00
|
|
|
@Put(':id')
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.LibraryUpdate, admin: true })
|
2025-11-11 17:01:14 -05:00
|
|
|
@ApiOperation({
|
|
|
|
|
summary: 'Update a library',
|
|
|
|
|
description: 'Update an existing external library.',
|
|
|
|
|
})
|
2024-08-20 08:50:14 -04:00
|
|
|
updateLibrary(@Param() { id }: UUIDParamDto, @Body() dto: UpdateLibraryDto): Promise<LibraryResponseDto> {
|
|
|
|
|
return this.service.update(id, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-25 19:26:19 +02:00
|
|
|
@Delete(':id')
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.LibraryDelete, admin: true })
|
2025-08-08 15:56:37 -04:00
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
2025-11-11 17:01:14 -05:00
|
|
|
@ApiOperation({
|
|
|
|
|
summary: 'Delete a library',
|
|
|
|
|
description: 'Delete an external library by its ID.',
|
|
|
|
|
})
|
2024-09-25 19:26:19 +02:00
|
|
|
deleteLibrary(@Param() { id }: UUIDParamDto): Promise<void> {
|
|
|
|
|
return this.service.delete(id);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 16:53:12 +01:00
|
|
|
@Post(':id/validate')
|
2024-05-09 13:58:44 -04:00
|
|
|
@Authenticated({ admin: true })
|
2025-08-08 15:56:37 -04:00
|
|
|
@HttpCode(HttpStatus.OK)
|
2025-11-11 17:01:14 -05:00
|
|
|
@ApiOperation({
|
|
|
|
|
summary: 'Validate library settings',
|
|
|
|
|
description: 'Validate the settings of an external library.',
|
|
|
|
|
})
|
2024-03-18 15:59:53 -05:00
|
|
|
// TODO: change endpoint to validate current settings instead
|
|
|
|
|
validate(@Param() { id }: UUIDParamDto, @Body() dto: ValidateLibraryDto): Promise<ValidateLibraryResponseDto> {
|
|
|
|
|
return this.service.validate(id, dto);
|
2024-02-20 16:53:12 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-20 13:16:33 +02:00
|
|
|
@Get(':id/statistics')
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.LibraryStatistics, admin: true })
|
2025-11-11 17:01:14 -05:00
|
|
|
@ApiOperation({
|
|
|
|
|
summary: 'Retrieve library statistics',
|
|
|
|
|
description:
|
|
|
|
|
'Retrieve statistics for a specific external library, including number of videos, images, and storage usage.',
|
|
|
|
|
})
|
2024-03-18 15:59:53 -05:00
|
|
|
getLibraryStatistics(@Param() { id }: UUIDParamDto): Promise<LibraryStatsResponseDto> {
|
|
|
|
|
return this.service.getStatistics(id);
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post(':id/scan')
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.LibraryUpdate, admin: true })
|
2025-08-08 15:56:37 -04:00
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
2025-11-11 17:01:14 -05:00
|
|
|
@ApiOperation({
|
|
|
|
|
summary: 'Scan a library',
|
|
|
|
|
description: 'Queue a scan for the external library to find and import new assets.',
|
|
|
|
|
})
|
2025-08-08 15:56:37 -04:00
|
|
|
scanLibrary(@Param() { id }: UUIDParamDto): Promise<void> {
|
2024-09-25 19:26:19 +02:00
|
|
|
return this.service.queueScan(id);
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
}
|