feat: refresh in libraries and books lists

This commit is contained in:
Julien Froidefond
2025-02-22 15:36:32 +01:00
parent b208a2aaf6
commit 448cdf6450
7 changed files with 135 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
import { BaseApiService } from "./base-api.service";
import { Library, LibraryResponse } from "@/types/library";
import { Series } from "@/types/series";
import { serverCacheService } from "./server-cache.service";
export class LibraryService extends BaseApiService {
static async getLibraries(): Promise<Library[]> {
@@ -53,4 +54,8 @@ export class LibraryService extends BaseApiService {
return this.handleError(error, "Impossible de récupérer les séries");
}
}
static async clearLibrarySeriesCache(libraryId: string) {
serverCacheService.delete(`library-${libraryId}-series`);
}
}

View File

@@ -4,6 +4,7 @@ import { KomgaBook, KomgaSeries } from "@/types/komga";
import { BookService } from "./book.service";
import { ImageService } from "./image.service";
import { PreferencesService } from "./preferences.service";
import { serverCacheService } from "./server-cache.service";
export class SeriesService extends BaseApiService {
static async getSeries(seriesId: string): Promise<KomgaSeries> {
@@ -22,6 +23,10 @@ export class SeriesService extends BaseApiService {
}
}
static async clearSeriesCache(seriesId: string) {
serverCacheService.delete(`series-${seriesId}`);
}
static async getSeriesBooks(
seriesId: string,
page: number = 0,
@@ -48,6 +53,10 @@ export class SeriesService extends BaseApiService {
}
}
static async clearSeriesBooksCache(seriesId: string) {
serverCacheService.deleteAll(`series-${seriesId}-books`);
}
static async getFirstBook(seriesId: string): Promise<string> {
try {
const config = await this.getKomgaConfig();

View File

@@ -283,6 +283,24 @@ class ServerCacheService {
}
}
/**
* Supprime toutes les entrées du cache qui commencent par un préfixe
*/
deleteAll(prefix: string): void {
if (this.config.mode === "memory") {
this.memoryCache.forEach((value, key) => {
if (key.startsWith(prefix)) {
this.memoryCache.delete(key);
}
});
} else {
const cacheDir = path.join(this.cacheDir, prefix);
if (fs.existsSync(cacheDir)) {
fs.rmdirSync(cacheDir, { recursive: true });
}
}
}
/**
* Vide le cache
*/