From 3928b411af9a4b94d3074b487a1b4fb214f68cec Mon Sep 17 00:00:00 2001 From: geoffreychen777 Date: Sat, 25 Jun 2022 00:13:42 +0100 Subject: [PATCH] fix force delete bug --- .../file-repository/backends/local-backend.ts | 5 ++--- .../file-repository/backends/webdav-backend.ts | 10 ++++------ .../repositories/scraper-repository/scrapers/pdf.ts | 6 +++--- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/preload/repositories/file-repository/backends/local-backend.ts b/packages/preload/repositories/file-repository/backends/local-backend.ts index b513b69e..13c4f87a 100644 --- a/packages/preload/repositories/file-repository/backends/local-backend.ts +++ b/packages/preload/repositories/file-repository/backends/local-backend.ts @@ -58,9 +58,8 @@ export class LocalFileBackend implements FileBackend { try { await fsPromise.copyFile(_sourceURL, _targetURL); if ( - ((this.preference.get("deleteSourceFile") as boolean) && - _sourceURL !== _targetURL) || - forceDelete + ((this.preference.get("deleteSourceFile") as boolean) || forceDelete) && + _sourceURL !== _targetURL ) { await fsPromise.unlink(sourceURL); } diff --git a/packages/preload/repositories/file-repository/backends/webdav-backend.ts b/packages/preload/repositories/file-repository/backends/webdav-backend.ts index 9b177e6d..34950858 100644 --- a/packages/preload/repositories/file-repository/backends/webdav-backend.ts +++ b/packages/preload/repositories/file-repository/backends/webdav-backend.ts @@ -197,17 +197,15 @@ export class WebDavFileBackend implements FileBackend { if (sourceURL.startsWith("file://")) { success = await this._local2localMove(sourceURL, targetCacheURL); success = await this._local2serverMove(sourceURL, targetURL); - if ( - (this.preference.get("deleteSourceFile") as boolean) || - forceDelete - ) { + if (this.preference.get("deleteSourceFile") as boolean) { await fsPromise.unlink(sourceURL); } } else if (sourceURL.startsWith("webdav://")) { success = await this._server2serverMove(sourceURL, targetURL); if ( - (this.preference.get("deleteSourceFile") as boolean) || - forceDelete + ((this.preference.get("deleteSourceFile") as boolean) || + forceDelete) && + sourceURL !== targetURL ) { await this.webdavClient?.deleteFile( sourceURL.replace("webdav://", "/paperlib/") diff --git a/packages/preload/repositories/scraper-repository/scrapers/pdf.ts b/packages/preload/repositories/scraper-repository/scrapers/pdf.ts index e8883777..6cd86546 100644 --- a/packages/preload/repositories/scraper-repository/scrapers/pdf.ts +++ b/packages/preload/repositories/scraper-repository/scrapers/pdf.ts @@ -68,16 +68,16 @@ export class PDFScraper extends Scraper { }; const firstPageText = rawResponse.firstPageText; - entityDraft.setValue("title", metaData.info.Title); + entityDraft.setValue("title", metaData.info.Title || ""); let authors; - if (metaData.info.Author.includes(";")) { + if (metaData.info.Author?.includes(";")) { authors = metaData.info.Author.split(";") .map((author) => { return author.trim(); }) .join(", "); } else { - authors = metaData.info.Author; + authors = metaData.info.Author || ""; } entityDraft.setValue("authors", authors);