fix(mobile): load supervisor review audio with auth

This commit is contained in:
2026-07-09 16:19:11 +08:00
parent f1a975b5f6
commit 7de6fa9969
2 changed files with 112 additions and 7 deletions
+44
View File
@@ -102,3 +102,47 @@ export const apiRequest = async <T>(options: RequestOptions): Promise<T> => {
return readPayload<T>(response.statusCode, response.data);
};
export const authenticatedFileUrl = async (url: string): Promise<string> => {
const fullUrl = normalizeUrl(url);
if (typeof XMLHttpRequest !== 'undefined' && typeof URL !== 'undefined') {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', fullUrl);
xhr.responseType = 'blob';
Object.entries(authHeaders(false)).forEach(([key, value]) => xhr.setRequestHeader(key, value));
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
resolve(URL.createObjectURL(xhr.response));
return;
}
if (xhr.status === 401 || xhr.status === 403) clearAuth();
reject(new Error(`HTTP ${xhr.status}`));
};
xhr.onerror = () => reject(new Error('网络请求失败'));
xhr.send();
});
}
return new Promise((resolve, reject) => {
uni.downloadFile({
url: fullUrl,
header: authHeaders(false),
success: (response) => {
if (response.statusCode >= 200 && response.statusCode < 300) {
resolve(response.tempFilePath);
return;
}
if (response.statusCode === 401 || response.statusCode === 403) clearAuth();
reject(new Error(`HTTP ${response.statusCode}`));
},
fail: () => reject(new Error('网络请求失败'))
});
});
};
export const releaseAuthenticatedFileUrl = (url: string) => {
if (url.startsWith('blob:') && typeof URL !== 'undefined') {
URL.revokeObjectURL(url);
}
};