sync: check local file availability before opening (#262)

This commit is contained in:
Huang Xin
2025-01-28 21:02:19 +01:00
committed by GitHub
parent 171a7ee759
commit c0d715bf77
6 changed files with 84 additions and 51 deletions
+13 -4
View File
@@ -224,17 +224,22 @@ export abstract class BaseAppService implements AppService {
book.updatedAt = Date.now();
book.uploadedAt = Date.now();
book.downloadedAt = Date.now();
} else {
throw new Error('Book file not uploaded');
}
}
async downloadBook(book: Book, onlyCover = false): Promise<void> {
const fps = [getCoverFilename(book)];
const bookFp = getFilename(book);
const coverFp = getCoverFilename(book);
const fps = [coverFp];
if (!onlyCover) {
fps.push(getFilename(book));
fps.push(bookFp);
}
let downloaded = false;
let bookDownloaded = false;
for (const fp of fps) {
let downloaded = false;
const existed = await this.fs.exists(fp, 'Books');
if (existed) {
downloaded = true;
@@ -245,8 +250,12 @@ export abstract class BaseAppService implements AppService {
await this.fs.writeFile(fp, 'Books', await fileobj.arrayBuffer());
downloaded = true;
}
if (fp === bookFp) {
bookDownloaded = downloaded;
}
}
if (!onlyCover && downloaded) {
// some books may not have cover image, so we need to check if the book is downloaded
if (bookDownloaded) {
book.downloadedAt = Date.now();
}
}
+1 -1
View File
@@ -351,7 +351,7 @@ export const READEST_WEB_BASE_URL = 'https://web.readest.com';
export const SYNC_PROGRESS_INTERVAL_SEC = 60;
export const SYNC_NOTES_INTERVAL_SEC = 60;
export const SYNC_BOOKS_INTERVAL_SEC = 60;
export const SYNC_BOOKS_INTERVAL_SEC = 10;
export const CHECK_UPDATE_INTERVAL_SEC = 24 * 60 * 60;
export const MAX_ZOOM_LEVEL = 140;