From e7bf3dd3318d5318658ea5fe7bd50f7968162a48 Mon Sep 17 00:00:00 2001 From: LittleC <26459759+XxLittleCxX@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:07:46 +0800 Subject: [PATCH] feat(dingtalk): support send private url assets --- adapters/dingtalk/src/message.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/adapters/dingtalk/src/message.ts b/adapters/dingtalk/src/message.ts index c2b8bb19..a2ab9adf 100644 --- a/adapters/dingtalk/src/message.ts +++ b/adapters/dingtalk/src/message.ts @@ -2,6 +2,7 @@ import { Context, Dict, h, MessageEncoder } from '@satorijs/satori' import { DingtalkBot } from './bot' import FormData from 'form-data' import { SendMessageData } from './types' +import { Entry } from '@satorijs/server-temp' export const escape = (val: string) => val @@ -93,7 +94,16 @@ export class DingtalkMessageEncoder extends Message // await this.sendMessage('sampleImageMsg', { // photoURL: attrs.url // }) - this.buffer += `![${attrs.alt}](${attrs.url})` + if (await this.bot.http.isPrivate(attrs.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') + } + const entry: Entry | undefined = await temp.create(attrs.url) + this.buffer += `![${attrs.alt ?? ''}](${entry.url})` + } else { + this.buffer += `![${attrs.alt ?? ''}](${attrs.url})` + } } else if (type === 'message') { await this.flush() await this.render(children)