From f20abbe76770587d204987fc8c6d9c8c7c1a81b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Thu, 27 Jul 2023 08:37:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/system/add.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/system/add.js b/plugins/system/add.js index 0ae4695..2fa74dc 100644 --- a/plugins/system/add.js +++ b/plugins/system/add.js @@ -154,7 +154,7 @@ export class add extends plugin { if (!this.e.msg?.includes("#结束添加")) { /** 添加内容 */ for (const i of this.e.message) { - if (i.url) i.file = await this.saveFile(i.url) + if (i.url) i.file = await this.saveFile(i) if (i.type == "at" && i.qq == this.e.self_id) continue context.message.push(i) } @@ -204,22 +204,22 @@ export class add extends plugin { } async fileType(data) { - const file = {} + const file = { name: `${this.group_id}/${data.type}/${Date.now()}` } try { - file.url = data.replace(/^base64:\/\/.*/, "base64://...") - file.buffer = await this.makeBuffer(data) + file.url = data.url.replace(/^base64:\/\/.*/, "base64://...") + file.buffer = await this.makeBuffer(data.url) file.type = await fileTypeFromBuffer(file.buffer) - file.name = `${this.group_id}/${Date.now()}.${file.type.ext}` + file.name = `${file.name}.${file.type.ext}` } catch (err) { logger.error(`文件类型检测错误:${logger.red(err)}`) - file.name = `${this.group_id}/${Date.now()}-${path.basename(file.url)}` + file.name = `${file.name}-${path.basename(data.file || data.url)}` } return file } - async saveFile(url) { - const file = await this.fileType(url) - if (file.name && Buffer.isBuffer(file.buffer) && common.mkdirs(`${this.path}${this.group_id}`)) { + async saveFile(data) { + const file = await this.fileType(data) + if (file.name && Buffer.isBuffer(file.buffer) && common.mkdirs(path.dirname(`${this.path}${file.name}`))) { fs.writeFileSync(`${this.path}${file.name}`, file.buffer) return file.name }