优化
This commit is contained in:
+6
-1
@@ -116,7 +116,8 @@ export async function overseasUpload(path, filePath, name = 'file', retry = true
|
||||
return body.data
|
||||
}
|
||||
|
||||
export async function overseasDownload(path, retry = true) {
|
||||
export async function overseasDownload(path, options = {}) {
|
||||
const { retry = true, expectedContentTypePrefix = '' } = options
|
||||
const attemptedToken = session.token
|
||||
let response = await rawDownload(path, attemptedToken)
|
||||
if (retry && unauthorized(response)) {
|
||||
@@ -126,6 +127,10 @@ export async function overseasDownload(path, retry = true) {
|
||||
if (response?.statusCode !== 200 || !response?.tempFilePath) {
|
||||
throw errorFrom({ ...response, data: {} }, '签收照片下载失败')
|
||||
}
|
||||
const contentType = String(response?.header?.['content-type'] || response?.header?.['Content-Type'] || '').toLowerCase()
|
||||
if (expectedContentTypePrefix && !contentType.startsWith(expectedContentTypePrefix.toLowerCase())) {
|
||||
throw errorFrom({ ...response, data: {} }, '照片服务返回了无效内容,请稍后重试')
|
||||
}
|
||||
return response.tempFilePath
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user