fix(onebot): support inline file url/path in send_group/private_msg (#80)
file 段现接受 file/url/path(无需先 upload_group_file/upload_private_file);群走 groupFile.upload()、私聊走 uploadPrivate()(内部已 publish/sendC2c),file_id 老路径不变。含 parser 与群/私聊文件发送测试。
This commit is contained in:
1 parent
69c8960ea9
commit
d3092a1806
5 files changed
+126
-83
No files matched your search
@@ -288,8 +288,9 @@ export async function segmentToElement(type: string, data: Record<string, unknow
|
||||
}
|
||||
case 'file': {
|
||||
const fileId = String(data.file_id ?? data.fileId ?? '').trim();
|
||||
if (!fileId) {
|
||||
log.warn('[MsgParser] file segment without file_id is unsupported (upload first via upload_group_file / upload_private_file)');
|
||||
const source = String(data.file ?? data.url ?? data.path ?? '').trim();
|
||||
if (!fileId && !source) {
|
||||
log.warn('[MsgParser] file segment without file_id or file/url is unsupported');
|
||||
return null;
|
||||
}
|
||||
const fileName = String(data.name ?? data.filename ?? data.fileName ?? '').trim();
|
||||
@@ -297,7 +298,7 @@ export async function segmentToElement(type: string, data: Record<string, unknow
|
||||
const md5Hex = String(data.md5 ?? data.md5Hex ?? '').trim();
|
||||
const sha1Hex = String(data.sha1 ?? data.sha1Hex ?? '').trim();
|
||||
const fileHash = String(data.file_hash ?? data.fileHash ?? '').trim();
|
||||
const elem: MessageElement = { type: 'file', fileId };
|
||||
const elem: MessageElement = fileId ? { type: 'file', fileId } : { type: 'file', url: source };
|
||||
if (fileName) elem.fileName = fileName;
|
||||
if (fileSize > 0) elem.fileSize = fileSize;
|
||||
if (md5Hex) elem.md5Hex = md5Hex;
|
||||
|
||||
Reference in new issue
Block a user