From 86b13fd67f2d6146f9aff72af3fa8ce7ed82e304 Mon Sep 17 00:00:00 2001 From: ZiuChen <457353192@qq.com> Date: Mon, 15 Aug 2022 17:14:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E6=9D=A1=E6=95=B0=E9=99=90=E5=88=B6=E4=B8=8E=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/preload.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/public/preload.js b/public/preload.js index 2fbbf00..c5bfbaa 100644 --- a/public/preload.js +++ b/public/preload.js @@ -23,29 +23,30 @@ class DB { } init() { const isExist = fs.existsSync(this.path) - if (isExist) { const data = fs.readFileSync(this.path, { encoding: 'utf8' }) - try { + // 读取磁盘记录到内存 const dataBase = JSON.parse(data) this.dataBase = dataBase + // 将超过14天的数据删除 + const now = new Date().getTime() + const deleteTime = now - '\u0031\u0034' * '\u0032\u0034' * 60 * 60 * 1000 // unicode + this.dataBase.data = this.dataBase.data.filter((item) => item.updateTime > deleteTime) + this.updateDataBaseLocal() } catch (err) { utools.showNotification('读取剪切板出错' + err) return } - return } - const defaultDB = { data: [], createTime: this.createTime, updateTime: this.updateTime } - this.dataBase = defaultDB this.updateDataBaseLocal(defaultDB) } @@ -65,6 +66,15 @@ class DB { addItem(cItem) { this.dataBase.data.unshift(cItem) this.updateDataBase() + // unicode + if (this.dataBase.data.length > '\u0035\u0030\u0030') { + // 达到条数限制 + this.dataBase.data.pop() + // 仍然大于: 超出了不止一条 + if (this.dataBase.data.length > '\u0035\u0030\u0030') { + this.dataBase.data = this.dataBase.data.splice(0, 499) + } + } this.updateDataBaseLocal() } emptyDataBase() {