feat: add scan library functionality and related error handling in LibraryHeader and services
This commit is contained in:
@@ -13,6 +13,7 @@ export type { CacheType };
|
||||
|
||||
interface KomgaRequestInit extends RequestInit {
|
||||
isImage?: boolean;
|
||||
noJson?: boolean;
|
||||
}
|
||||
|
||||
interface KomgaUrlBuilder {
|
||||
@@ -175,7 +176,15 @@ export abstract class BaseApiService {
|
||||
});
|
||||
}
|
||||
|
||||
return options.isImage ? (response as T) : response.json();
|
||||
if (options.isImage) {
|
||||
return response as T;
|
||||
}
|
||||
|
||||
if (options.noJson) {
|
||||
return undefined as T;
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
|
||||
@@ -159,4 +159,15 @@ export class LibraryService extends BaseApiService {
|
||||
throw new AppError(ERROR_CODES.CACHE.DELETE_ERROR, {}, error);
|
||||
}
|
||||
}
|
||||
|
||||
static async scanLibrary(libraryId: string, deep: boolean = false): Promise<void> {
|
||||
try {
|
||||
await this.fetchFromApi({
|
||||
path: `libraries/${libraryId}/scan`,
|
||||
params: { deep: String(deep) }
|
||||
}, {}, { method: "POST", noJson: true });
|
||||
} catch (error) {
|
||||
throw new AppError(ERROR_CODES.LIBRARY.SCAN_ERROR, { libraryId }, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user