Chaîne de résolution metadata (local, Open Library, Google Books, BNF) avec activation/priorité/clé API par provider, colonnes isbn13 et identifiers sur les livres, et intégration au scanner pour compléter métadonnées et jaquettes manquantes. Module automation: réglages persistés, planifications scan/enrichissement et déclenchement manuel, exposés via des endpoints admin. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
122 lines
3.5 KiB
TypeScript
122 lines
3.5 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, Patch, Post, Put, UseGuards } from "@nestjs/common";
|
|
import {
|
|
CreateLibraryDto,
|
|
CreateLibrarySchema,
|
|
CreateUserDto,
|
|
CreateUserSchema,
|
|
UpdateAutomationSettingsDto,
|
|
UpdateAutomationSettingsSchema,
|
|
UpdateMetadataSourcesConfigDto,
|
|
UpdateMetadataSourcesConfigSchema,
|
|
UpdateLibraryDto,
|
|
UpdateLibrarySchema,
|
|
UpdateUserDto,
|
|
UpdateUserSchema
|
|
} from "@readabook/shared";
|
|
import { AuthGuard } from "../auth/auth.guard.js";
|
|
import { Roles } from "../auth/roles.decorator.js";
|
|
import { RolesGuard } from "../auth/roles.guard.js";
|
|
import { AuthService } from "../auth/auth.service.js";
|
|
import { AutomationService } from "../automation/automation.service.js";
|
|
import { ZodValidationPipe } from "../common/zod-validation.pipe.js";
|
|
import { JobsService } from "../jobs/jobs.service.js";
|
|
import { LibrariesService } from "../libraries/libraries.service.js";
|
|
import { MetadataService } from "../metadata/metadata.service.js";
|
|
import { ScannerService } from "../scanner/scanner.service.js";
|
|
|
|
@Controller("admin")
|
|
@UseGuards(AuthGuard, RolesGuard)
|
|
@Roles("admin")
|
|
export class AdminController {
|
|
constructor(
|
|
private readonly auth: AuthService,
|
|
private readonly libraries: LibrariesService,
|
|
private readonly jobs: JobsService,
|
|
private readonly scanner: ScannerService,
|
|
private readonly metadata: MetadataService,
|
|
private readonly automation: AutomationService
|
|
) {}
|
|
|
|
@Get("users")
|
|
users() {
|
|
return this.auth.listUsers();
|
|
}
|
|
|
|
@Post("users")
|
|
createUser(@Body(new ZodValidationPipe(CreateUserSchema)) body: CreateUserDto) {
|
|
return this.auth.createUser(body);
|
|
}
|
|
|
|
@Patch("users/:id")
|
|
updateUser(@Param("id") id: string, @Body(new ZodValidationPipe(UpdateUserSchema)) body: UpdateUserDto) {
|
|
return this.auth.updateUser(Number(id), body);
|
|
}
|
|
|
|
@Delete("users/:id")
|
|
deleteUser(@Param("id") id: string) {
|
|
this.auth.deleteUser(Number(id));
|
|
return { ok: true };
|
|
}
|
|
|
|
@Get("libraries")
|
|
listLibraries() {
|
|
return this.libraries.list();
|
|
}
|
|
|
|
@Post("libraries")
|
|
createLibrary(@Body(new ZodValidationPipe(CreateLibrarySchema)) body: CreateLibraryDto) {
|
|
return this.libraries.create(body);
|
|
}
|
|
|
|
@Patch("libraries/:id")
|
|
updateLibrary(@Param("id") id: string, @Body(new ZodValidationPipe(UpdateLibrarySchema)) body: UpdateLibraryDto) {
|
|
return this.libraries.update(Number(id), body);
|
|
}
|
|
|
|
@Delete("libraries/:id")
|
|
deleteLibrary(@Param("id") id: string) {
|
|
this.libraries.delete(Number(id));
|
|
return { ok: true };
|
|
}
|
|
|
|
@Post("libraries/:id/scan")
|
|
scanLibrary(@Param("id") id: string) {
|
|
return this.scanner.enqueueLibraryScan(Number(id));
|
|
}
|
|
|
|
@Get("jobs")
|
|
listJobs() {
|
|
return this.jobs.list();
|
|
}
|
|
|
|
@Get("metadata-sources")
|
|
metadataSources() {
|
|
return this.metadata.getSourcesConfig();
|
|
}
|
|
|
|
@Put("metadata-sources")
|
|
updateMetadataSources(@Body(new ZodValidationPipe(UpdateMetadataSourcesConfigSchema)) body: UpdateMetadataSourcesConfigDto) {
|
|
return this.metadata.updateSourcesConfig(body);
|
|
}
|
|
|
|
@Get("automation")
|
|
automationSettings() {
|
|
return this.automation.getSettings();
|
|
}
|
|
|
|
@Put("automation")
|
|
updateAutomationSettings(@Body(new ZodValidationPipe(UpdateAutomationSettingsSchema)) body: UpdateAutomationSettingsDto) {
|
|
return this.automation.updateSettings(body);
|
|
}
|
|
|
|
@Post("automation/run-scan")
|
|
runAutomationScan() {
|
|
return this.automation.runScanNow();
|
|
}
|
|
|
|
@Post("automation/run-enrich")
|
|
runAutomationEnrich() {
|
|
return this.automation.runEnrichNow();
|
|
}
|
|
}
|