@ctil/gql 1.0.16 → 1.0.18
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 +38 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -7
- 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));
|
|
@@ -4744,13 +4744,44 @@ var oss = {
|
|
|
4744
4744
|
async uploadFile(params) {
|
|
4745
4745
|
const { file, folder, acl = "private" } = params;
|
|
4746
4746
|
const md5Base64 = await computeFileMd5Base64(file);
|
|
4747
|
-
|
|
4747
|
+
const presignedInput = {
|
|
4748
|
+
fileMd5Base64: md5Base64,
|
|
4749
|
+
fileSuffix: file.name.split(".").pop() || "",
|
|
4750
|
+
originalFileName: file.name,
|
|
4751
|
+
fileSize: file.size,
|
|
4752
|
+
acl
|
|
4753
|
+
};
|
|
4754
|
+
if (folder) presignedInput.folder = folder;
|
|
4755
|
+
const presignedResult = await rateLimit("uploadPresignedUrl", "mutation", async () => {
|
|
4756
|
+
const { query: query2, variables } = buildGraphQLUploadPresignedUrl(presignedInput);
|
|
4757
|
+
const result = await execute({ query: query2, variables });
|
|
4758
|
+
return result;
|
|
4759
|
+
});
|
|
4760
|
+
console.log("presignedResult====>", presignedResult);
|
|
4761
|
+
if (!presignedResult.uploadPresignedUrl) throw new Error("\u83B7\u53D6\u9884\u7B7E\u540D URL \u5931\u8D25");
|
|
4762
|
+
const { uploadUrl, uploadHeaders, downloadUrl, resourceId, contentType, originalFileName } = presignedResult.uploadPresignedUrl;
|
|
4763
|
+
const headers = {};
|
|
4764
|
+
if (uploadHeaders) {
|
|
4765
|
+
if (uploadHeaders.contentMD5) headers["Content-MD5"] = uploadHeaders.contentMD5;
|
|
4766
|
+
if (uploadHeaders.contentType) headers["Content-Type"] = uploadHeaders.contentType;
|
|
4767
|
+
if (uploadHeaders.date) headers["Date"] = uploadHeaders.date;
|
|
4768
|
+
}
|
|
4769
|
+
const res = await fetch(uploadUrl, {
|
|
4770
|
+
method: "PUT",
|
|
4771
|
+
body: file,
|
|
4772
|
+
headers
|
|
4773
|
+
});
|
|
4774
|
+
if (!res.ok) {
|
|
4775
|
+
throw new Error(`\u4E0A\u4F20\u5931\u8D25: ${res.status} ${res.statusText}`);
|
|
4776
|
+
}
|
|
4748
4777
|
return {
|
|
4749
|
-
id:
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4778
|
+
id: resourceId,
|
|
4779
|
+
// 非空断言,确保 TS 类型通过
|
|
4780
|
+
originalFileName: originalFileName ?? file.name,
|
|
4781
|
+
contentType: contentType ?? file.type,
|
|
4782
|
+
fileSize: file.size,
|
|
4783
|
+
url: downloadUrl ?? uploadUrl
|
|
4784
|
+
// downloadUrl 可能为 undefined,fallback 使用 uploadUrl
|
|
4754
4785
|
};
|
|
4755
4786
|
},
|
|
4756
4787
|
/**
|