From 67dc81090eb969918a9c3417f2881f2fd0f6a835 Mon Sep 17 00:00:00 2001 From: Jurgis Sakalauskas Date: Mon, 30 Oct 2023 11:42:38 +0200 Subject: [PATCH] add re-scan all option --- src/KodiApi/AllFiles/all-files.controller.ts | 5 +++++ src/KodiApi/AllFiles/all-files.service.ts | 9 +++++++++ src/VideoFiles/Update/video-files-update.service.ts | 3 +++ src/VideoFiles/video-files.facade.ts | 4 ++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/KodiApi/AllFiles/all-files.controller.ts b/src/KodiApi/AllFiles/all-files.controller.ts index 964dacf..5527925 100644 --- a/src/KodiApi/AllFiles/all-files.controller.ts +++ b/src/KodiApi/AllFiles/all-files.controller.ts @@ -30,6 +30,11 @@ export class AllFilesController { return this.allFilesService.scanNewFiles(); } + @Get('scan-all') + scanAllFiles(): KodiApiResponse { + return this.allFilesService.scanAllFiles(); + } + @Get('delete/:fileId') async deleteFile(@Param('fileId') fileId: string): Promise { return this.allFilesService.deleteFile(fileId); diff --git a/src/KodiApi/AllFiles/all-files.service.ts b/src/KodiApi/AllFiles/all-files.service.ts index 59bb187..c60c96f 100644 --- a/src/KodiApi/AllFiles/all-files.service.ts +++ b/src/KodiApi/AllFiles/all-files.service.ts @@ -26,6 +26,7 @@ export class AllFilesService { ['Movies', 'movie'], ['Shows', 'show'], ['Scan for new Files', 'scan'], + ['Re-Scan Files', 'scan-all'], ], 'all/', ) @@ -203,6 +204,14 @@ export class AllFilesService { ); } + public scanAllFiles(): NotificationResponse { + this.videoFilesFacade.updateFsVideoFiles(true); + return this.koiApiResponseFactory.createNotificationResponse( + 'Scanning for all files.', + false, + ); + } + async deleteFile(fileId: string) { const id = parseInt(fileId); const result = await this.videoFilesFacade.deleteFile(id); diff --git a/src/VideoFiles/Update/video-files-update.service.ts b/src/VideoFiles/Update/video-files-update.service.ts index 7a23f08..0cc946e 100644 --- a/src/VideoFiles/Update/video-files-update.service.ts +++ b/src/VideoFiles/Update/video-files-update.service.ts @@ -65,6 +65,9 @@ export class VideoFilesUpdateService { } await this.repository.saveFiles(entitiesToSave); + console.log( + `file scan and update complete - ${refresh ? 'full update' : 'only new'}`, + ); } private isPathToIgnore(filePath: string): boolean { diff --git a/src/VideoFiles/video-files.facade.ts b/src/VideoFiles/video-files.facade.ts index 11f6efa..ba26b71 100644 --- a/src/VideoFiles/video-files.facade.ts +++ b/src/VideoFiles/video-files.facade.ts @@ -47,8 +47,8 @@ export class VideoFilesFacade { * Scan for new files and remove deleted. * Once all hooks are working correctly, this one shouldn't be needed anymore */ - updateFsVideoFiles(): void { - this.videoFilesUpdateService.updateFsVideoFiles().then(); + updateFsVideoFiles(refresh = false): void { + this.videoFilesUpdateService.updateFsVideoFiles(refresh).then(); } addVideoFiles(