From c8574dd5b0d1b6949b8010e1fefa445e6f241129 Mon Sep 17 00:00:00 2001 From: COOL Date: Tue, 28 Oct 2025 16:13:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DuploadWithKey=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=B7=AF=E5=BE=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/plugin/hooks/upload/index.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/modules/plugin/hooks/upload/index.ts b/src/modules/plugin/hooks/upload/index.ts index a078305..effb4b7 100644 --- a/src/modules/plugin/hooks/upload/index.ts +++ b/src/modules/plugin/hooks/upload/index.ts @@ -69,8 +69,20 @@ export class CoolPlugin extends BasePluginHook implements BaseUpload { async uploadWithKey(filePath: any, key: any) { const { domain } = this.pluginInfo.config; const data = fs.readFileSync(filePath); - fs.writeFileSync(path.join(this.app.getBaseDir(), '..', key), data); - return domain + key; + // 如果文件夹不存在则创建 + const dirPath = path.join( + pUploadPath(), + moment().format('YYYYMMDD'), + path.dirname(key) + ); + if (!fs.existsSync(dirPath)) { + fs.mkdirSync(dirPath, { recursive: true }); + } + fs.writeFileSync( + path.join(pUploadPath(), moment().format('YYYYMMDD'), key), + data + ); + return `${domain}/upload/${moment().format('YYYYMMDD')}/${key}`; } /**