zcbot/web/static/js/attachments.js

20 lines
673 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 新消息使用结构化 attachment_refs这里只解析旧客户端与存量消息的正文标记。
const USER_ATTACHMENT_RE = /^\[(用户上传的参考图|用户上传的文件)\]\s+(.+?)\s*$/;
export function parseUserAttachments(content) {
const attachments = [];
const bodyLines = [];
for (const line of String(content || "").split("\n")) {
const match = line.match(USER_ATTACHMENT_RE);
if (!match) {
bodyLines.push(line);
continue;
}
attachments.push({
path: match[2],
kind: match[1] === "用户上传的参考图" ? "image" : "file",
});
}
return { content: bodyLines.join("\n").trim(), attachments };
}