拆解页面脚本和应用层脚本的强关联
This commit is contained in:
@@ -2,7 +2,26 @@
|
|||||||
利用chrome的fetch来避免跨域
|
利用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) => {
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||||
if (request.type == 'api') {
|
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) {
|
export async function uploadImage(folderId, imageUrl, mallId) {
|
||||||
let res1 = await getImageMd5(imageUrl)
|
let res1 = await getImageMd5(imageUrl)
|
||||||
let detailList = []
|
let detailList = []
|
||||||
|
|||||||
Reference in New Issue
Block a user