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