From 481ca177b7d953441b6c9908410ac30b22490e60 Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 13 May 2025 13:43:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96fanqie=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/fanqie.js | 34 +++++++++++++++++++++++++++++----- apps/reportBots.js | 2 +- package.json | 1 + 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/apps/fanqie.js b/apps/fanqie.js index 61570b7..6c6c5d1 100644 --- a/apps/fanqie.js +++ b/apps/fanqie.js @@ -2,7 +2,10 @@ import fs from 'node:fs'; import path from 'path'; import chokidar from 'chokidar'; import ConfigControl from '../lib/config/configControl.js'; +import configControl from '../lib/config/configControl.js'; import Fanqie from '../models/apps/fanqie/fanqie.js'; +import FromData from 'form-data'; +import axios from 'axios'; let redis = global.redis; @@ -191,16 +194,19 @@ export class xzq extends plugin { } } - const uploadOk = await this.upload(e, filePath); - this.clearCache(false, true, String(e.message_id)); + const uploadReturn = await this.upload(e, filePath); + await this.clearCache(false, true, String(e.message_id)); if (!uploadOk) return e.reply('上传失败', true); - e.reply(`《${book_info.book_name}》上传成功,用时 ${(Date.now() - startTime) / 1000}s`, true); + e.reply( + `《${book_info.book_name}》上传成功,用时 ${(Date.now() - startTime) / 1000}s\n下载链接为${uploadReturn.url},将在10分钟后删除,请及时下载` + ); return true; } async upload(e, filePath) { try { + /* let res; if (e.isGroup) { res = e.bot.sendApi('upload_group_file', { @@ -217,10 +223,28 @@ export class xzq extends plugin { }); } return !!res; + */ + const form = new FromData(); + const fileStream = fs.createReadStream(filePath); + form.append('file', fileStream); + form.append('token', configControl.get('coreConfig')?.token); + const uploadUrl = `${configControl.get('coreConfig')?.coreUrl}/upload?dir=fanqie&expire=600`; + const response = await axios.post(uploadUrl, form, { + headers: { + ...form.getHeaders(), + }, + maxContentLength: Infinity, + maxBodyLength: Infinity, + }); + if (response?.success) { + const url = response.data?.url; + const message = response.data?.message; + return { url, message }; + } } catch (err) { logger.error(`文件上传错误:${logger.red(err.stack)}`); - if (e?.reply) e.reply(`文件上传失败:${err.message}`, true); - return false; + e.reply(`文件上传失败:${err.message}`, true); + return null; } } } diff --git a/apps/reportBots.js b/apps/reportBots.js index 7012001..254c6f0 100644 --- a/apps/reportBots.js +++ b/apps/reportBots.js @@ -16,7 +16,7 @@ export default class ReportBots extends plugin { { name: 'crystelf定时同步', corn: '*/30 * * * *', - fnc: 'autoReport', + fnc: () => this.autoReport(), }, ], }); diff --git a/package.json b/package.json index e2f9ee2..c561884 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "dependencies": { "axios": "^1.8.4", "chalk": "^5.4.1", + "form-data": "^4.0.2", "openai": "^4.89.0", "ws": "^8.18.1" },