@ctil/gql 1.0.14 → 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 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -40
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4410,7 +4410,6 @@ var CCRequest = class {
|
|
|
4410
4410
|
return info;
|
|
4411
4411
|
}
|
|
4412
4412
|
getLoginInfo() {
|
|
4413
|
-
if (this.config.loginInfo) return this.config.loginInfo;
|
|
4414
4413
|
return this.loadLoginInfo();
|
|
4415
4414
|
}
|
|
4416
4415
|
removeLoginInfo() {
|
|
@@ -4704,7 +4703,7 @@ var import_crypto = __toESM(require("crypto"), 1);
|
|
|
4704
4703
|
var import_fs2 = __toESM(require("fs"), 1);
|
|
4705
4704
|
var import_path2 = __toESM(require("path"), 1);
|
|
4706
4705
|
async function computeFileMd5Base64(file) {
|
|
4707
|
-
if (typeof window
|
|
4706
|
+
if (typeof window != "undefined") {
|
|
4708
4707
|
let buffer;
|
|
4709
4708
|
if (typeof file === "string") {
|
|
4710
4709
|
buffer = import_fs2.default.readFileSync(import_path2.default.resolve(file));
|
|
@@ -4715,7 +4714,11 @@ async function computeFileMd5Base64(file) {
|
|
|
4715
4714
|
} else {
|
|
4716
4715
|
const arrayBuffer = await file.arrayBuffer();
|
|
4717
4716
|
const SparkMD5 = (await import("spark-md5")).default;
|
|
4718
|
-
|
|
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);
|
|
4719
4722
|
}
|
|
4720
4723
|
}
|
|
4721
4724
|
function parseFileNameAndSuffix(url) {
|
|
@@ -4741,44 +4744,13 @@ var oss = {
|
|
|
4741
4744
|
async uploadFile(params) {
|
|
4742
4745
|
const { file, folder, acl = "private" } = params;
|
|
4743
4746
|
const md5Base64 = await computeFileMd5Base64(file);
|
|
4744
|
-
|
|
4745
|
-
fileMd5Base64: md5Base64,
|
|
4746
|
-
fileSuffix: file.name.split(".").pop() || "",
|
|
4747
|
-
originalFileName: file.name,
|
|
4748
|
-
fileSize: file.size,
|
|
4749
|
-
acl
|
|
4750
|
-
};
|
|
4751
|
-
if (folder) presignedInput.folder = folder;
|
|
4752
|
-
const presignedResult = await rateLimit("uploadPresignedUrl", "mutation", async () => {
|
|
4753
|
-
const { query: query2, variables } = buildGraphQLUploadPresignedUrl(presignedInput);
|
|
4754
|
-
const result = await execute({ query: query2, variables });
|
|
4755
|
-
return result;
|
|
4756
|
-
});
|
|
4757
|
-
console.log("presignedResult====>", presignedResult);
|
|
4758
|
-
if (!presignedResult.uploadPresignedUrl) throw new Error("\u83B7\u53D6\u9884\u7B7E\u540D URL \u5931\u8D25");
|
|
4759
|
-
const { uploadUrl, uploadHeaders, downloadUrl, resourceId, contentType, originalFileName } = presignedResult.uploadPresignedUrl;
|
|
4760
|
-
const headers = {};
|
|
4761
|
-
if (uploadHeaders) {
|
|
4762
|
-
if (uploadHeaders.contentMD5) headers["Content-MD5"] = uploadHeaders.contentMD5;
|
|
4763
|
-
if (uploadHeaders.contentType) headers["Content-Type"] = uploadHeaders.contentType;
|
|
4764
|
-
if (uploadHeaders.date) headers["Date"] = uploadHeaders.date;
|
|
4765
|
-
}
|
|
4766
|
-
const res = await fetch(uploadUrl, {
|
|
4767
|
-
method: "PUT",
|
|
4768
|
-
body: file,
|
|
4769
|
-
headers
|
|
4770
|
-
});
|
|
4771
|
-
if (!res.ok) {
|
|
4772
|
-
throw new Error(`\u4E0A\u4F20\u5931\u8D25: ${res.status} ${res.statusText}`);
|
|
4773
|
-
}
|
|
4747
|
+
console.log(md5Base64);
|
|
4774
4748
|
return {
|
|
4775
|
-
id:
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
url: downloadUrl ?? uploadUrl
|
|
4781
|
-
// downloadUrl 可能为 undefined,fallback 使用 uploadUrl
|
|
4749
|
+
id: 1,
|
|
4750
|
+
originalFileName: "tt",
|
|
4751
|
+
contentType: "11",
|
|
4752
|
+
fileSize: 123,
|
|
4753
|
+
url: "HHH"
|
|
4782
4754
|
};
|
|
4783
4755
|
},
|
|
4784
4756
|
/**
|