This commit is contained in:
2026-08-26 15:59:08 +08:00
parent ee83d87a85
commit 3c283ada46
19 changed files with 196 additions and 46 deletions
+32
View File
@@ -78,6 +78,25 @@ function rawUpload(path, filePath, name, token) {
})
}
function overseasUrl(path) {
const value = String(path || '')
const normalized = /\/(?:api|overseas-api)$/.test(session.apiBase)
? value.replace(/^\/api(?=\/)/, '')
: value
return `${session.apiBase}${normalized}`
}
function rawDownload(path, token) {
return new Promise((resolve, reject) => {
uni.downloadFile({
url: overseasUrl(path),
header: { Authorization: `Bearer ${token}` },
success: resolve,
fail: (cause) => reject(Object.assign(new Error(cause.errMsg || '签收照片下载失败'), { network: true }))
})
})
}
export async function overseasUpload(path, filePath, name = 'file', retry = true) {
const attemptedToken = session.token
let response = await rawUpload(path, filePath, name, attemptedToken)
@@ -92,4 +111,17 @@ export async function overseasUpload(path, filePath, name = 'file', retry = true
return body.data
}
export async function overseasDownload(path, retry = true) {
const attemptedToken = session.token
let response = await rawDownload(path, attemptedToken)
if (retry && unauthorized(response)) {
const replacementToken = await tokenAfterUnauthorized(attemptedToken)
response = await rawDownload(path, replacementToken)
}
if (response?.statusCode !== 200 || !response?.tempFilePath) {
throw errorFrom({ ...response, data: {} }, '签收照片下载失败')
}
return response.tempFilePath
}
export function resetOverseasRequestStateForTest() { refreshPromise = null }