@ctil/gql 1.0.15 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +12 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4703,7 +4703,7 @@ var import_crypto = __toESM(require("crypto"), 1);
|
|
|
4703
4703
|
var import_fs2 = __toESM(require("fs"), 1);
|
|
4704
4704
|
var import_path2 = __toESM(require("path"), 1);
|
|
4705
4705
|
async function computeFileMd5Base64(file) {
|
|
4706
|
-
if (typeof window
|
|
4706
|
+
if (typeof window != "undefined") {
|
|
4707
4707
|
let buffer;
|
|
4708
4708
|
if (typeof file === "string") {
|
|
4709
4709
|
buffer = import_fs2.default.readFileSync(import_path2.default.resolve(file));
|
|
@@ -4714,7 +4714,11 @@ async function computeFileMd5Base64(file) {
|
|
|
4714
4714
|
} else {
|
|
4715
4715
|
const arrayBuffer = await file.arrayBuffer();
|
|
4716
4716
|
const SparkMD5 = (await import("spark-md5")).default;
|
|
4717
|
-
|
|
4717
|
+
const md5Hex = SparkMD5.ArrayBuffer.hash(arrayBuffer, false);
|
|
4718
|
+
const md5Bytes = new Uint8Array(md5Hex.match(/.{2}/g).map((b) => parseInt(b, 16)));
|
|
4719
|
+
let binary = "";
|
|
4720
|
+
md5Bytes.forEach((byte) => binary += String.fromCharCode(byte));
|
|
4721
|
+
return btoa(binary);
|
|
4718
4722
|
}
|
|
4719
4723
|
}
|
|
4720
4724
|
function parseFileNameAndSuffix(url) {
|
|
@@ -4740,44 +4744,13 @@ var oss = {
|
|
|
4740
4744
|
async uploadFile(params) {
|
|
4741
4745
|
const { file, folder, acl = "private" } = params;
|
|
4742
4746
|
const md5Base64 = await computeFileMd5Base64(file);
|
|
4743
|
-
|
|
4744
|
-
fileMd5Base64: md5Base64,
|
|
4745
|
-
fileSuffix: file.name.split(".").pop() || "",
|
|
4746
|
-
originalFileName: file.name,
|
|
4747
|
-
fileSize: file.size,
|
|
4748
|
-
acl
|
|
4749
|
-
};
|
|
4750
|
-
if (folder) presignedInput.folder = folder;
|
|
4751
|
-
const presignedResult = await rateLimit("uploadPresignedUrl", "mutation", async () => {
|
|
4752
|
-
const { query: query2, variables } = buildGraphQLUploadPresignedUrl(presignedInput);
|
|
4753
|
-
const result = await execute({ query: query2, variables });
|
|
4754
|
-
return result;
|
|
4755
|
-
});
|
|
4756
|
-
console.log("presignedResult====>", presignedResult);
|
|
4757
|
-
if (!presignedResult.uploadPresignedUrl) throw new Error("\u83B7\u53D6\u9884\u7B7E\u540D URL \u5931\u8D25");
|
|
4758
|
-
const { uploadUrl, uploadHeaders, downloadUrl, resourceId, contentType, originalFileName } = presignedResult.uploadPresignedUrl;
|
|
4759
|
-
const headers = {};
|
|
4760
|
-
if (uploadHeaders) {
|
|
4761
|
-
if (uploadHeaders.contentMD5) headers["Content-MD5"] = uploadHeaders.contentMD5;
|
|
4762
|
-
if (uploadHeaders.contentType) headers["Content-Type"] = uploadHeaders.contentType;
|
|
4763
|
-
if (uploadHeaders.date) headers["Date"] = uploadHeaders.date;
|
|
4764
|
-
}
|
|
4765
|
-
const res = await fetch(uploadUrl, {
|
|
4766
|
-
method: "PUT",
|
|
4767
|
-
body: file,
|
|
4768
|
-
headers
|
|
4769
|
-
});
|
|
4770
|
-
if (!res.ok) {
|
|
4771
|
-
throw new Error(`\u4E0A\u4F20\u5931\u8D25: ${res.status} ${res.statusText}`);
|
|
4772
|
-
}
|
|
4747
|
+
console.log(md5Base64);
|
|
4773
4748
|
return {
|
|
4774
|
-
id:
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
url: downloadUrl ?? uploadUrl
|
|
4780
|
-
// downloadUrl 可能为 undefined,fallback 使用 uploadUrl
|
|
4749
|
+
id: 1,
|
|
4750
|
+
originalFileName: "tt",
|
|
4751
|
+
contentType: "11",
|
|
4752
|
+
fileSize: 123,
|
|
4753
|
+
url: "HHH"
|
|
4781
4754
|
};
|
|
4782
4755
|
},
|
|
4783
4756
|
/**
|