@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.js CHANGED
@@ -1934,7 +1934,7 @@ import crypto from "crypto";
1934
1934
  import fs2 from "fs";
1935
1935
  import path2 from "path";
1936
1936
  async function computeFileMd5Base64(file) {
1937
- if (typeof window === "undefined") {
1937
+ if (typeof window != "undefined") {
1938
1938
  let buffer;
1939
1939
  if (typeof file === "string") {
1940
1940
  buffer = fs2.readFileSync(path2.resolve(file));
@@ -1945,7 +1945,11 @@ async function computeFileMd5Base64(file) {
1945
1945
  } else {
1946
1946
  const arrayBuffer = await file.arrayBuffer();
1947
1947
  const SparkMD5 = (await import("spark-md5")).default;
1948
- return SparkMD5.ArrayBuffer.hash(arrayBuffer, true);
1948
+ const md5Hex = SparkMD5.ArrayBuffer.hash(arrayBuffer, false);
1949
+ const md5Bytes = new Uint8Array(md5Hex.match(/.{2}/g).map((b) => parseInt(b, 16)));
1950
+ let binary = "";
1951
+ md5Bytes.forEach((byte) => binary += String.fromCharCode(byte));
1952
+ return btoa(binary);
1949
1953
  }
1950
1954
  }
1951
1955
  function parseFileNameAndSuffix(url) {
@@ -1971,44 +1975,13 @@ var oss = {
1971
1975
  async uploadFile(params) {
1972
1976
  const { file, folder, acl = "private" } = params;
1973
1977
  const md5Base64 = await computeFileMd5Base64(file);
1974
- const presignedInput = {
1975
- fileMd5Base64: md5Base64,
1976
- fileSuffix: file.name.split(".").pop() || "",
1977
- originalFileName: file.name,
1978
- fileSize: file.size,
1979
- acl
1980
- };
1981
- if (folder) presignedInput.folder = folder;
1982
- const presignedResult = await rateLimit("uploadPresignedUrl", "mutation", async () => {
1983
- const { query: query2, variables } = buildGraphQLUploadPresignedUrl(presignedInput);
1984
- const result = await execute({ query: query2, variables });
1985
- return result;
1986
- });
1987
- console.log("presignedResult====>", presignedResult);
1988
- if (!presignedResult.uploadPresignedUrl) throw new Error("\u83B7\u53D6\u9884\u7B7E\u540D URL \u5931\u8D25");
1989
- const { uploadUrl, uploadHeaders, downloadUrl, resourceId, contentType, originalFileName } = presignedResult.uploadPresignedUrl;
1990
- const headers = {};
1991
- if (uploadHeaders) {
1992
- if (uploadHeaders.contentMD5) headers["Content-MD5"] = uploadHeaders.contentMD5;
1993
- if (uploadHeaders.contentType) headers["Content-Type"] = uploadHeaders.contentType;
1994
- if (uploadHeaders.date) headers["Date"] = uploadHeaders.date;
1995
- }
1996
- const res = await fetch(uploadUrl, {
1997
- method: "PUT",
1998
- body: file,
1999
- headers
2000
- });
2001
- if (!res.ok) {
2002
- throw new Error(`\u4E0A\u4F20\u5931\u8D25: ${res.status} ${res.statusText}`);
2003
- }
1978
+ console.log(md5Base64);
2004
1979
  return {
2005
- id: resourceId,
2006
- // 非空断言,确保 TS 类型通过
2007
- originalFileName: originalFileName ?? file.name,
2008
- contentType: contentType ?? file.type,
2009
- fileSize: file.size,
2010
- url: downloadUrl ?? uploadUrl
2011
- // downloadUrl 可能为 undefined,fallback 使用 uploadUrl
1980
+ id: 1,
1981
+ originalFileName: "tt",
1982
+ contentType: "11",
1983
+ fileSize: 123,
1984
+ url: "HHH"
2012
1985
  };
2013
1986
  },
2014
1987
  /**