From 7288eeac1fdd086aaaf8a25dd4afe09a6741aef4 Mon Sep 17 00:00:00 2001 From: Qquanwei Date: Tue, 31 May 2022 14:43:04 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BD=93=E6=B7=BB=E5=8A=A0=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 不会重复添加相同路径 --- src/package.json | 2 +- src/server/comicsservice.ts | 38 +++++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/package.json b/src/package.json index 52fff42..6cc4bc5 100644 --- a/src/package.json +++ b/src/package.json @@ -1,7 +1,7 @@ { "name": "electron-webtoon", "productName": "electron-webtoon", - "version": "2.3.5", + "version": "2.3.6", "description": "Electron application boilerplate based on React, React Router, Webpack, React Hot Loader for rapid application development", "main": "./main.prod.js", "author": { diff --git a/src/server/comicsservice.ts b/src/server/comicsservice.ts index d8bf5ea..ad6ae27 100644 --- a/src/server/comicsservice.ts +++ b/src/server/comicsservice.ts @@ -172,21 +172,39 @@ export default class ComicService { return R.find(R.propEq('id', id), library); } - async addComicToLibrary(comicpath: string) { + + isExistsAndTouch(comicPath: string) { const library = this.store.get('library'); - const newLibrary = (library || []).concat( - await this.buildNewComic(comicpath) - ); - this.store.set('library', newLibrary); + const index = R.findIndex(R.propEq('path', comicPath), library); + + if (index !== -1) { + const newLibrary = [...library]; + newLibrary.splice(index, 1); + this.store.set('library', [...newLibrary, library[index]]); + return true; + } + return false; + } + + async addComicToLibrary(comicpath: string) { + if (!this.isExistsAndTouch(comicpath)) { + const library = this.store.get('library'); + const newLibrary = (library || []).concat( + await this.buildNewComic(comicpath) + ); + this.store.set('library', newLibrary); + } } // add compress file meta info to config async addComicToLibrary2(comicpath: string, compressFilePath: string) { - const library = this.store.get('library'); - const newComic = await this.buildNewComic(comicpath); - newComic.compressFilePath = compressFilePath; - const newLibrary = (library || []).concat(newComic); - this.store.set('library', newLibrary); + if (!this.isExistsAndTouch(comicpath)) { + const library = this.store.get('library'); + const newComic = await this.buildNewComic(comicpath); + newComic.compressFilePath = compressFilePath; + const newLibrary = (library || []).concat(newComic); + this.store.set('library', newLibrary); + } } // 打开文件选择对话框