|
@@ -77,27 +77,33 @@ export const api = !global.android
|
|
await window.open(await api.getFile(filename));
|
|
await window.open(await api.getFile(filename));
|
|
},
|
|
},
|
|
async getFile(url) {
|
|
async getFile(url) {
|
|
- const urlRaw = url;
|
|
|
|
- getFilesIng.push(urlRaw);
|
|
|
|
|
|
+ try {
|
|
|
|
+ const urlRaw = url;
|
|
|
|
+ getFilesIng.push(urlRaw);
|
|
|
|
|
|
- if (url.includes(baseURL)) {
|
|
|
|
- url = url.substring(baseURL.length);
|
|
|
|
- }
|
|
|
|
- url = url.trim();
|
|
|
|
- const paths = url.split("/");
|
|
|
|
- const notBase64BaseTypes = [".png", ".jpg"];
|
|
|
|
- const notBase64 = notBase64BaseTypes.some((type) =>
|
|
|
|
- paths[paths.length - 1].includes(type)
|
|
|
|
- );
|
|
|
|
- if (notBase64) {
|
|
|
|
- getFilesSuccess.push(urlRaw);
|
|
|
|
- // await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
|
|
- return baseURL + url;
|
|
|
|
- } else {
|
|
|
|
- const data = await axios.get(url, { responseType: "blob" });
|
|
|
|
- const base64 = await blobToBase64(data.data);
|
|
|
|
- getFilesSuccess.push(urlRaw);
|
|
|
|
- return URL.createObjectURL(base64ToBlob(base64));
|
|
|
|
|
|
+ if (url.includes(baseURL)) {
|
|
|
|
+ url = url.substring(baseURL.length);
|
|
|
|
+ }
|
|
|
|
+ url = url.trim();
|
|
|
|
+ const paths = url.split("/");
|
|
|
|
+ const notBase64BaseTypes = [".png", ".jpg"];
|
|
|
|
+ const notBase64 = notBase64BaseTypes.some((type) =>
|
|
|
|
+ paths[paths.length - 1].includes(type)
|
|
|
|
+ );
|
|
|
|
+ if (notBase64) {
|
|
|
|
+ getFilesSuccess.push(urlRaw);
|
|
|
|
+ // await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
|
|
+ console.error(baseURL + url);
|
|
|
|
+ return baseURL + url;
|
|
|
|
+ } else {
|
|
|
|
+ const data = await axios.get(url, { responseType: "blob" });
|
|
|
|
+ const base64 = await blobToBase64(data.data);
|
|
|
|
+ getFilesSuccess.push(urlRaw);
|
|
|
|
+ return URL.createObjectURL(base64ToBlob(base64));
|
|
|
|
+ }
|
|
|
|
+ } catch (e) {
|
|
|
|
+ console.error("获取文件失败 url:", url);
|
|
|
|
+ throw e;
|
|
}
|
|
}
|
|
},
|
|
},
|
|
async photograph(rotate = true) {
|
|
async photograph(rotate = true) {
|
|
@@ -180,7 +186,16 @@ export const api = !global.android
|
|
const apiName = `getImageCallback${global.count++}`;
|
|
const apiName = `getImageCallback${global.count++}`;
|
|
global[apiName] = (base64) => {
|
|
global[apiName] = (base64) => {
|
|
getFilesSuccess.push(urlRaw);
|
|
getFilesSuccess.push(urlRaw);
|
|
- resolve(URL.createObjectURL(base64ToBlob(base64)));
|
|
|
|
|
|
+ try {
|
|
|
|
+ resolve(URL.createObjectURL(base64ToBlob(base64)));
|
|
|
|
+ } catch (e) {
|
|
|
|
+ console.error(
|
|
|
|
+ "getFile 失败 获取url:",
|
|
|
|
+ fileUrl,
|
|
|
|
+ "获取结果:",
|
|
|
|
+ base64
|
|
|
|
+ );
|
|
|
|
+ }
|
|
delete global[apiName];
|
|
delete global[apiName];
|
|
};
|
|
};
|
|
global.android.getImage(fileUrl, apiName);
|
|
global.android.getImage(fileUrl, apiName);
|