|
|
@@ -182,3 +182,38 @@ export async function downloadAttachmentFile(
|
|
|
}
|
|
|
triggerAnchorDownload(href, fileName)
|
|
|
}
|
|
|
+
|
|
|
+/** 附件内容:预签名 URL → Blob(供 ZIP 打包);预签名失败时回退直连。 */
|
|
|
+export async function fetchAttachmentBlob(
|
|
|
+ file: AttachmentDownloadItem,
|
|
|
+ options?: { fullFileUrl?: (url: string) => string }
|
|
|
+): Promise<Blob> {
|
|
|
+ const fileUrl = String(file.fileUrl || '').trim()
|
|
|
+ if (!fileUrl) {
|
|
|
+ throw new Error('empty fileUrl')
|
|
|
+ }
|
|
|
+ const fileName = String(file.fileName || '').trim() || fileUrl.split('/').pop() || 'download'
|
|
|
+
|
|
|
+ let href = ''
|
|
|
+ try {
|
|
|
+ const res = await fetchAttachmentDownloadUrl({ fileUrl, fileName })
|
|
|
+ if (res?.downloadUrl) href = res.downloadUrl
|
|
|
+ } catch {
|
|
|
+ // fall through
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!href) {
|
|
|
+ const resolveUrl = options?.fullFileUrl || ((url: string) => url)
|
|
|
+ href = resolveUrl(fileUrl)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!href) {
|
|
|
+ throw new Error('无法获取文件下载地址')
|
|
|
+ }
|
|
|
+
|
|
|
+ const resp = await fetch(href)
|
|
|
+ if (!resp.ok) {
|
|
|
+ throw new Error(`download failed: ${resp.status}`)
|
|
|
+ }
|
|
|
+ return resp.blob()
|
|
|
+}
|