diff --git a/ui/src/api/API_README.md b/ui/src/api/API_README.md index 086f93ff9d8..f3a6761b785 100644 --- a/ui/src/api/API_README.md +++ b/ui/src/api/API_README.md @@ -847,3 +847,10 @@ PUT `/v3/application//chat//chat_record//vote` `1`(不满意)字符串,`vote_reason` 为单选原因,`vote_other_content` 为补充说明。 满意原因支持 `accurate`、`complete`、`other`,不满意支持 `inaccurate`、`incomplete`、`other`。 已评价记录须先撤销才能再次评价;历史记录通过同名字段回显。 + +## URL 附件读取 + +Admin 与 Chat 的 `file.ts` 提供 `getUrlFile(applicationId, url)`,请求 `/oss/get_url/{applicationId}`, +返回共享类型 `UrlFileContent`:响应状态、Content-Type、Content-Length 和 content。 +后端对 text/json 类型返回文本原文,其他内容返回 Base64。对话装配层注入各入口的文件 API, +输入组件负责类型、大小校验及需要落库的文件转上传,不跨入口复用请求客户端。 diff --git a/ui/src/api/admin/file.ts b/ui/src/api/admin/file.ts index 3fb5eaf7ff0..4111bcaa6d0 100644 --- a/ui/src/api/admin/file.ts +++ b/ui/src/api/admin/file.ts @@ -1,6 +1,6 @@ import type { AxiosProgressEvent } from 'axios' -import { postUpload, del } from './core/request' -import type { FileSourceType } from '@/api/types' +import { postUpload, del, get } from './core/request' +import type { FileSourceType, UrlFileContent } from '@/api/types' /** 上传资源文件,支持可选的进度回调与取消操作。 */ const postUploadFile = ( @@ -19,4 +19,7 @@ const postUploadFile = ( /** 删除已上传的资源文件。 */ const deleteFile = (fileId: string) => del(`/oss/file/${fileId}`) -export default { postUploadFile, deleteFile } +/** 获取 URL 文件内容、类型和大小。 */ +const getUrlFile = (applicationId: string, url: string) => get(`/oss/get_url/${applicationId}`, { url }) + +export default { getUrlFile, postUploadFile, deleteFile } diff --git a/ui/src/api/chat/file.ts b/ui/src/api/chat/file.ts index 060a999559a..a03965a21fb 100644 --- a/ui/src/api/chat/file.ts +++ b/ui/src/api/chat/file.ts @@ -1,6 +1,6 @@ import type { AxiosProgressEvent } from 'axios' -import { postUpload } from './core/request' -import type { FileSourceType } from '@/api/types' +import { postUpload, get } from './core/request' +import type { FileSourceType, UrlFileContent } from '@/api/types' /** 上传资源文件,支持可选的进度回调与取消操作。 */ const postUploadFile = ( @@ -16,4 +16,7 @@ const postUploadFile = ( return postUpload('/oss/file', formData, onProgress) } -export default { postUploadFile } +/** 获取 URL 文件内容、类型和大小。 */ +const getUrlFile = (applicationId: string, url: string) => get(`/oss/get_url/${applicationId}`, { url }) + +export default { getUrlFile, postUploadFile } diff --git a/ui/src/api/types/file.ts b/ui/src/api/types/file.ts index 5642593da34..20d5ab1e02c 100644 --- a/ui/src/api/types/file.ts +++ b/ui/src/api/types/file.ts @@ -1,3 +1,11 @@ import type { FILE_SOURCE_TYPE } from '@/api/enums' export type FileSourceType = (typeof FILE_SOURCE_TYPE)[keyof typeof FILE_SOURCE_TYPE] + +/** 服务端读取远程 URL 后返回的内容与响应头。 */ +export interface UrlFileContent { + status_code: number + 'Content-Type': string + 'Content-Length': string | number | null + content: string +} diff --git a/ui/src/conversation-panel/components/message-input/index.ts b/ui/src/conversation-panel/components/message-input/index.ts index a2e9c1e579b..39dfbb2bfc9 100644 --- a/ui/src/conversation-panel/components/message-input/index.ts +++ b/ui/src/conversation-panel/components/message-input/index.ts @@ -4,7 +4,8 @@ import { pick } from 'lodash' import { IMAGE_EXTENSIONS, DOCUMENT_EXTENSIONS, VIDEO_EXTENSIONS, AUDIO_EXTENSIONS } from '@/constants/file-type' import { isImage, isDocument, isAudio, isVideo, getFileExtension } from '@/utils/icon' import { MsgError, MsgWarning } from '@/utils/message' -import type { Dict } from '@/api/types' +import { URL_FILE_MIME_TYPES, createUrlFile } from './url-upload/index' +import type { UrlFileContent, Dict } from '@/api/types' import { defaultFileUploadSetting } from '@/workflow-canvas/nodes/base-node/constant' import type { BaseNodeForm, FileUploadSettingData } from '@/workflow-canvas/nodes/base-node/types' import type { ChatMessage, Conversation, ConversationAppInfo, SendMessageOptions } from '../../core/types' @@ -14,7 +15,8 @@ export interface FileItem { uid: number name: string size: number - raw: File + raw?: File + attachmentType?: MessageAttachmentKey url?: string file_id?: string previewUrl?: string @@ -40,6 +42,7 @@ export interface QuestionOptions { // 仅注入消息输入所需的会话、上传和发送能力。 export interface MessageInputDeps { + getUrlFile: (url: string) => Promise // 来自 conversation-list conversations: Ref getChatId: () => string @@ -79,6 +82,7 @@ export function createMessageInputStore(deps: MessageInputDeps) { const question = ref('') const fileList = ref([]) const sending = ref(false) + const urlUploading = ref(false) // 文件上传配置:优先读取开始节点,缺失时回退到智能体字段,再补齐默认值。 const baseNodeData = computed(() => { @@ -92,7 +96,6 @@ export function createMessageInputStore(deps: MessageInputDeps) { const fileUploadEnabled = computed(() => Boolean(baseNodeData.value.file_upload_enable ?? appInfo.value?.file_upload_enable)) /** 本地上传:控制上传按钮、拖拽与粘贴入口。 */ const uploadEnabled = computed(() => fileUploadEnabled.value && uploadSetting.value.local_upload) - // TODO: URL 上传入口未实现,页面接入时使用 urlUploadEnabled 控制显示,并复用数量、大小、类型限制。 const urlUploadEnabled = computed(() => fileUploadEnabled.value && uploadSetting.value.url_upload) const maxFiles = computed(() => uploadSetting.value.maxFiles) const maxSizeMB = computed(() => uploadSetting.value.fileLimit) @@ -110,7 +113,13 @@ export function createMessageInputStore(deps: MessageInputDeps) { }) const acceptList = computed(() => allowedExtensions.value.map((extension) => `.${extension}`).join(',')) const canUpload = computed( - () => uploadEnabled.value && !disabled.value && !streamLoading.value && !sending.value && fileList.value.length < maxFiles.value, + () => + (uploadEnabled.value || urlUploadEnabled.value) && + !disabled.value && + !streamLoading.value && + !sending.value && + !urlUploading.value && + fileList.value.length < maxFiles.value, ) // 语音输入:智能体开启语音转文字且当前模式提供接口时可用 @@ -131,10 +140,118 @@ export function createMessageInputStore(deps: MessageInputDeps) { !streamLoading.value && !sending.value && !transcribing.value && + !urlUploading.value && attachmentsReady.value, ) - const imageFiles = computed(() => fileList.value.filter((attachment) => isImage(attachment.name))) + const imageFiles = computed(() => + fileList.value.filter((attachment) => attachment.attachmentType === 'image_list' || (!attachment.attachmentType && isImage(attachment.name))), + ) + + // URL 上传:服务端读取远程文件,校验后按类型保留地址或转为本地上传。 + const urlUploadTypes = computed(() => + [ + { enabled: uploadSetting.value.document, value: 'document_list' as const, label: '文档' }, + { enabled: uploadSetting.value.image, value: 'image_list' as const, label: '图片' }, + { enabled: uploadSetting.value.audio, value: 'audio_list' as const, label: '音频' }, + { enabled: uploadSetting.value.video, value: 'video_list' as const, label: '视频' }, + { enabled: uploadSetting.value.other, value: 'other_list' as const, label: '其他' }, + ].filter((type) => type.enabled), + ) + const addUrls = async (addresses: string[], attachmentType: MessageAttachmentKey): Promise => { + if ( + !addresses.length || + urlUploading.value || + !urlUploadEnabled.value || + !canUpload.value || + !urlUploadTypes.value.some((type) => type.value === attachmentType) + ) + return false + if (fileList.value.length + addresses.length > maxFiles.value) { + MsgWarning(`单次最多上传 ${maxFiles.value} 个文件`) + return false + } + const validAddresses = addresses.filter((address) => { + try { + return ['http:', 'https:'].includes(new URL(address).protocol) + } catch { + return false + } + }) + if (validAddresses.length !== addresses.length) MsgWarning('请输入有效的 HTTP 或 HTTPS URL 地址') + if (!validAddresses.length) return false + const extensions = + attachmentType === 'image_list' + ? IMAGE_EXTENSIONS + : attachmentType === 'document_list' + ? DOCUMENT_EXTENSIONS + : attachmentType === 'audio_list' + ? AUDIO_EXTENSIONS + : attachmentType === 'video_list' + ? VIDEO_EXTENSIONS + : (uploadSetting.value.otherExtensions ?? []) + const expectedMimes = extensions.flatMap((extension) => URL_FILE_MIME_TYPES[extension.toLowerCase()] ?? []) + // 先占用附件名额,避免并发上传超限,也阻止校验完成前发送。 + const attachments = validAddresses.map((address) => + reactive({ + uid: Date.now() + Math.random(), + name: new URL(address).pathname.split('/').filter(Boolean).pop() || `file_${Date.now()}`, + size: 0, + url: address, + attachmentType, + status: 'uploading', + progress: 0, + }), + ) + fileList.value.push(...attachments) + urlUploading.value = true + try { + const results = await Promise.all( + attachments.map(async (attachment) => { + try { + const response = await deps.getUrlFile(attachment.url!) + if (!fileList.value.includes(attachment)) return false + if (response.status_code !== 200) throw new Error('URL 地址无效') + const mime = (response['Content-Type'] || '').split(';')[0]!.trim().toLowerCase() + if (expectedMimes.length && !expectedMimes.includes(mime)) throw new Error('文件类型与所选类型不匹配') + const size = Number(response['Content-Length']) || 0 + if (size > maxSizeMB.value * 1024 * 1024) throw new Error(`每个文件不能超过 ${maxSizeMB.value}MB`) + if (!attachment.name.includes('.')) { + const extension = + extensions.find((extension) => URL_FILE_MIME_TYPES[extension.toLowerCase()] === mime) ?? + Object.keys(URL_FILE_MIME_TYPES).find((extension) => URL_FILE_MIME_TYPES[extension] === mime) + if (extension) attachment.name += `.${extension.toLowerCase()}` + } + attachment.size = size + if (attachmentType === 'document_list' || attachmentType === 'audio_list' || attachmentType === 'other_list') { + const file = createUrlFile(response.content, attachment.name, mime) + if (file.size > maxSizeMB.value * 1024 * 1024) throw new Error(`每个文件不能超过 ${maxSizeMB.value}MB`) + if (!file.size) throw new Error('不能上传空文件') + attachment.raw = file + attachment.size = file.size + attachment.url = undefined + attachment.status = 'ready' + await uploadAttachment(attachment) + return fileList.value.some((file) => file.uid === attachment.uid && file.status === 'success') + } + attachment.status = 'success' + attachment.progress = 100 + return true + } catch (error) { + const index = fileList.value.indexOf(attachment) + if (index >= 0) { + removeFile(index) + MsgWarning(`${attachment.url || attachment.name}:${error instanceof Error ? error.message : '读取 URL 文件失败'}`) + } + return false + } + }), + ) + return results.some(Boolean) + } finally { + urlUploading.value = false + } + } // 附件上传与本地预览 /** 校验单个文件,返回不通过的提示;拖拽、粘贴不受 accept 限制,需校验扩展名。 */ @@ -171,9 +288,10 @@ export function createMessageInputStore(deps: MessageInputDeps) { attachment.status = 'uploading' attachment.progress = 0 attachment.errMsg = '' - void Promise.resolve() + return Promise.resolve() .then(() => { if (!fileList.value.includes(attachment)) return + if (!attachment.raw) return return uploadFile(attachment.raw, getChatId(), (percent) => { if (!fileList.value.includes(attachment)) return // 文件传输结束后仍等待服务端处理,成功响应前最多显示 95%。 @@ -277,7 +395,8 @@ export function createMessageInputStore(deps: MessageInputDeps) { const message: QuestionMessage = { type: 'QUESTION', content: question.value.trim() } for (const attachment of fileList.value) { let attachmentKey: MessageAttachmentKey = 'other_list' - if (isImage(attachment.name)) attachmentKey = 'image_list' + if (attachment.attachmentType) attachmentKey = attachment.attachmentType + else if (isImage(attachment.name)) attachmentKey = 'image_list' else if (isDocument(attachment.name)) attachmentKey = 'document_list' else if (isAudio(attachment.name)) attachmentKey = 'audio_list' else if (isVideo(attachment.name)) attachmentKey = 'video_list' @@ -344,6 +463,9 @@ export function createMessageInputStore(deps: MessageInputDeps) { fileList, uploadEnabled, urlUploadEnabled, + urlUploadTypes, + urlUploading, + addUrls, canUpload, maxFiles, maxSizeMB, diff --git a/ui/src/conversation-panel/components/message-input/index.vue b/ui/src/conversation-panel/components/message-input/index.vue index 0c81c28f627..eff236256ac 100644 --- a/ui/src/conversation-panel/components/message-input/index.vue +++ b/ui/src/conversation-panel/components/message-input/index.vue @@ -1,5 +1,5 @@ @@ -100,9 +108,12 @@ const { recording, seconds: recordSeconds, waveLevels, start: startRecording, st
+ - - + + + + - + + - diff --git a/ui/src/conversation-panel/components/message-input/url-upload/index.ts b/ui/src/conversation-panel/components/message-input/url-upload/index.ts new file mode 100644 index 00000000000..0062bcb678f --- /dev/null +++ b/ui/src/conversation-panel/components/message-input/url-upload/index.ts @@ -0,0 +1,129 @@ +export const URL_FILE_MIME_TYPES: Record = { + html: 'text/html', + htm: 'text/html', + shtml: 'text/html', + css: 'text/css', + xml: 'text/xml', + gif: 'image/gif', + jpeg: 'image/jpeg', + jpg: 'image/jpeg', + js: 'application/javascript', + atom: 'application/atom+xml', + rss: 'application/rss+xml', + mml: 'text/mathml', + txt: 'text/plain', + jad: 'text/vnd.sun.j2me.app-descriptor', + wml: 'text/vnd.wap.wml', + htc: 'text/x-component', + avif: 'image/avif', + png: 'image/png', + svg: 'image/svg+xml', + svgz: 'image/svg+xml', + tif: 'image/tiff', + tiff: 'image/tiff', + wbmp: 'image/vnd.wap.wbmp', + webp: 'image/webp', + ico: 'image/x-icon', + jng: 'image/x-jng', + bmp: 'image/x-ms-bmp', + woff: 'font/woff', + woff2: 'font/woff2', + jar: 'application/java-archive', + war: 'application/java-archive', + ear: 'application/java-archive', + json: 'application/json', + hqx: 'application/mac-binhex40', + doc: 'application/msword', + pdf: 'application/pdf', + ps: 'application/postscript', + docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + eps: 'application/postscript', + ai: 'application/postscript', + rtf: 'application/rtf', + m3u8: 'application/vnd.apple.mpegurl', + kml: 'application/vnd.google-earth.kml+xml', + kmz: 'application/vnd.google-earth.kmz', + xls: 'application/vnd.ms-excel', + eot: 'application/vnd.ms-fontobject', + ppt: 'application/vnd.ms-powerpoint', + odg: 'application/vnd.oasis.opendocument.graphics', + odp: 'application/vnd.oasis.opendocument.presentation', + ods: 'application/vnd.oasis.opendocument.spreadsheet', + odt: 'application/vnd.oasis.opendocument.text', + wmlc: 'application/vnd.wap.wmlc', + wasm: 'application/wasm', + '7z': 'application/x-7z-compressed', + cco: 'application/x-cocoa', + jardiff: 'application/x-java-archive-diff', + jnlp: 'application/x-java-jnlp-file', + run: 'application/x-makeself', + pl: 'application/x-perl', + pm: 'application/x-perl', + prc: 'application/x-pilot', + pdb: 'application/x-pilot', + rar: 'application/x-rar-compressed', + rpm: 'application/x-redhat-package-manager', + sea: 'application/x-sea', + swf: 'application/x-shockwave-flash', + sit: 'application/x-stuffit', + tcl: 'application/x-tcl', + tk: 'application/x-tcl', + der: 'application/x-x509-ca-cert', + pem: 'application/x-x509-ca-cert', + crt: 'application/x-x509-ca-cert', + xpi: 'application/x-xpinstall', + xhtml: 'application/xhtml+xml', + xspf: 'application/xspf+xml', + zip: 'application/zip', + bin: 'application/octet-stream', + exe: 'application/octet-stream', + dll: 'application/octet-stream', + deb: 'application/octet-stream', + dmg: 'application/octet-stream', + iso: 'application/octet-stream', + img: 'application/octet-stream', + msi: 'application/octet-stream', + msp: 'application/octet-stream', + msm: 'application/octet-stream', + mid: 'audio/midi', + midi: 'audio/midi', + kar: 'audio/midi', + mp3: 'audio/mpeg', + ogg: 'audio/ogg', + m4a: 'audio/x-m4a', + ra: 'audio/x-realaudio', + '3gpp': 'video/3gpp', + '3gp': 'video/3gpp', + ts: 'video/mp2t', + mp4: 'video/mp4', + mpeg: 'video/mpeg', + mpg: 'video/mpeg', + mov: 'video/quicktime', + webm: 'video/webm', + flv: 'video/x-flv', + m4v: 'video/x-m4v', + mng: 'video/x-mng', + asx: 'video/x-ms-asf', + asf: 'video/x-ms-asf', + wmv: 'video/x-ms-wmv', + avi: 'video/x-msvideo', + wav: 'audio/wav', + flac: 'audio/flac', + aac: 'audio/aac', + opus: 'audio/opus', + csv: 'text/csv', + tsv: 'text/tab-separated-values', + ics: 'text/calendar', +} + +/** 后端对文本返回原文,对二进制文件返回 Base64。 */ +export function createUrlFile(content: string, name: string, mime: string): File { + if (/^(text\/|application\/(json|javascript|xml))/.test(mime) && !content.startsWith('data:')) { + return new File([content], name, { type: mime }) + } + const encoded = content.startsWith('data:') ? content.slice(content.indexOf(',') + 1) : content + const bytes = Uint8Array.from(atob(encoded), (character) => character.charCodeAt(0)) + return new File([bytes], name, { type: mime }) +} diff --git a/ui/src/conversation-panel/components/message-input/url-upload/index.vue b/ui/src/conversation-panel/components/message-input/url-upload/index.vue new file mode 100644 index 00000000000..2e008e92174 --- /dev/null +++ b/ui/src/conversation-panel/components/message-input/url-upload/index.vue @@ -0,0 +1,81 @@ + + + diff --git a/ui/src/conversation-panel/view/chat/index.ts b/ui/src/conversation-panel/view/chat/index.ts index a4f05c2bc03..47cf6bf95af 100644 --- a/ui/src/conversation-panel/view/chat/index.ts +++ b/ui/src/conversation-panel/view/chat/index.ts @@ -119,6 +119,7 @@ export function createChatConversation(routing: ChatConversationRouting = useApp streamLoading: msgs.streamLoading, sendMessage: msgs.sendMessage, uploadFile: msgs.uploadFile, + getUrlFile: (url) => FileApi.getUrlFile(getApplicationId(), url), stop: msgs.stop, speechToText: (data) => ConversationApi.postSpeechToText(getApplicationId(), data), appInfo, diff --git a/ui/src/conversation-panel/view/debug/index.ts b/ui/src/conversation-panel/view/debug/index.ts index 077c2e02885..ee9a3df84d0 100644 --- a/ui/src/conversation-panel/view/debug/index.ts +++ b/ui/src/conversation-panel/view/debug/index.ts @@ -22,9 +22,7 @@ import { useAdminAppInfo } from './app-info' export function createDebugConversation(application: Readonly>): ConversationBundle { const route = useRoute() const ConversationApi = isSystemResource() ? SystemResourceConversationApi : WorkspaceConversationApi - const appId = computed( - () => (route.params.id as string) || (route.params.applicationId as string) || '', - ) + const appId = computed(() => (route.params.id as string) || (route.params.applicationId as string) || '') const api: ConversationApiAdapter = { pageConversations: (p, s) => ConversationApi.getConversationPage(p, s, appId.value), pageRecords: (cid, p, s) => ConversationApi.getConversationRecordPage(cid, p, s, appId.value), @@ -68,6 +66,7 @@ export function createDebugConversation(application: Readonly FileApi.getUrlFile(appId.value, url), stop: msgs.stop, speechToText: (data) => ConversationApi.postSpeechToText(appId.value, data), appInfo, diff --git a/ui/src/styles/element-plus.scss b/ui/src/styles/element-plus.scss index 7c5d13842c2..526c297f2af 100644 --- a/ui/src/styles/element-plus.scss +++ b/ui/src/styles/element-plus.scss @@ -760,7 +760,7 @@ } } .el-select { - width: 90px; + width: 100px; } .el-select__wrapper { min-height: 28px; diff --git a/ui/src/views/VIEW_README.md b/ui/src/views/VIEW_README.md index 6874fb847f1..842cbe104d2 100644 --- a/ui/src/views/VIEW_README.md +++ b/ui/src/views/VIEW_README.md @@ -63,7 +63,7 @@ | `login/`、`login/forgot-password/` | Admin 登录与找回密码 | | `chat/`、`portal/` | 单应用与门户对话 | | `chat/share/` | 公开分享链接的只读问答展示与失败重试 | -| `chat/login/`、`chat/error/` | Chat 登录、独立 404 与服务不可用展示 | +| `chat/login/`、`chat/error/` | Chat 登录、独立 404 与服务不可用展示 | | `error/404.vue`、`error/NoPermission.vue`、`error/NoService.vue` | Admin 页面不存在、无访问权限与服务不可用展示 | | `details-demo/` | 临时执行详情预览 | @@ -515,6 +515,8 @@ System 资源管理的修正内容与添加知识库选项仅包含当前智能 ### 正式对话与门户 +`conversation-panel/components/message-input/url-upload/` 维护 URL 附件浮层:开启 URL 上传时,附件按钮打开浮层,按启用的文件类型选择分类、逐行输入 HTTP/HTTPS 地址。通过当前入口的文件 API 获取远程内容,校验响应状态、MIME 类型和大小,并补齐无扩展名的文件名;图片、视频保留原地址,文档、音频和其他文件转换为 File 后复用附件上传流程。URL 与本地文件共用附件总数限制,远程读取及转上传完成前禁止发送。本地上传开启时,允许输入区拖拽、文件粘贴上传,并通过浮层底部按钮选择文件;关闭本地上传时禁用这些入口。仅本地上传模式沿用原有直接选择入口。 + - Chat/Portal 页面以 auth token 为面板 key,token 变化重建并加载用户档案;路由认证见路由文档。 会话装配在 conversation-panel,列表 Store 不感知 Router;门户复用 chat 装配,保留各智能体最近会话分组。 账户菜单位于 `conversation-panel/left-sidebar/account-menu/index.vue`,单应用与门户共用;直接调用 Chat API 的 `postLogout()`,成功后清理当前认证场景并重新导航,由守卫处理后续认证。 diff --git a/ui/tests/conversation-url-upload.test.mjs b/ui/tests/conversation-url-upload.test.mjs new file mode 100644 index 00000000000..54496d8f2f4 --- /dev/null +++ b/ui/tests/conversation-url-upload.test.mjs @@ -0,0 +1,24 @@ +import assert from 'node:assert/strict' +import test from 'node:test' +import { createUrlFile } from '../src/conversation-panel/components/message-input/url-upload/index.ts' + +test('URL 文本附件保留中文和换行,不按 Base64 解码', async () => { + const content = '知识库内容\n第二行' + const file = createUrlFile(content, '知识.txt', 'text/plain') + assert.equal(await file.text(), content) + assert.equal(file.size, Buffer.byteLength(content)) +}) + +test('URL 二进制附件支持纯 Base64 和 data URL', async () => { + const bytes = Uint8Array.from([0, 127, 128, 255]) + const base64 = Buffer.from(bytes).toString('base64') + for (const content of [base64, `data:application/pdf;base64,${base64}`]) { + const file = createUrlFile(content, 'test.pdf', 'application/pdf') + assert.deepEqual(new Uint8Array(await file.arrayBuffer()), bytes) + assert.equal(file.type, 'application/pdf') + } +}) + +test('URL 附件拒绝损坏的 Base64', () => { + assert.throws(() => createUrlFile('%%%invalid', 'test.pdf', 'application/pdf')) +})