From e8bc9625af27e533e6524799e48b5e215908e6ae Mon Sep 17 00:00:00 2001 From: lcq Date: Sun, 30 Oct 2022 17:17:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=B9=A6=E7=AD=BE=E8=A7=A3?= =?UTF-8?q?=E7=A0=81=E9=94=99=E8=AF=AF=E7=BB=A7=E7=BB=AD=E8=BF=9B=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/api.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/controller/api.js b/src/controller/api.js index f2a23f0..184fba7 100644 --- a/src/controller/api.js +++ b/src/controller/api.js @@ -530,28 +530,35 @@ module.exports = class extends Base { let count = 0; let repeat = 0; - let tags = await this.model('tags').where({ userId: this.ctx.state.user.id }).select(); + let fail = 0; + let failStr = ""; + let tags = await this.model("tags").where({ userId: this.ctx.state.user.id }).select(); for (let bookmark of bookmarks) { - let find = await this.model('bookmarks').where({ userId: this.ctx.state.user.id, url: bookmark.url }).find(); + let find = await this.model("bookmarks").where({ userId: this.ctx.state.user.id, url: bookmark.url }).find(); if (think.isEmpty(find)) { - let tag = tags.find(item => item.name == bookmark.tagName); + let tag = tags.find((item) => item.name == bookmark.tagName); if (tag) { bookmark.tagId = tag.id; } else { bookmark.tagId = await this.model("tags").add({ userId: this.ctx.state.user.id, name: bookmark.tagName }); tags.push({ id: bookmark.tagId, - name: bookmark.tagName - }) + name: bookmark.tagName, + }); } delete bookmark.tagName; - await this.model("bookmarks").add(bookmark); + try { + await this.model("bookmarks").add(bookmark); + } catch (error) { + fail++; + failStr += bookmark.title + ","; + } count++; } else { repeat++; } } - this.json({ code: 0, data: count, msg: `书签传入${bookmarks.length}个,重复书签${repeat}个,成功导入${count}个。` }); + this.json({ code: 0, data: count, msg: `书签传入${bookmarks.length}个,重复书签${repeat}个,${fail}个导入失败:${failStr},成功导入${count}个。` }); } // 书签备份