拆解页面脚本和应用层脚本的强关联
This commit is contained in:
@@ -2,7 +2,26 @@
|
||||
利用chrome的fetch来避免跨域
|
||||
**/
|
||||
|
||||
import {getImageBlob} from "@/utils/image";
|
||||
/**
|
||||
* 根据图片URL获取Blob对象
|
||||
* @param imageUrl
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
function getImageBlob(imageUrl) {
|
||||
return new Promise((resolve) => {
|
||||
fetch(imageUrl).then((response) => response.blob()) // 将响应转换为Blob对象
|
||||
.then((blobData) => {
|
||||
const fileName = imageUrl.match(/\/([^/]+)$/).at(-1)
|
||||
const reader = new FileReader();
|
||||
// 读取Blob对象的内容
|
||||
reader.onloadend = function () {
|
||||
const image = {blobData, fileName}
|
||||
resolve({image});
|
||||
};
|
||||
reader.readAsArrayBuffer(blobData); // 将Blob对象作为参数传递给FileReader的readAsArrayBuffer()方法
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
if (request.type == 'api') {
|
||||
|
||||
@@ -19,23 +19,6 @@ export function getImageMd5(imageUrl) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function getImageBlob(imageUrl) {
|
||||
return new Promise((resolve) => {
|
||||
fetch(imageUrl).then((response) => response.blob()) // 将响应转换为Blob对象
|
||||
.then((blobData) => {
|
||||
const fileName = imageUrl.match(/\/([^/]+)$/).at(-1)
|
||||
const reader = new FileReader();
|
||||
// 读取Blob对象的内容
|
||||
reader.onloadend = function () {
|
||||
const image = {blobData, fileName}
|
||||
resolve({image});
|
||||
};
|
||||
reader.readAsArrayBuffer(blobData); // 将Blob对象作为参数传递给FileReader的readAsArrayBuffer()方法
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export async function uploadImage(folderId, imageUrl, mallId) {
|
||||
let res1 = await getImageMd5(imageUrl)
|
||||
let detailList = []
|
||||
@@ -51,7 +34,7 @@ export async function uploadImage(folderId, imageUrl, mallId) {
|
||||
data: {
|
||||
createDetailList: detailList,
|
||||
folderId: folderId
|
||||
}})
|
||||
}})
|
||||
|
||||
if (res2.success) {
|
||||
if (res2.result.responseDetailList[0].alreadyExists) {
|
||||
@@ -75,7 +58,7 @@ export async function uploadImage(folderId, imageUrl, mallId) {
|
||||
upload_sign: res3.result.signature
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
let res5 = await sendChromeAPIMessage({
|
||||
url: 'marvel-mms/cn/api/kiana/gmp/bg/phoenix/api/material/edit',
|
||||
needMallId: true,
|
||||
@@ -92,4 +75,4 @@ export async function uploadImage(folderId, imageUrl, mallId) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user