From dc7da23e2758b8c67b48a3599db45ab8b17c9572 Mon Sep 17 00:00:00 2001 From: LittleC <26459759+XxLittleCxX@users.noreply.github.com> Date: Sun, 24 Mar 2024 01:51:30 +0800 Subject: [PATCH 1/4] feat(qq): send image without `server-temp` --- adapters/qq/src/message.ts | 19 ++++++------------- adapters/qq/src/types.ts | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/adapters/qq/src/message.ts b/adapters/qq/src/message.ts index 958430fc..fd32471a 100644 --- a/adapters/qq/src/message.ts +++ b/adapters/qq/src/message.ts @@ -2,7 +2,6 @@ import * as QQ from './types' import { Context, Dict, h, MessageEncoder, Quester } from '@satorijs/satori' import { QQBot } from './bot' import { QQGuildBot } from './bot/guild' -import { Entry } from '@satorijs/server-temp' export const escapeMarkdown = (val: string) => val @@ -301,16 +300,7 @@ export class QQMessageEncoder extends MessageEncode } async sendFile(type: string, attrs: Dict) { - let url = attrs.src || attrs.url, entry: Entry | undefined - if (await this.bot.ctx.http.isLocal(url)) { - const temp = this.bot.ctx.get('server.temp') - if (!temp) { - return this.bot.logger.warn('missing temporary file service, cannot send assets with private url') - } - entry = await temp.create(url) - url = entry.url - } - await this.flush() + let url = attrs.src || attrs.url let file_type = 0 if (type === 'img' || type === 'image') file_type = 1 else if (type === 'video') file_type = 2 @@ -318,9 +308,13 @@ export class QQMessageEncoder extends MessageEncode else return const data: QQ.Message.File.Request = { file_type, - url, srv_send_msg: false, } + if (await this.bot.ctx.http.isLocal(url)) { + data.file_data = Buffer.from((await this.bot.ctx.http.file(url)).data).toString('base64') + } else { + data.url = url + } let res: QQ.Message.File.Response try { if (this.session.isDirect) { @@ -337,7 +331,6 @@ export class QQMessageEncoder extends MessageEncode await this.sendFile(type, attrs) } } - entry?.dispose?.() this.retry = false return res } diff --git a/adapters/qq/src/types.ts b/adapters/qq/src/types.ts index fb0b437d..b63946df 100644 --- a/adapters/qq/src/types.ts +++ b/adapters/qq/src/types.ts @@ -455,7 +455,7 @@ export namespace Message { } export interface Request { file_type: Type - url: string + url?: string srv_send_msg: boolean file_data?: unknown } From 80f3ef67224e0441f73f46f5c9f6a56fd7bf93ad Mon Sep 17 00:00:00 2001 From: LittleC <26459759+XxLittleCxX@users.noreply.github.com> Date: Sun, 24 Mar 2024 01:55:31 +0800 Subject: [PATCH 2/4] fix(qq): make lint happy --- adapters/qq/src/message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/qq/src/message.ts b/adapters/qq/src/message.ts index fd32471a..345937d6 100644 --- a/adapters/qq/src/message.ts +++ b/adapters/qq/src/message.ts @@ -300,7 +300,7 @@ export class QQMessageEncoder extends MessageEncode } async sendFile(type: string, attrs: Dict) { - let url = attrs.src || attrs.url + const url = attrs.src || attrs.url let file_type = 0 if (type === 'img' || type === 'image') file_type = 1 else if (type === 'video') file_type = 2 From f5e4ae7636fc02c89f4abd5c55e87e9399988a30 Mon Sep 17 00:00:00 2001 From: LittleC <26459759+XxLittleCxX@users.noreply.github.com> Date: Sun, 24 Mar 2024 15:02:11 +0800 Subject: [PATCH 3/4] fix(qq): send base64 --- adapters/qq/src/message.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adapters/qq/src/message.ts b/adapters/qq/src/message.ts index 345937d6..451c8b56 100644 --- a/adapters/qq/src/message.ts +++ b/adapters/qq/src/message.ts @@ -310,7 +310,10 @@ export class QQMessageEncoder extends MessageEncode file_type, srv_send_msg: false, } - if (await this.bot.ctx.http.isLocal(url)) { + let capture = /^data:([\w/-]+);base64,(.*)$/.exec(url) + if (capture?.[2]) { + data.file_data = capture[2] + } else if (await this.bot.ctx.http.isLocal(url)) { data.file_data = Buffer.from((await this.bot.ctx.http.file(url)).data).toString('base64') } else { data.url = url From 9b0802a4a8c8597f16abaf33fdc7faac01ce1224 Mon Sep 17 00:00:00 2001 From: Shigma Date: Sun, 24 Mar 2024 17:46:21 +0800 Subject: [PATCH 4/4] Update adapters/qq/src/message.ts --- adapters/qq/src/message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/qq/src/message.ts b/adapters/qq/src/message.ts index 451c8b56..cc02a2cf 100644 --- a/adapters/qq/src/message.ts +++ b/adapters/qq/src/message.ts @@ -310,7 +310,7 @@ export class QQMessageEncoder extends MessageEncode file_type, srv_send_msg: false, } - let capture = /^data:([\w/-]+);base64,(.*)$/.exec(url) + const capture = /^data:([\w/-]+);base64,(.*)$/.exec(url) if (capture?.[2]) { data.file_data = capture[2] } else if (await this.bot.ctx.http.isLocal(url)) {