@wzyjs/utils 0.3.3 → 0.3.6

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.
Files changed (39) hide show
  1. package/dist/common/base/index.d.ts +6 -0
  2. package/dist/common/index.d.ts +2 -10
  3. package/dist/node.cjs.js +281 -2764
  4. package/dist/node.d.ts +11 -2
  5. package/dist/node.esm.js +287 -2768
  6. package/dist/{browser.cjs.js → web.cjs.js} +18049 -20116
  7. package/dist/web.d.ts +15 -0
  8. package/dist/{browser.esm.js → web.esm.js} +17962 -20027
  9. package/package.json +14 -14
  10. package/dist/ai/index.d.ts +0 -1
  11. package/dist/ai/midjourney/index.d.ts +0 -1
  12. package/dist/ai/midjourney/utils.d.ts +0 -12
  13. package/dist/browser/index.d.ts +0 -10
  14. package/dist/browser.d.ts +0 -2
  15. package/dist/node/index.d.ts +0 -6
  16. /package/dist/{ai → common/ai}/302/axios.d.ts +0 -0
  17. /package/dist/{ai → common/ai}/302/chat/index.d.ts +0 -0
  18. /package/dist/{ai → common/ai}/302/image/index.d.ts +0 -0
  19. /package/dist/{ai → common/ai}/302/image/midjourney.d.ts +0 -0
  20. /package/dist/{ai → common/ai}/302/index.d.ts +0 -0
  21. /package/dist/{ai → common/ai}/keling/axios.d.ts +0 -0
  22. /package/dist/{ai → common/ai}/keling/index.d.ts +0 -0
  23. /package/dist/{ai → common/ai}/keling/utils.d.ts +0 -0
  24. /package/dist/common/{array.d.ts → base/array.d.ts} +0 -0
  25. /package/dist/common/{number.d.ts → base/number.d.ts} +0 -0
  26. /package/dist/common/{object.d.ts → base/object.d.ts} +0 -0
  27. /package/dist/common/{other.d.ts → base/other.d.ts} +0 -0
  28. /package/dist/common/{promise.d.ts → base/promise.d.ts} +0 -0
  29. /package/dist/common/{string.d.ts → base/string.d.ts} +0 -0
  30. /package/dist/node/{cron/index.d.ts → cron.d.ts} +0 -0
  31. /package/dist/node/{file/index.d.ts → file.d.ts} +0 -0
  32. /package/dist/node/{mail/index.d.ts → mail.d.ts} +0 -0
  33. /package/dist/node/{oss/index.d.ts → oss.d.ts} +0 -0
  34. /package/dist/{common → web}/antd.d.ts +0 -0
  35. /package/dist/{browser/other.d.ts → web/clipboard.d.ts} +0 -0
  36. /package/dist/{browser → web}/download.d.ts +0 -0
  37. /package/dist/{browser → web}/element.d.ts +0 -0
  38. /package/dist/{browser → web}/location.d.ts +0 -0
  39. /package/dist/{browser → web}/style.d.ts +0 -0
package/dist/node.cjs.js CHANGED
@@ -1204,7 +1204,7 @@ var require_lodash = __commonJS((exports2, module2) => {
1204
1204
  if (typeof func != "function") {
1205
1205
  throw new TypeError2(FUNC_ERROR_TEXT);
1206
1206
  }
1207
- return setTimeout2(function() {
1207
+ return setTimeout(function() {
1208
1208
  func.apply(undefined2, args);
1209
1209
  }, wait);
1210
1210
  }
@@ -3013,7 +3013,7 @@ var require_lodash = __commonJS((exports2, module2) => {
3013
3013
  return object[key];
3014
3014
  }
3015
3015
  var setData = shortOut(baseSetData);
3016
- var setTimeout2 = ctxSetTimeout || function(func, wait) {
3016
+ var setTimeout = ctxSetTimeout || function(func, wait) {
3017
3017
  return root.setTimeout(func, wait);
3018
3018
  };
3019
3019
  var setToString = shortOut(baseSetToString);
@@ -3803,7 +3803,7 @@ var require_lodash = __commonJS((exports2, module2) => {
3803
3803
  }
3804
3804
  function leadingEdge(time) {
3805
3805
  lastInvokeTime = time;
3806
- timerId = setTimeout2(timerExpired, wait);
3806
+ timerId = setTimeout(timerExpired, wait);
3807
3807
  return leading ? invokeFunc(time) : result2;
3808
3808
  }
3809
3809
  function remainingWait(time) {
@@ -3819,7 +3819,7 @@ var require_lodash = __commonJS((exports2, module2) => {
3819
3819
  if (shouldInvoke(time)) {
3820
3820
  return trailingEdge(time);
3821
3821
  }
3822
- timerId = setTimeout2(timerExpired, remainingWait(time));
3822
+ timerId = setTimeout(timerExpired, remainingWait(time));
3823
3823
  }
3824
3824
  function trailingEdge(time) {
3825
3825
  timerId = undefined2;
@@ -3850,12 +3850,12 @@ var require_lodash = __commonJS((exports2, module2) => {
3850
3850
  }
3851
3851
  if (maxing) {
3852
3852
  clearTimeout(timerId);
3853
- timerId = setTimeout2(timerExpired, wait);
3853
+ timerId = setTimeout(timerExpired, wait);
3854
3854
  return invokeFunc(lastCallTime);
3855
3855
  }
3856
3856
  }
3857
3857
  if (timerId === undefined2) {
3858
- timerId = setTimeout2(timerExpired, wait);
3858
+ timerId = setTimeout(timerExpired, wait);
3859
3859
  }
3860
3860
  return result2;
3861
3861
  }
@@ -4062,7 +4062,7 @@ var require_lodash = __commonJS((exports2, module2) => {
4062
4062
  var tag = baseGetTag(value);
4063
4063
  return tag == errorTag || tag == domExcTag || typeof value.message == "string" && typeof value.name == "string" && !isPlainObject(value);
4064
4064
  }
4065
- function isFinite2(value) {
4065
+ function isFinite(value) {
4066
4066
  return typeof value == "number" && nativeIsFinite(value);
4067
4067
  }
4068
4068
  function isFunction(value) {
@@ -4093,7 +4093,7 @@ var require_lodash = __commonJS((exports2, module2) => {
4093
4093
  customizer = typeof customizer == "function" ? customizer : undefined2;
4094
4094
  return baseIsMatch(object, source, getMatchData(source), customizer);
4095
4095
  }
4096
- function isNaN2(value) {
4096
+ function isNaN(value) {
4097
4097
  return isNumber(value) && value != +value;
4098
4098
  }
4099
4099
  function isNative(value) {
@@ -4752,7 +4752,7 @@ __p += '`;
4752
4752
  }
4753
4753
  return result2 + omission;
4754
4754
  }
4755
- function unescape2(string) {
4755
+ function unescape(string) {
4756
4756
  string = toString(string);
4757
4757
  return string && reHasEscapedHtml.test(string) ? string.replace(reEscapedHtml, unescapeHtmlChar) : string;
4758
4758
  }
@@ -5176,14 +5176,14 @@ __p += '`;
5176
5176
  lodash.isEqual = isEqual;
5177
5177
  lodash.isEqualWith = isEqualWith;
5178
5178
  lodash.isError = isError;
5179
- lodash.isFinite = isFinite2;
5179
+ lodash.isFinite = isFinite;
5180
5180
  lodash.isFunction = isFunction;
5181
5181
  lodash.isInteger = isInteger;
5182
5182
  lodash.isLength = isLength;
5183
5183
  lodash.isMap = isMap;
5184
5184
  lodash.isMatch = isMatch;
5185
5185
  lodash.isMatchWith = isMatchWith;
5186
- lodash.isNaN = isNaN2;
5186
+ lodash.isNaN = isNaN;
5187
5187
  lodash.isNative = isNative;
5188
5188
  lodash.isNil = isNil;
5189
5189
  lodash.isNull = isNull;
@@ -5265,7 +5265,7 @@ __p += '`;
5265
5265
  lodash.trimEnd = trimEnd;
5266
5266
  lodash.trimStart = trimStart;
5267
5267
  lodash.truncate = truncate;
5268
- lodash.unescape = unescape2;
5268
+ lodash.unescape = unescape;
5269
5269
  lodash.uniqueId = uniqueId;
5270
5270
  lodash.upperCase = upperCase;
5271
5271
  lodash.upperFirst = upperFirst;
@@ -5460,7 +5460,6 @@ __p += '`;
5460
5460
  var exports_node = {};
5461
5461
  __export(exports_node, {
5462
5462
  z: () => exports_external,
5463
- watch: () => watch,
5464
5463
  void: () => voidType,
5465
5464
  util: () => util,
5466
5465
  uploadFile: () => uploadFile,
@@ -5469,35 +5468,26 @@ __export(exports_node, {
5469
5468
  undefined: () => undefinedType,
5470
5469
  tuple: () => tupleType,
5471
5470
  transformer: () => effectsType,
5472
- toString: () => toString,
5473
5471
  symbol: () => symbolType,
5474
5472
  string: () => stringType,
5475
5473
  strictObject: () => strictObjectType,
5476
- shuffleArray: () => shuffleArray,
5477
5474
  setErrorMap: () => setErrorMap,
5475
+ setCookie: () => setCookie,
5478
5476
  set: () => setType,
5479
5477
  sendMail: () => sendMail,
5480
5478
  schedule: () => schedule,
5481
5479
  replaceContentInFile: () => replaceContentInFile,
5482
- replaceByVariables: () => replaceByVariables,
5483
- replaceByRules: () => replaceByRules,
5484
- replaceAll: () => replaceAll,
5485
- removeSimilarDuplicates: () => removeSimilarDuplicates,
5486
5480
  record: () => recordType,
5487
5481
  quotelessJson: () => quotelessJson,
5488
5482
  promise: () => promiseType,
5489
- printConsoleLog: () => printConsoleLog,
5490
5483
  preprocess: () => preprocessType,
5491
5484
  pipeline: () => pipelineType,
5492
- performDecimalOperation: () => performDecimalOperation,
5493
5485
  ostring: () => ostring,
5494
- optionsToEnum: () => optionsToEnum,
5495
5486
  optional: () => optionalType,
5496
5487
  onumber: () => onumber,
5497
5488
  oboolean: () => oboolean,
5498
5489
  objectUtil: () => objectUtil,
5499
5490
  object: () => objectType,
5500
- numberWithCommas: () => numberWithCommas,
5501
5491
  number: () => numberType,
5502
5492
  nullable: () => nullableType,
5503
5493
  null: () => nullType,
@@ -5507,15 +5497,10 @@ __export(exports_node, {
5507
5497
  map: () => mapType,
5508
5498
  makeIssue: () => makeIssue,
5509
5499
  literal: () => literalType,
5510
- limitDecimals: () => limitDecimals,
5511
- levenshteinDistance: () => levenshteinDistance,
5512
5500
  lazy: () => lazyType,
5513
5501
  late: () => late,
5514
- jsonParse: () => jsonParse,
5515
- json5: () => import_json5.default,
5516
- isValidNumber: () => isValidNumber,
5502
+ json5: () => import_json52.default,
5517
5503
  isValid: () => isValid,
5518
- isJson: () => isJson,
5519
5504
  isDirty: () => isDirty,
5520
5505
  isAsync: () => isAsync,
5521
5506
  isAborted: () => isAborted,
@@ -5524,31 +5509,15 @@ __export(exports_node, {
5524
5509
  instanceof: () => instanceOfType,
5525
5510
  initChinaDayjs: () => initChinaDayjs,
5526
5511
  imageToBase64: () => imageToBase64,
5527
- getType: () => getType,
5528
- getTotal: () => getTotal,
5529
- getStrLength: () => getStrLength,
5530
- getSliceStr: () => getSliceStr,
5531
- getRandomString: () => getRandomString,
5532
- getRandomNum: () => getRandomNum,
5533
- getRandomColor: () => getRandomColor,
5534
- getProxyUrl: () => getProxyUrl,
5512
+ getVideoStatus: () => getVideoStatus,
5535
5513
  getParsedType: () => getParsedType,
5536
- getLength: () => getLength,
5537
- getFileSize: () => getFileSize,
5538
5514
  getErrorMap: () => getErrorMap,
5539
- getCookie: () => getCookie,
5540
- getChineseByStr: () => getChineseByStr,
5541
- getChinese: () => getChinese,
5542
- generateUniqueFileName: () => generateUniqueFileName,
5543
- generateAlphabetArray: () => generateAlphabetArray,
5515
+ generateVideo: () => generateVideo,
5544
5516
  function: () => functionType,
5545
- findItem: () => findItem,
5546
- filterParams: () => filterParams,
5547
5517
  enum: () => enumType,
5548
5518
  effect: () => effectsType,
5549
5519
  downloadFile: () => downloadFile,
5550
5520
  discriminatedUnion: () => discriminatedUnionType,
5551
- delay: () => delay,
5552
5521
  defaultErrorMap: () => en_default,
5553
5522
  dayjs: () => dayjs_default,
5554
5523
  datetimeRegex: () => datetimeRegex,
@@ -5558,14 +5527,12 @@ __export(exports_node, {
5558
5527
  coerce: () => coerce,
5559
5528
  chinaDayjs: () => chinaDayjs,
5560
5529
  cheerio: () => cheerio,
5561
- calcJsText: () => calcJsText,
5530
+ chat: () => chat,
5562
5531
  boolean: () => booleanType,
5563
5532
  bigint: () => bigIntType,
5564
- axios: () => import_axios2.default,
5533
+ axios: () => import_axios9.default,
5565
5534
  array: () => arrayType,
5566
5535
  any: () => anyType,
5567
- amount: () => amount,
5568
- ai302: () => exports_302,
5569
5536
  addIssueToContext: () => addIssueToContext,
5570
5537
  _: () => import_lodash.default,
5571
5538
  ZodVoid: () => ZodVoid,
@@ -5626,11 +5593,11 @@ __export(exports_node, {
5626
5593
  BRAND: () => BRAND
5627
5594
  });
5628
5595
  module.exports = __toCommonJS(exports_node);
5629
-
5630
- // src/common/index.ts
5596
+ var import_nedb = __toESM(require("nedb"));
5597
+ var cheerio = __toESM(require("cheerio"));
5631
5598
  var import_lodash = __toESM(require_lodash());
5632
- var import_axios2 = __toESM(require("axios"));
5633
- var import_json5 = __toESM(require("json5"));
5599
+ var import_axios9 = __toESM(require("axios"));
5600
+ var import_json52 = __toESM(require("json5"));
5634
5601
  var import_consola = __toESM(require("consola"));
5635
5602
 
5636
5603
  // ../../node_modules/zod/v3/external.js
@@ -9606,2682 +9573,280 @@ var coerce = {
9606
9573
  date: (arg) => ZodDate.create({ ...arg, coerce: true })
9607
9574
  };
9608
9575
  var NEVER = INVALID;
9609
- // src/common/string.ts
9610
- var getChineseByStr = (str) => {
9611
- if (!str) {
9612
- return "";
9613
- }
9614
- const match = str.match(/[\u4e00-\u9fa5]/g);
9615
- if (!match) {
9616
- return "";
9617
- }
9618
- return match.join("");
9619
- };
9620
- var getStrLength = (value) => {
9621
- if (!value) {
9622
- return 0;
9623
- }
9624
- const chineseLength = getChineseByStr(value).length;
9625
- return value.length - chineseLength + chineseLength * 2;
9626
- };
9627
- var replaceAll = (str, searchValue, replaceValue) => {
9628
- if (!str || !searchValue || !replaceValue) {
9629
- return str || "";
9630
- }
9631
- str = str.replace(searchValue, replaceValue);
9632
- if (!str.includes(searchValue)) {
9633
- return str;
9576
+ // src/common/ai/302/axios.ts
9577
+ var import_axios = __toESM(require("axios"));
9578
+ var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
9579
+ var axios = import_axios.default.create({
9580
+ baseURL: "https://api.302.ai",
9581
+ headers: {
9582
+ "mj-api-secret": key,
9583
+ Authorization: `Bearer ${key}`
9634
9584
  }
9635
- return replaceAll(str, searchValue, replaceValue);
9636
- };
9637
- var replaceByRules = (str, rules) => {
9638
- rules.forEach(([searchValue, replaceValue]) => {
9639
- str = str.replaceAll(searchValue, replaceValue);
9640
- });
9641
- return str;
9642
- };
9643
- var replaceByVariables = (prompt, variables) => {
9644
- if (!variables || Object.keys(variables).length === 0) {
9645
- return prompt;
9585
+ });
9586
+
9587
+ // src/common/ai/302/chat/index.ts
9588
+ var import_json5 = __toESM(require("json5"));
9589
+ var chat = async (message, model = "gpt-4.1", isParse = true) => {
9590
+ try {
9591
+ let { data } = await axios({
9592
+ url: "/v1/chat/completions",
9593
+ method: "post",
9594
+ data: {
9595
+ model,
9596
+ message
9597
+ }
9598
+ });
9599
+ console.log(666, typeof data, data);
9600
+ const output = typeof data === "string" ? import_json5.default.parse(data)?.output : data?.output;
9601
+ if (isParse) {
9602
+ const match = /```(json)?(.*)```/s.exec(output);
9603
+ if (!match) {
9604
+ return import_json5.default.parse(output);
9605
+ } else {
9606
+ return import_json5.default.parse(match[2]);
9607
+ }
9608
+ }
9609
+ return output;
9610
+ } catch (error) {
9611
+ throw new Error(error?.response?.statusText || error?.message || "未知原因");
9646
9612
  }
9647
- const regex = /\{\{\s*(\w+)\s*\}\}/g;
9648
- return prompt.replace(regex, (match, p1) => {
9649
- return variables[p1] ?? match;
9650
- });
9651
9613
  };
9652
- var getType = (value) => {
9653
- return Object.prototype.toString.call(value).slice(8, -1);
9654
- };
9655
- var amount = (str) => {
9656
- const reg = /(?=(?!\b)(\d{3})+$)/g;
9657
- return str.replace(reg, ",");
9658
- };
9659
- var jsonParse = (value) => {
9660
- if (typeof value === "object") {
9661
- return value;
9614
+ // src/common/ai/keling/utils.ts
9615
+ var url = __toESM(require("url"));
9616
+ var path = __toESM(require("path"));
9617
+
9618
+ // src/common/ai/keling/axios.ts
9619
+ var import_axios3 = __toESM(require("axios"));
9620
+ var axios2 = import_axios3.default.create({
9621
+ headers: {
9622
+ "Content-Type": "application/json",
9623
+ Cookie: "weblogger_did=web_52354269549862D; did=web_d22eeae73f6e4c74a76a4cc98e3a1188a5b0; anonymous-message-release-notice-1=true; anonymous-message-release-notice-2=true; dev-center-view-welcome-dialog-key=true; userId=2904283585; welcome-future-partner-key=true; old-user-time=1731936878621; kuaishou.ai.portal_st=ChVrdWFpc2hvdS5haS5wb3J0YWwuc3QSoAFuUNTARKNKXARahOJhWZ4iVBl2mIANSUfk2nCSr85bxCg2lrpE3PHj2Kn_kjPW0_KV8DfZS6UnNam4i6gaYeBmxRwOVAldYysCz7YtlsosEZRuiTe2iY7Ziq5SZeAP7jhTg8lxk7gvC-bEELmAc8HSrqN5HLWeU4GUFcEq-ChV7qsodJ8m42oBuvkFgX1qytVTIROpSS4cMmEiBhB3h99EGhLGi0v_iyPMOr2JVXM8LPzBvxQiIJrnuzAheyLtkeb55iZOUgZoAzXjYj0U1e4mLSonbXBGKAUwAQ; kuaishou.ai.portal_ph=2669d9adaa5c0629ac1053ab87e6c123880a"
9662
9624
  }
9625
+ });
9626
+
9627
+ // src/common/ai/keling/utils.ts
9628
+ var getToken = async (filename) => {
9663
9629
  try {
9664
- return JSON.parse(value);
9665
- } catch (err) {
9666
- return {};
9630
+ const response = await axios2.get("https://klingai.kuaishou.com/api/upload/issue/token", {
9631
+ params: { filename }
9632
+ });
9633
+ return response.data.data.token;
9634
+ } catch (error) {
9635
+ console.error("获取 token 失败:", error);
9636
+ throw error;
9667
9637
  }
9668
9638
  };
9669
- var isJson = (str) => {
9639
+ var uploadFragment = async (uploadToken, imageBuffer) => {
9670
9640
  try {
9671
- if (getType(JSON.parse(str)) === "Object") {
9672
- return true;
9673
- }
9674
- } catch (e) {}
9675
- return false;
9676
- };
9677
- var toString = (value) => {
9678
- return Object.prototype.toString.call(value).slice(8, -1) === "object" ? JSON.stringify(value) : String(value);
9679
- };
9680
- var getRandomColor = () => {
9681
- const color = Math.floor(Math.random() * 16777215).toString(16);
9682
- if (color.length === 6) {
9683
- return color;
9684
- } else {
9685
- return getRandomColor();
9686
- }
9687
- };
9688
- var getRandomString = (length = 4) => {
9689
- return Math.random().toString(36).substr(2, length);
9690
- };
9691
- var getChinese = (str) => {
9692
- if (str == null || str === "") {
9693
- return "";
9694
- }
9695
- const res = str.match(/[\u4e00-\u9fa5]/g);
9696
- if (!res) {
9697
- return "";
9641
+ const response = await axios2.post("https://upload.kuaishouzt.com/api/upload/fragment", imageBuffer, {
9642
+ params: {
9643
+ upload_token: uploadToken,
9644
+ fragment_id: 0
9645
+ },
9646
+ headers: {
9647
+ "Content-Type": "application/octet-stream"
9648
+ }
9649
+ });
9650
+ return response.data;
9651
+ } catch (error) {
9652
+ console.error("上传片段失败:", error);
9653
+ throw error;
9698
9654
  }
9699
- return res.join("");
9700
- };
9701
- var getSliceStr = (str, before, after) => {
9702
- return str.slice(str.indexOf(before) + before.length, str.lastIndexOf(after));
9703
- };
9704
- var getProxyUrl = (url) => {
9705
- const beforeUrl = "https://1141871752167714.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/a.LATEST/proxy/?url=";
9706
- return beforeUrl + url;
9707
- };
9708
- var getLength = (value) => {
9709
- const chineseLength = getChinese(value).length;
9710
- return value.length - chineseLength + chineseLength * 2;
9711
- };
9712
- var getCookie = (name) => {
9713
- const reg = new RegExp(`(^| )${name}=([^;]*)(;|$)`);
9714
- const arr = document.cookie.match(reg);
9715
- return arr ? unescape(arr[2]) : null;
9716
- };
9717
- var generateAlphabetArray = (n) => {
9718
- return Array.from({ length: n }, (_, i) => String.fromCharCode(97 + i));
9719
9655
  };
9720
- var levenshteinDistance = (a, b) => {
9721
- const matrix = [];
9722
- for (let i = 0;i <= b.length; i++) {
9723
- matrix[i] = [i];
9724
- }
9725
- for (let j = 0;j <= a.length; j++) {
9726
- matrix[0][j] = j;
9727
- }
9728
- for (let i = 1;i <= b.length; i++) {
9729
- for (let j = 1;j <= a.length; j++) {
9730
- if (b[i - 1] === a[j - 1]) {
9731
- matrix[i][j] = matrix[i - 1][j - 1];
9732
- } else {
9733
- matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j] + 1);
9656
+ var completeUpload = async (uploadToken) => {
9657
+ try {
9658
+ const response = await axios2.post("https://upload.kuaishouzt.com/api/upload/complete", null, {
9659
+ params: {
9660
+ upload_token: uploadToken,
9661
+ fragment_count: 1
9734
9662
  }
9735
- }
9663
+ });
9664
+ return response.data;
9665
+ } catch (error) {
9666
+ console.error("完成上传失败:", error);
9667
+ throw error;
9736
9668
  }
9737
- return matrix[b.length][a.length];
9738
9669
  };
9739
- var generateUniqueFileName = (name) => {
9740
- const match = name.match(/^(.*?)(\.[^.]*$|$)/);
9741
- if (match) {
9742
- const namePart = match[1];
9743
- const extensionPart = match[2];
9744
- if (extensionPart) {
9745
- return `${namePart}_${Date.now()}${extensionPart}`;
9670
+ var verifyUpload = async (token) => {
9671
+ try {
9672
+ const response = await axios2.get("https://klingai.kuaishou.com/api/upload/verify/token", {
9673
+ params: { token }
9674
+ });
9675
+ if (response.data?.result === 1 && response.data?.data?.status === 3) {
9676
+ return response.data.data?.url;
9746
9677
  } else {
9747
- return `${namePart}_${Date.now()}.dat`;
9678
+ throw new Error(`上传验证失败: ${response.data.message}`);
9748
9679
  }
9680
+ } catch (error) {
9681
+ console.error("获取上传结果失败:", error);
9682
+ throw error;
9749
9683
  }
9750
- throw new Error("Invalid filename format.");
9751
9684
  };
9752
- // src/common/object.ts
9753
- var findItem = (list, attr, value) => {
9754
- return list.find((item) => value === undefined ? item[attr] : item[attr] === value);
9685
+ var downloadImage = async (imageUrl) => {
9686
+ try {
9687
+ const response = await axios2.get(imageUrl, {
9688
+ responseType: "arraybuffer"
9689
+ });
9690
+ return Buffer.from(response.data, "binary");
9691
+ } catch (error) {
9692
+ console.error("下载图片失败:", error);
9693
+ throw error;
9694
+ }
9755
9695
  };
9756
- var filterParams = (params, deep = false) => {
9757
- const clean = (value) => {
9758
- if (value === undefined || value === null) {
9696
+ var uploadImage = async (imageUrl) => {
9697
+ try {
9698
+ const parsedUrl = url.parse(imageUrl);
9699
+ if (!parsedUrl.pathname) {
9759
9700
  return;
9760
9701
  }
9761
- if (!deep) {
9762
- return value;
9763
- }
9764
- if (Array.isArray(value)) {
9765
- return value.map((v) => clean(v)).filter((v) => v !== undefined);
9766
- }
9767
- if (typeof value === "object") {
9768
- return Object.entries(value).reduce((acc, [k, v]) => {
9769
- const cleaned = clean(v);
9770
- if (cleaned !== undefined)
9771
- acc[k] = cleaned;
9772
- return acc;
9773
- }, {});
9774
- }
9775
- return value;
9776
- };
9777
- return clean(params);
9778
- };
9779
- var watch = {
9780
- observe(obj, key, watchFun) {
9781
- const val = obj[key];
9782
- Object.defineProperty(obj, key, {
9783
- configurable: true,
9784
- enumerable: true,
9785
- set(value) {
9786
- obj[key] = value;
9787
- watchFun(value, val);
9788
- },
9789
- get() {
9790
- return val;
9791
- }
9792
- });
9793
- },
9794
- setWatcher(data = {}, watch2 = {}) {
9795
- Object.keys(watch2).forEach((v) => {
9796
- this.observe(data, v, watch2[v]);
9797
- });
9702
+ const filename = path.basename(parsedUrl.pathname);
9703
+ const imageBuffer = await downloadImage(imageUrl);
9704
+ const token = await getToken(filename);
9705
+ await uploadFragment(token, imageBuffer);
9706
+ await completeUpload(token);
9707
+ return await verifyUpload(token);
9708
+ } catch (error) {
9709
+ console.error("上传图片失败:", error);
9710
+ throw error;
9798
9711
  }
9799
9712
  };
9800
- // ../../node_modules/decimal.js/decimal.mjs
9801
- /*!
9802
- * decimal.js v10.6.0
9803
- * An arbitrary-precision Decimal type for JavaScript.
9804
- * https://github.com/MikeMcl/decimal.js
9805
- * Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
9806
- * MIT Licence
9807
- */
9808
- var EXP_LIMIT = 9000000000000000;
9809
- var MAX_DIGITS = 1e9;
9810
- var NUMERALS = "0123456789abcdef";
9811
- var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
9812
- var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
9813
- var DEFAULTS = {
9814
- precision: 20,
9815
- rounding: 4,
9816
- modulo: 1,
9817
- toExpNeg: -7,
9818
- toExpPos: 21,
9819
- minE: -EXP_LIMIT,
9820
- maxE: EXP_LIMIT,
9821
- crypto: false
9822
- };
9823
- var inexact;
9824
- var quadrant;
9825
- var external2 = true;
9826
- var decimalError = "[DecimalError] ";
9827
- var invalidArgument = decimalError + "Invalid argument: ";
9828
- var precisionLimitExceeded = decimalError + "Precision limit exceeded";
9829
- var cryptoUnavailable = decimalError + "crypto unavailable";
9830
- var tag = "[object Decimal]";
9831
- var mathfloor = Math.floor;
9832
- var mathpow = Math.pow;
9833
- var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
9834
- var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
9835
- var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
9836
- var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
9837
- var BASE = 1e7;
9838
- var LOG_BASE = 7;
9839
- var MAX_SAFE_INTEGER = 9007199254740991;
9840
- var LN10_PRECISION = LN10.length - 1;
9841
- var PI_PRECISION = PI.length - 1;
9842
- var P = { toStringTag: tag };
9843
- P.absoluteValue = P.abs = function() {
9844
- var x = new this.constructor(this);
9845
- if (x.s < 0)
9846
- x.s = 1;
9847
- return finalise(x);
9848
- };
9849
- P.ceil = function() {
9850
- return finalise(new this.constructor(this), this.e + 1, 2);
9851
- };
9852
- P.clampedTo = P.clamp = function(min, max) {
9853
- var k, x = this, Ctor = x.constructor;
9854
- min = new Ctor(min);
9855
- max = new Ctor(max);
9856
- if (!min.s || !max.s)
9857
- return new Ctor(NaN);
9858
- if (min.gt(max))
9859
- throw Error(invalidArgument + max);
9860
- k = x.cmp(min);
9861
- return k < 0 ? min : x.cmp(max) > 0 ? max : new Ctor(x);
9862
- };
9863
- P.comparedTo = P.cmp = function(y) {
9864
- var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
9865
- if (!xd || !yd) {
9866
- return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
9867
- }
9868
- if (!xd[0] || !yd[0])
9869
- return xd[0] ? xs : yd[0] ? -ys : 0;
9870
- if (xs !== ys)
9871
- return xs;
9872
- if (x.e !== y.e)
9873
- return x.e > y.e ^ xs < 0 ? 1 : -1;
9874
- xdL = xd.length;
9875
- ydL = yd.length;
9876
- for (i = 0, j = xdL < ydL ? xdL : ydL;i < j; ++i) {
9877
- if (xd[i] !== yd[i])
9878
- return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
9879
- }
9880
- return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
9881
- };
9882
- P.cosine = P.cos = function() {
9883
- var pr, rm, x = this, Ctor = x.constructor;
9884
- if (!x.d)
9885
- return new Ctor(NaN);
9886
- if (!x.d[0])
9887
- return new Ctor(1);
9888
- pr = Ctor.precision;
9889
- rm = Ctor.rounding;
9890
- Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
9891
- Ctor.rounding = 1;
9892
- x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
9893
- Ctor.precision = pr;
9894
- Ctor.rounding = rm;
9895
- return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
9896
- };
9897
- P.cubeRoot = P.cbrt = function() {
9898
- var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
9899
- if (!x.isFinite() || x.isZero())
9900
- return new Ctor(x);
9901
- external2 = false;
9902
- s = x.s * mathpow(x.s * x, 1 / 3);
9903
- if (!s || Math.abs(s) == 1 / 0) {
9904
- n = digitsToString(x.d);
9905
- e = x.e;
9906
- if (s = (e - n.length + 1) % 3)
9907
- n += s == 1 || s == -2 ? "0" : "00";
9908
- s = mathpow(n, 1 / 3);
9909
- e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
9910
- if (s == 1 / 0) {
9911
- n = "5e" + e;
9912
- } else {
9913
- n = s.toExponential();
9914
- n = n.slice(0, n.indexOf("e") + 1) + e;
9915
- }
9916
- r = new Ctor(n);
9917
- r.s = x.s;
9918
- } else {
9919
- r = new Ctor(s.toString());
9920
- }
9921
- sd = (e = Ctor.precision) + 3;
9922
- for (;; ) {
9923
- t = r;
9924
- t3 = t.times(t).times(t);
9925
- t3plusx = t3.plus(x);
9926
- r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
9927
- if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
9928
- n = n.slice(sd - 3, sd + 1);
9929
- if (n == "9999" || !rep && n == "4999") {
9930
- if (!rep) {
9931
- finalise(t, e + 1, 0);
9932
- if (t.times(t).times(t).eq(x)) {
9933
- r = t;
9934
- break;
9935
- }
9713
+ var sbumit = async (imageUrl, prompt) => {
9714
+ try {
9715
+ var data = JSON.stringify({
9716
+ arguments: [
9717
+ {
9718
+ name: "prompt",
9719
+ value: prompt || ""
9720
+ },
9721
+ {
9722
+ name: "negative_prompt",
9723
+ value: "闪烁、动画、模糊、变形、毁容、低质量、拼贴、颗粒状、抽象、计算机生成、扭曲"
9724
+ },
9725
+ {
9726
+ name: "cfg",
9727
+ value: "0.5"
9728
+ },
9729
+ {
9730
+ name: "duration",
9731
+ value: "5"
9732
+ },
9733
+ {
9734
+ name: "imageCount",
9735
+ value: "1"
9736
+ },
9737
+ {
9738
+ name: "kling_version",
9739
+ value: "1.5"
9740
+ },
9741
+ {
9742
+ name: "tail_image_enabled",
9743
+ value: "false"
9744
+ },
9745
+ {
9746
+ name: "camera_json",
9747
+ value: '{"type":"empty","horizontal":0,"vertical":0,"zoom":0,"tilt":0,"pan":0,"roll":0}'
9748
+ },
9749
+ {
9750
+ name: "camera_control_enabled",
9751
+ value: "false"
9752
+ },
9753
+ {
9754
+ name: "biz",
9755
+ value: "klingai"
9936
9756
  }
9937
- sd += 4;
9938
- rep = 1;
9939
- } else {
9940
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
9941
- finalise(r, e + 1, 1);
9942
- m = !r.times(r).times(r).eq(x);
9757
+ ],
9758
+ inputs: [
9759
+ {
9760
+ inputType: "URL",
9761
+ url: imageUrl,
9762
+ name: "input"
9943
9763
  }
9944
- break;
9945
- }
9946
- }
9947
- }
9948
- external2 = true;
9949
- return finalise(r, e, Ctor.rounding, m);
9950
- };
9951
- P.decimalPlaces = P.dp = function() {
9952
- var w, d = this.d, n = NaN;
9953
- if (d) {
9954
- w = d.length - 1;
9955
- n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
9956
- w = d[w];
9957
- if (w)
9958
- for (;w % 10 == 0; w /= 10)
9959
- n--;
9960
- if (n < 0)
9961
- n = 0;
9962
- }
9963
- return n;
9964
- };
9965
- P.dividedBy = P.div = function(y) {
9966
- return divide(this, new this.constructor(y));
9967
- };
9968
- P.dividedToIntegerBy = P.divToInt = function(y) {
9969
- var x = this, Ctor = x.constructor;
9970
- return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
9971
- };
9972
- P.equals = P.eq = function(y) {
9973
- return this.cmp(y) === 0;
9974
- };
9975
- P.floor = function() {
9976
- return finalise(new this.constructor(this), this.e + 1, 3);
9977
- };
9978
- P.greaterThan = P.gt = function(y) {
9979
- return this.cmp(y) > 0;
9980
- };
9981
- P.greaterThanOrEqualTo = P.gte = function(y) {
9982
- var k = this.cmp(y);
9983
- return k == 1 || k === 0;
9984
- };
9985
- P.hyperbolicCosine = P.cosh = function() {
9986
- var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
9987
- if (!x.isFinite())
9988
- return new Ctor(x.s ? 1 / 0 : NaN);
9989
- if (x.isZero())
9990
- return one;
9991
- pr = Ctor.precision;
9992
- rm = Ctor.rounding;
9993
- Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
9994
- Ctor.rounding = 1;
9995
- len = x.d.length;
9996
- if (len < 32) {
9997
- k = Math.ceil(len / 3);
9998
- n = (1 / tinyPow(4, k)).toString();
9999
- } else {
10000
- k = 16;
10001
- n = "2.3283064365386962890625e-10";
10002
- }
10003
- x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
10004
- var cosh2_x, i = k, d8 = new Ctor(8);
10005
- for (;i--; ) {
10006
- cosh2_x = x.times(x);
10007
- x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
9764
+ ],
9765
+ type: "m2v_img2video_hq"
9766
+ });
9767
+ const response = await axios2({
9768
+ method: "POST",
9769
+ url: "https://klingai.kuaishou.com/api/task/submit",
9770
+ data
9771
+ });
9772
+ return response.data?.data?.task?.id;
9773
+ } catch (error) {
9774
+ console.error("完成上传失败:", error);
9775
+ throw error;
10008
9776
  }
10009
- return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
10010
- };
10011
- P.hyperbolicSine = P.sinh = function() {
10012
- var k, pr, rm, len, x = this, Ctor = x.constructor;
10013
- if (!x.isFinite() || x.isZero())
10014
- return new Ctor(x);
10015
- pr = Ctor.precision;
10016
- rm = Ctor.rounding;
10017
- Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
10018
- Ctor.rounding = 1;
10019
- len = x.d.length;
10020
- if (len < 3) {
10021
- x = taylorSeries(Ctor, 2, x, x, true);
10022
- } else {
10023
- k = 1.4 * Math.sqrt(len);
10024
- k = k > 16 ? 16 : k | 0;
10025
- x = x.times(1 / tinyPow(5, k));
10026
- x = taylorSeries(Ctor, 2, x, x, true);
10027
- var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
10028
- for (;k--; ) {
10029
- sinh2_x = x.times(x);
10030
- x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
10031
- }
10032
- }
10033
- Ctor.precision = pr;
10034
- Ctor.rounding = rm;
10035
- return finalise(x, pr, rm, true);
10036
- };
10037
- P.hyperbolicTangent = P.tanh = function() {
10038
- var pr, rm, x = this, Ctor = x.constructor;
10039
- if (!x.isFinite())
10040
- return new Ctor(x.s);
10041
- if (x.isZero())
10042
- return new Ctor(x);
10043
- pr = Ctor.precision;
10044
- rm = Ctor.rounding;
10045
- Ctor.precision = pr + 7;
10046
- Ctor.rounding = 1;
10047
- return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
10048
- };
10049
- P.inverseCosine = P.acos = function() {
10050
- var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
10051
- if (k !== -1) {
10052
- return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
10053
- }
10054
- if (x.isZero())
10055
- return getPi(Ctor, pr + 4, rm).times(0.5);
10056
- Ctor.precision = pr + 6;
10057
- Ctor.rounding = 1;
10058
- x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
10059
- Ctor.precision = pr;
10060
- Ctor.rounding = rm;
10061
- return x.times(2);
10062
- };
10063
- P.inverseHyperbolicCosine = P.acosh = function() {
10064
- var pr, rm, x = this, Ctor = x.constructor;
10065
- if (x.lte(1))
10066
- return new Ctor(x.eq(1) ? 0 : NaN);
10067
- if (!x.isFinite())
10068
- return new Ctor(x);
10069
- pr = Ctor.precision;
10070
- rm = Ctor.rounding;
10071
- Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
10072
- Ctor.rounding = 1;
10073
- external2 = false;
10074
- x = x.times(x).minus(1).sqrt().plus(x);
10075
- external2 = true;
10076
- Ctor.precision = pr;
10077
- Ctor.rounding = rm;
10078
- return x.ln();
10079
- };
10080
- P.inverseHyperbolicSine = P.asinh = function() {
10081
- var pr, rm, x = this, Ctor = x.constructor;
10082
- if (!x.isFinite() || x.isZero())
10083
- return new Ctor(x);
10084
- pr = Ctor.precision;
10085
- rm = Ctor.rounding;
10086
- Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
10087
- Ctor.rounding = 1;
10088
- external2 = false;
10089
- x = x.times(x).plus(1).sqrt().plus(x);
10090
- external2 = true;
10091
- Ctor.precision = pr;
10092
- Ctor.rounding = rm;
10093
- return x.ln();
10094
9777
  };
10095
- P.inverseHyperbolicTangent = P.atanh = function() {
10096
- var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
10097
- if (!x.isFinite())
10098
- return new Ctor(NaN);
10099
- if (x.e >= 0)
10100
- return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
10101
- pr = Ctor.precision;
10102
- rm = Ctor.rounding;
10103
- xsd = x.sd();
10104
- if (Math.max(xsd, pr) < 2 * -x.e - 1)
10105
- return finalise(new Ctor(x), pr, rm, true);
10106
- Ctor.precision = wpr = xsd - x.e;
10107
- x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
10108
- Ctor.precision = pr + 4;
10109
- Ctor.rounding = 1;
10110
- x = x.ln();
10111
- Ctor.precision = pr;
10112
- Ctor.rounding = rm;
10113
- return x.times(0.5);
10114
- };
10115
- P.inverseSine = P.asin = function() {
10116
- var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
10117
- if (x.isZero())
10118
- return new Ctor(x);
10119
- k = x.abs().cmp(1);
10120
- pr = Ctor.precision;
10121
- rm = Ctor.rounding;
10122
- if (k !== -1) {
10123
- if (k === 0) {
10124
- halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
10125
- halfPi.s = x.s;
10126
- return halfPi;
10127
- }
10128
- return new Ctor(NaN);
10129
- }
10130
- Ctor.precision = pr + 6;
10131
- Ctor.rounding = 1;
10132
- x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
10133
- Ctor.precision = pr;
10134
- Ctor.rounding = rm;
10135
- return x.times(2);
10136
- };
10137
- P.inverseTangent = P.atan = function() {
10138
- var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
10139
- if (!x.isFinite()) {
10140
- if (!x.s)
10141
- return new Ctor(NaN);
10142
- if (pr + 4 <= PI_PRECISION) {
10143
- r = getPi(Ctor, pr + 4, rm).times(0.5);
10144
- r.s = x.s;
10145
- return r;
10146
- }
10147
- } else if (x.isZero()) {
10148
- return new Ctor(x);
10149
- } else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
10150
- r = getPi(Ctor, pr + 4, rm).times(0.25);
10151
- r.s = x.s;
10152
- return r;
10153
- }
10154
- Ctor.precision = wpr = pr + 10;
10155
- Ctor.rounding = 1;
10156
- k = Math.min(28, wpr / LOG_BASE + 2 | 0);
10157
- for (i = k;i; --i)
10158
- x = x.div(x.times(x).plus(1).sqrt().plus(1));
10159
- external2 = false;
10160
- j = Math.ceil(wpr / LOG_BASE);
10161
- n = 1;
10162
- x2 = x.times(x);
10163
- r = new Ctor(x);
10164
- px = x;
10165
- for (;i !== -1; ) {
10166
- px = px.times(x2);
10167
- t = r.minus(px.div(n += 2));
10168
- px = px.times(x2);
10169
- r = t.plus(px.div(n += 2));
10170
- if (r.d[j] !== undefined)
10171
- for (i = j;r.d[i] === t.d[i] && i--; )
10172
- ;
10173
- }
10174
- if (k)
10175
- r = r.times(2 << k - 1);
10176
- external2 = true;
10177
- return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
10178
- };
10179
- P.isFinite = function() {
10180
- return !!this.d;
10181
- };
10182
- P.isInteger = P.isInt = function() {
10183
- return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
10184
- };
10185
- P.isNaN = function() {
10186
- return !this.s;
10187
- };
10188
- P.isNegative = P.isNeg = function() {
10189
- return this.s < 0;
10190
- };
10191
- P.isPositive = P.isPos = function() {
10192
- return this.s > 0;
10193
- };
10194
- P.isZero = function() {
10195
- return !!this.d && this.d[0] === 0;
10196
- };
10197
- P.lessThan = P.lt = function(y) {
10198
- return this.cmp(y) < 0;
10199
- };
10200
- P.lessThanOrEqualTo = P.lte = function(y) {
10201
- return this.cmp(y) < 1;
10202
- };
10203
- P.logarithm = P.log = function(base) {
10204
- var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
10205
- if (base == null) {
10206
- base = new Ctor(10);
10207
- isBase10 = true;
10208
- } else {
10209
- base = new Ctor(base);
10210
- d = base.d;
10211
- if (base.s < 0 || !d || !d[0] || base.eq(1))
10212
- return new Ctor(NaN);
10213
- isBase10 = base.eq(10);
10214
- }
10215
- d = arg.d;
10216
- if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
10217
- return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
10218
- }
10219
- if (isBase10) {
10220
- if (d.length > 1) {
10221
- inf = true;
10222
- } else {
10223
- for (k = d[0];k % 10 === 0; )
10224
- k /= 10;
10225
- inf = k !== 1;
10226
- }
10227
- }
10228
- external2 = false;
10229
- sd = pr + guard;
10230
- num = naturalLogarithm(arg, sd);
10231
- denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
10232
- r = divide(num, denominator, sd, 1);
10233
- if (checkRoundingDigits(r.d, k = pr, rm)) {
10234
- do {
10235
- sd += 10;
10236
- num = naturalLogarithm(arg, sd);
10237
- denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
10238
- r = divide(num, denominator, sd, 1);
10239
- if (!inf) {
10240
- if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 100000000000000) {
10241
- r = finalise(r, pr + 1, 0);
10242
- }
10243
- break;
10244
- }
10245
- } while (checkRoundingDigits(r.d, k += 10, rm));
10246
- }
10247
- external2 = true;
10248
- return finalise(r, pr, rm);
10249
- };
10250
- P.minus = P.sub = function(y) {
10251
- var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
10252
- y = new Ctor(y);
10253
- if (!x.d || !y.d) {
10254
- if (!x.s || !y.s)
10255
- y = new Ctor(NaN);
10256
- else if (x.d)
10257
- y.s = -y.s;
10258
- else
10259
- y = new Ctor(y.d || x.s !== y.s ? x : NaN);
10260
- return y;
10261
- }
10262
- if (x.s != y.s) {
10263
- y.s = -y.s;
10264
- return x.plus(y);
10265
- }
10266
- xd = x.d;
10267
- yd = y.d;
10268
- pr = Ctor.precision;
10269
- rm = Ctor.rounding;
10270
- if (!xd[0] || !yd[0]) {
10271
- if (yd[0])
10272
- y.s = -y.s;
10273
- else if (xd[0])
10274
- y = new Ctor(x);
10275
- else
10276
- return new Ctor(rm === 3 ? -0 : 0);
10277
- return external2 ? finalise(y, pr, rm) : y;
10278
- }
10279
- e = mathfloor(y.e / LOG_BASE);
10280
- xe = mathfloor(x.e / LOG_BASE);
10281
- xd = xd.slice();
10282
- k = xe - e;
10283
- if (k) {
10284
- xLTy = k < 0;
10285
- if (xLTy) {
10286
- d = xd;
10287
- k = -k;
10288
- len = yd.length;
10289
- } else {
10290
- d = yd;
10291
- e = xe;
10292
- len = xd.length;
10293
- }
10294
- i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
10295
- if (k > i) {
10296
- k = i;
10297
- d.length = 1;
10298
- }
10299
- d.reverse();
10300
- for (i = k;i--; )
10301
- d.push(0);
10302
- d.reverse();
10303
- } else {
10304
- i = xd.length;
10305
- len = yd.length;
10306
- xLTy = i < len;
10307
- if (xLTy)
10308
- len = i;
10309
- for (i = 0;i < len; i++) {
10310
- if (xd[i] != yd[i]) {
10311
- xLTy = xd[i] < yd[i];
10312
- break;
10313
- }
10314
- }
10315
- k = 0;
10316
- }
10317
- if (xLTy) {
10318
- d = xd;
10319
- xd = yd;
10320
- yd = d;
10321
- y.s = -y.s;
10322
- }
10323
- len = xd.length;
10324
- for (i = yd.length - len;i > 0; --i)
10325
- xd[len++] = 0;
10326
- for (i = yd.length;i > k; ) {
10327
- if (xd[--i] < yd[i]) {
10328
- for (j = i;j && xd[--j] === 0; )
10329
- xd[j] = BASE - 1;
10330
- --xd[j];
10331
- xd[i] += BASE;
10332
- }
10333
- xd[i] -= yd[i];
10334
- }
10335
- for (;xd[--len] === 0; )
10336
- xd.pop();
10337
- for (;xd[0] === 0; xd.shift())
10338
- --e;
10339
- if (!xd[0])
10340
- return new Ctor(rm === 3 ? -0 : 0);
10341
- y.d = xd;
10342
- y.e = getBase10Exponent(xd, e);
10343
- return external2 ? finalise(y, pr, rm) : y;
10344
- };
10345
- P.modulo = P.mod = function(y) {
10346
- var q, x = this, Ctor = x.constructor;
10347
- y = new Ctor(y);
10348
- if (!x.d || !y.s || y.d && !y.d[0])
10349
- return new Ctor(NaN);
10350
- if (!y.d || x.d && !x.d[0]) {
10351
- return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
10352
- }
10353
- external2 = false;
10354
- if (Ctor.modulo == 9) {
10355
- q = divide(x, y.abs(), 0, 3, 1);
10356
- q.s *= y.s;
10357
- } else {
10358
- q = divide(x, y, 0, Ctor.modulo, 1);
9778
+ var calculateProgress = (taskData) => {
9779
+ const createTime = taskData?.task?.createTime;
9780
+ const etaTime = taskData?.etaTime;
9781
+ const currentTime = Date.now();
9782
+ if (!createTime || !etaTime) {
9783
+ return 0;
10359
9784
  }
10360
- q = q.times(y);
10361
- external2 = true;
10362
- return x.minus(q);
10363
- };
10364
- P.naturalExponential = P.exp = function() {
10365
- return naturalExponential(this);
10366
- };
10367
- P.naturalLogarithm = P.ln = function() {
10368
- return naturalLogarithm(this);
10369
- };
10370
- P.negated = P.neg = function() {
10371
- var x = new this.constructor(this);
10372
- x.s = -x.s;
10373
- return finalise(x);
10374
- };
10375
- P.plus = P.add = function(y) {
10376
- var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
10377
- y = new Ctor(y);
10378
- if (!x.d || !y.d) {
10379
- if (!x.s || !y.s)
10380
- y = new Ctor(NaN);
10381
- else if (!x.d)
10382
- y = new Ctor(y.d || x.s === y.s ? x : NaN);
10383
- return y;
10384
- }
10385
- if (x.s != y.s) {
10386
- y.s = -y.s;
10387
- return x.minus(y);
10388
- }
10389
- xd = x.d;
10390
- yd = y.d;
10391
- pr = Ctor.precision;
10392
- rm = Ctor.rounding;
10393
- if (!xd[0] || !yd[0]) {
10394
- if (!yd[0])
10395
- y = new Ctor(x);
10396
- return external2 ? finalise(y, pr, rm) : y;
10397
- }
10398
- k = mathfloor(x.e / LOG_BASE);
10399
- e = mathfloor(y.e / LOG_BASE);
10400
- xd = xd.slice();
10401
- i = k - e;
10402
- if (i) {
10403
- if (i < 0) {
10404
- d = xd;
10405
- i = -i;
10406
- len = yd.length;
10407
- } else {
10408
- d = yd;
10409
- e = k;
10410
- len = xd.length;
10411
- }
10412
- k = Math.ceil(pr / LOG_BASE);
10413
- len = k > len ? k + 1 : len + 1;
10414
- if (i > len) {
10415
- i = len;
10416
- d.length = 1;
10417
- }
10418
- d.reverse();
10419
- for (;i--; )
10420
- d.push(0);
10421
- d.reverse();
10422
- }
10423
- len = xd.length;
10424
- i = yd.length;
10425
- if (len - i < 0) {
10426
- i = len;
10427
- d = yd;
10428
- yd = xd;
10429
- xd = d;
10430
- }
10431
- for (carry = 0;i; ) {
10432
- carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
10433
- xd[i] %= BASE;
10434
- }
10435
- if (carry) {
10436
- xd.unshift(carry);
10437
- ++e;
10438
- }
10439
- for (len = xd.length;xd[--len] == 0; )
10440
- xd.pop();
10441
- y.d = xd;
10442
- y.e = getBase10Exponent(xd, e);
10443
- return external2 ? finalise(y, pr, rm) : y;
10444
- };
10445
- P.precision = P.sd = function(z) {
10446
- var k, x = this;
10447
- if (z !== undefined && z !== !!z && z !== 1 && z !== 0)
10448
- throw Error(invalidArgument + z);
10449
- if (x.d) {
10450
- k = getPrecision(x.d);
10451
- if (z && x.e + 1 > k)
10452
- k = x.e + 1;
10453
- } else {
10454
- k = NaN;
9785
+ const totalTimeSpan = etaTime - createTime;
9786
+ const timeElapsed = currentTime - createTime;
9787
+ if (totalTimeSpan <= 0) {
9788
+ return 0;
10455
9789
  }
10456
- return k;
10457
- };
10458
- P.round = function() {
10459
- var x = this, Ctor = x.constructor;
10460
- return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
10461
- };
10462
- P.sine = P.sin = function() {
10463
- var pr, rm, x = this, Ctor = x.constructor;
10464
- if (!x.isFinite())
10465
- return new Ctor(NaN);
10466
- if (x.isZero())
10467
- return new Ctor(x);
10468
- pr = Ctor.precision;
10469
- rm = Ctor.rounding;
10470
- Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
10471
- Ctor.rounding = 1;
10472
- x = sine(Ctor, toLessThanHalfPi(Ctor, x));
10473
- Ctor.precision = pr;
10474
- Ctor.rounding = rm;
10475
- return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
10476
- };
10477
- P.squareRoot = P.sqrt = function() {
10478
- var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
10479
- if (s !== 1 || !d || !d[0]) {
10480
- return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
10481
- }
10482
- external2 = false;
10483
- s = Math.sqrt(+x);
10484
- if (s == 0 || s == 1 / 0) {
10485
- n = digitsToString(d);
10486
- if ((n.length + e) % 2 == 0)
10487
- n += "0";
10488
- s = Math.sqrt(n);
10489
- e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
10490
- if (s == 1 / 0) {
10491
- n = "5e" + e;
10492
- } else {
10493
- n = s.toExponential();
10494
- n = n.slice(0, n.indexOf("e") + 1) + e;
10495
- }
10496
- r = new Ctor(n);
10497
- } else {
10498
- r = new Ctor(s.toString());
10499
- }
10500
- sd = (e = Ctor.precision) + 3;
10501
- for (;; ) {
10502
- t = r;
10503
- r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
10504
- if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
10505
- n = n.slice(sd - 3, sd + 1);
10506
- if (n == "9999" || !rep && n == "4999") {
10507
- if (!rep) {
10508
- finalise(t, e + 1, 0);
10509
- if (t.times(t).eq(x)) {
10510
- r = t;
10511
- break;
10512
- }
10513
- }
10514
- sd += 4;
10515
- rep = 1;
10516
- } else {
10517
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
10518
- finalise(r, e + 1, 1);
10519
- m = !r.times(r).eq(x);
10520
- }
10521
- break;
10522
- }
10523
- }
9790
+ let progressRatio = timeElapsed / totalTimeSpan;
9791
+ if (progressRatio >= 1) {
9792
+ progressRatio = 0.99;
10524
9793
  }
10525
- external2 = true;
10526
- return finalise(r, e, Ctor.rounding, m);
10527
- };
10528
- P.tangent = P.tan = function() {
10529
- var pr, rm, x = this, Ctor = x.constructor;
10530
- if (!x.isFinite())
10531
- return new Ctor(NaN);
10532
- if (x.isZero())
10533
- return new Ctor(x);
10534
- pr = Ctor.precision;
10535
- rm = Ctor.rounding;
10536
- Ctor.precision = pr + 10;
10537
- Ctor.rounding = 1;
10538
- x = x.sin();
10539
- x.s = 1;
10540
- x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
10541
- Ctor.precision = pr;
10542
- Ctor.rounding = rm;
10543
- return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
10544
- };
10545
- P.times = P.mul = function(y) {
10546
- var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
10547
- y.s *= x.s;
10548
- if (!xd || !xd[0] || !yd || !yd[0]) {
10549
- return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
10550
- }
10551
- e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
10552
- xdL = xd.length;
10553
- ydL = yd.length;
10554
- if (xdL < ydL) {
10555
- r = xd;
10556
- xd = yd;
10557
- yd = r;
10558
- rL = xdL;
10559
- xdL = ydL;
10560
- ydL = rL;
10561
- }
10562
- r = [];
10563
- rL = xdL + ydL;
10564
- for (i = rL;i--; )
10565
- r.push(0);
10566
- for (i = ydL;--i >= 0; ) {
10567
- carry = 0;
10568
- for (k = xdL + i;k > i; ) {
10569
- t = r[k] + yd[i] * xd[k - i - 1] + carry;
10570
- r[k--] = t % BASE | 0;
10571
- carry = t / BASE | 0;
10572
- }
10573
- r[k] = (r[k] + carry) % BASE | 0;
10574
- }
10575
- for (;!r[--rL]; )
10576
- r.pop();
10577
- if (carry)
10578
- ++e;
10579
- else
10580
- r.shift();
10581
- y.d = r;
10582
- y.e = getBase10Exponent(r, e);
10583
- return external2 ? finalise(y, Ctor.precision, Ctor.rounding) : y;
10584
- };
10585
- P.toBinary = function(sd, rm) {
10586
- return toStringBinary(this, 2, sd, rm);
10587
- };
10588
- P.toDecimalPlaces = P.toDP = function(dp, rm) {
10589
- var x = this, Ctor = x.constructor;
10590
- x = new Ctor(x);
10591
- if (dp === undefined)
10592
- return x;
10593
- checkInt32(dp, 0, MAX_DIGITS);
10594
- if (rm === undefined)
10595
- rm = Ctor.rounding;
10596
- else
10597
- checkInt32(rm, 0, 8);
10598
- return finalise(x, dp + x.e + 1, rm);
10599
- };
10600
- P.toExponential = function(dp, rm) {
10601
- var str, x = this, Ctor = x.constructor;
10602
- if (dp === undefined) {
10603
- str = finiteToString(x, true);
10604
- } else {
10605
- checkInt32(dp, 0, MAX_DIGITS);
10606
- if (rm === undefined)
10607
- rm = Ctor.rounding;
10608
- else
10609
- checkInt32(rm, 0, 8);
10610
- x = finalise(new Ctor(x), dp + 1, rm);
10611
- str = finiteToString(x, true, dp + 1);
10612
- }
10613
- return x.isNeg() && !x.isZero() ? "-" + str : str;
10614
- };
10615
- P.toFixed = function(dp, rm) {
10616
- var str, y, x = this, Ctor = x.constructor;
10617
- if (dp === undefined) {
10618
- str = finiteToString(x);
10619
- } else {
10620
- checkInt32(dp, 0, MAX_DIGITS);
10621
- if (rm === undefined)
10622
- rm = Ctor.rounding;
10623
- else
10624
- checkInt32(rm, 0, 8);
10625
- y = finalise(new Ctor(x), dp + x.e + 1, rm);
10626
- str = finiteToString(y, false, dp + y.e + 1);
10627
- }
10628
- return x.isNeg() && !x.isZero() ? "-" + str : str;
9794
+ return progressRatio;
10629
9795
  };
10630
- P.toFraction = function(maxD) {
10631
- var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
10632
- if (!xd)
10633
- return new Ctor(x);
10634
- n1 = d0 = new Ctor(1);
10635
- d1 = n0 = new Ctor(0);
10636
- d = new Ctor(d1);
10637
- e = d.e = getPrecision(xd) - x.e - 1;
10638
- k = e % LOG_BASE;
10639
- d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
10640
- if (maxD == null) {
10641
- maxD = e > 0 ? d : n1;
10642
- } else {
10643
- n = new Ctor(maxD);
10644
- if (!n.isInt() || n.lt(n1))
10645
- throw Error(invalidArgument + n);
10646
- maxD = n.gt(d) ? e > 0 ? d : n1 : n;
10647
- }
10648
- external2 = false;
10649
- n = new Ctor(digitsToString(xd));
10650
- pr = Ctor.precision;
10651
- Ctor.precision = e = xd.length * LOG_BASE * 2;
10652
- for (;; ) {
10653
- q = divide(n, d, 0, 1, 1);
10654
- d2 = d0.plus(q.times(d1));
10655
- if (d2.cmp(maxD) == 1)
10656
- break;
10657
- d0 = d1;
10658
- d1 = d2;
10659
- d2 = n1;
10660
- n1 = n0.plus(q.times(d2));
10661
- n0 = d2;
10662
- d2 = d;
10663
- d = n.minus(q.times(d2));
10664
- n = d2;
10665
- }
10666
- d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
10667
- n0 = n0.plus(d2.times(n1));
10668
- d0 = d0.plus(d2.times(d1));
10669
- n0.s = n1.s = x.s;
10670
- r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
10671
- Ctor.precision = pr;
10672
- external2 = true;
10673
- return r;
9796
+ var setCookie = (newCookieValue) => {
9797
+ axios2.defaults.headers.Cookie = newCookieValue;
10674
9798
  };
10675
- P.toHexadecimal = P.toHex = function(sd, rm) {
10676
- return toStringBinary(this, 16, sd, rm);
10677
- };
10678
- P.toNearest = function(y, rm) {
10679
- var x = this, Ctor = x.constructor;
10680
- x = new Ctor(x);
10681
- if (y == null) {
10682
- if (!x.d)
10683
- return x;
10684
- y = new Ctor(1);
10685
- rm = Ctor.rounding;
10686
- } else {
10687
- y = new Ctor(y);
10688
- if (rm === undefined) {
10689
- rm = Ctor.rounding;
10690
- } else {
10691
- checkInt32(rm, 0, 8);
10692
- }
10693
- if (!x.d)
10694
- return y.s ? x : y;
10695
- if (!y.d) {
10696
- if (y.s)
10697
- y.s = x.s;
10698
- return y;
10699
- }
10700
- }
10701
- if (y.d[0]) {
10702
- external2 = false;
10703
- x = divide(x, y, 0, rm, 1).times(y);
10704
- external2 = true;
10705
- finalise(x);
10706
- } else {
10707
- y.s = x.s;
10708
- x = y;
9799
+
9800
+ // src/common/ai/keling/index.ts
9801
+ var getVideoStatus = async (taskId) => {
9802
+ if (!taskId) {
9803
+ return;
10709
9804
  }
10710
- return x;
10711
- };
10712
- P.toNumber = function() {
10713
- return +this;
10714
- };
10715
- P.toOctal = function(sd, rm) {
10716
- return toStringBinary(this, 8, sd, rm);
10717
- };
10718
- P.toPower = P.pow = function(y) {
10719
- var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
10720
- if (!x.d || !y.d || !x.d[0] || !y.d[0])
10721
- return new Ctor(mathpow(+x, yn));
10722
- x = new Ctor(x);
10723
- if (x.eq(1))
10724
- return x;
10725
- pr = Ctor.precision;
10726
- rm = Ctor.rounding;
10727
- if (y.eq(1))
10728
- return finalise(x, pr, rm);
10729
- e = mathfloor(y.e / LOG_BASE);
10730
- if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
10731
- r = intPow(Ctor, x, k, pr);
10732
- return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
10733
- }
10734
- s = x.s;
10735
- if (s < 0) {
10736
- if (e < y.d.length - 1)
10737
- return new Ctor(NaN);
10738
- if ((y.d[e] & 1) == 0)
10739
- s = 1;
10740
- if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
10741
- x.s = s;
10742
- return x;
10743
- }
10744
- }
10745
- k = mathpow(+x, yn);
10746
- e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
10747
- if (e > Ctor.maxE + 1 || e < Ctor.minE - 1)
10748
- return new Ctor(e > 0 ? s / 0 : 0);
10749
- external2 = false;
10750
- Ctor.rounding = x.s = 1;
10751
- k = Math.min(12, (e + "").length);
10752
- r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
10753
- if (r.d) {
10754
- r = finalise(r, pr + 5, 1);
10755
- if (checkRoundingDigits(r.d, pr, rm)) {
10756
- e = pr + 10;
10757
- r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
10758
- if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 100000000000000) {
10759
- r = finalise(r, pr + 1, 0);
10760
- }
10761
- }
10762
- }
10763
- r.s = s;
10764
- external2 = true;
10765
- Ctor.rounding = rm;
10766
- return finalise(r, pr, rm);
10767
- };
10768
- P.toPrecision = function(sd, rm) {
10769
- var str, x = this, Ctor = x.constructor;
10770
- if (sd === undefined) {
10771
- str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
10772
- } else {
10773
- checkInt32(sd, 1, MAX_DIGITS);
10774
- if (rm === undefined)
10775
- rm = Ctor.rounding;
10776
- else
10777
- checkInt32(rm, 0, 8);
10778
- x = finalise(new Ctor(x), sd, rm);
10779
- str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
10780
- }
10781
- return x.isNeg() && !x.isZero() ? "-" + str : str;
10782
- };
10783
- P.toSignificantDigits = P.toSD = function(sd, rm) {
10784
- var x = this, Ctor = x.constructor;
10785
- if (sd === undefined) {
10786
- sd = Ctor.precision;
10787
- rm = Ctor.rounding;
10788
- } else {
10789
- checkInt32(sd, 1, MAX_DIGITS);
10790
- if (rm === undefined)
10791
- rm = Ctor.rounding;
10792
- else
10793
- checkInt32(rm, 0, 8);
9805
+ try {
9806
+ const response = await axios2.get("https://klingai.kuaishou.com/api/task/status", {
9807
+ params: { taskId }
9808
+ });
9809
+ return {
9810
+ status: response.data?.data?.status,
9811
+ url: response.data?.data?.works?.[0]?.resource?.resource,
9812
+ cover: response.data?.data?.works?.[0]?.cover?.resource,
9813
+ progress: calculateProgress(response.data?.data) * 100
9814
+ };
9815
+ } catch (error) {
9816
+ console.error("获取 status 失败:", error);
9817
+ throw error;
10794
9818
  }
10795
- return finalise(new Ctor(x), sd, rm);
10796
9819
  };
10797
- P.toString = function() {
10798
- var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
10799
- return x.isNeg() && !x.isZero() ? "-" + str : str;
9820
+ var generateVideo = async (imageUrl, prompt) => {
9821
+ const uploadedUrl = await uploadImage(imageUrl);
9822
+ console.log("图片上传成功,URL:", uploadedUrl);
9823
+ const taskId = await sbumit(uploadedUrl, prompt);
9824
+ console.log(666, "任务 id", taskId);
9825
+ return taskId;
10800
9826
  };
10801
- P.truncated = P.trunc = function() {
10802
- return finalise(new this.constructor(this), this.e + 1, 1);
10803
- };
10804
- P.valueOf = P.toJSON = function() {
10805
- var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
10806
- return x.isNeg() ? "-" + str : str;
10807
- };
10808
- function digitsToString(d) {
10809
- var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
10810
- if (indexOfLastWord > 0) {
10811
- str += w;
10812
- for (i = 1;i < indexOfLastWord; i++) {
10813
- ws = d[i] + "";
10814
- k = LOG_BASE - ws.length;
10815
- if (k)
10816
- str += getZeroString(k);
10817
- str += ws;
10818
- }
10819
- w = d[i];
10820
- ws = w + "";
10821
- k = LOG_BASE - ws.length;
10822
- if (k)
10823
- str += getZeroString(k);
10824
- } else if (w === 0) {
10825
- return "0";
10826
- }
10827
- for (;w % 10 === 0; )
10828
- w /= 10;
10829
- return str + w;
10830
- }
10831
- function checkInt32(i, min, max) {
10832
- if (i !== ~~i || i < min || i > max) {
10833
- throw Error(invalidArgument + i);
9827
+ // src/common/image.ts
9828
+ var import_axios6 = __toESM(require("axios"));
9829
+ async function imageToBase64(url2) {
9830
+ try {
9831
+ const response = await import_axios6.default.get(url2, {
9832
+ responseType: "arraybuffer"
9833
+ });
9834
+ const base64String = Buffer.from(response.data).toString("base64");
9835
+ return `data:image/*;base64,${base64String}`;
9836
+ } catch (error) {
9837
+ console.error("Failed to fetch the image:", error);
9838
+ throw error;
10834
9839
  }
10835
9840
  }
10836
- function checkRoundingDigits(d, i, rm, repeating) {
10837
- var di, k, r, rd;
10838
- for (k = d[0];k >= 10; k /= 10)
10839
- --i;
10840
- if (--i < 0) {
10841
- i += LOG_BASE;
10842
- di = 0;
10843
- } else {
10844
- di = Math.ceil((i + 1) / LOG_BASE);
10845
- i %= LOG_BASE;
10846
- }
10847
- k = mathpow(10, LOG_BASE - i);
10848
- rd = d[di] % k | 0;
10849
- if (repeating == null) {
10850
- if (i < 3) {
10851
- if (i == 0)
10852
- rd = rd / 100 | 0;
10853
- else if (i == 1)
10854
- rd = rd / 10 | 0;
10855
- r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 50000 || rd == 0;
10856
- } else {
10857
- r = (rm < 4 && rd + 1 == k || rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 100 | 0) == mathpow(10, i - 2) - 1 || (rd == k / 2 || rd == 0) && (d[di + 1] / k / 100 | 0) == 0;
10858
- }
10859
- } else {
10860
- if (i < 4) {
10861
- if (i == 0)
10862
- rd = rd / 1000 | 0;
10863
- else if (i == 1)
10864
- rd = rd / 100 | 0;
10865
- else if (i == 2)
10866
- rd = rd / 10 | 0;
10867
- r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
10868
- } else {
10869
- r = ((repeating || rm < 4) && rd + 1 == k || !repeating && rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 1000 | 0) == mathpow(10, i - 3) - 1;
10870
- }
10871
- }
10872
- return r;
10873
- }
10874
- function convertBase(str, baseIn, baseOut) {
10875
- var j, arr = [0], arrL, i = 0, strL = str.length;
10876
- for (;i < strL; ) {
10877
- for (arrL = arr.length;arrL--; )
10878
- arr[arrL] *= baseIn;
10879
- arr[0] += NUMERALS.indexOf(str.charAt(i++));
10880
- for (j = 0;j < arr.length; j++) {
10881
- if (arr[j] > baseOut - 1) {
10882
- if (arr[j + 1] === undefined)
10883
- arr[j + 1] = 0;
10884
- arr[j + 1] += arr[j] / baseOut | 0;
10885
- arr[j] %= baseOut;
10886
- }
10887
- }
10888
- }
10889
- return arr.reverse();
10890
- }
10891
- function cosine(Ctor, x) {
10892
- var k, len, y;
10893
- if (x.isZero())
10894
- return x;
10895
- len = x.d.length;
10896
- if (len < 32) {
10897
- k = Math.ceil(len / 3);
10898
- y = (1 / tinyPow(4, k)).toString();
10899
- } else {
10900
- k = 16;
10901
- y = "2.3283064365386962890625e-10";
10902
- }
10903
- Ctor.precision += k;
10904
- x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
10905
- for (var i = k;i--; ) {
10906
- var cos2x = x.times(x);
10907
- x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
10908
- }
10909
- Ctor.precision -= k;
10910
- return x;
10911
- }
10912
- var divide = function() {
10913
- function multiplyInteger(x, k, base) {
10914
- var temp, carry = 0, i = x.length;
10915
- for (x = x.slice();i--; ) {
10916
- temp = x[i] * k + carry;
10917
- x[i] = temp % base | 0;
10918
- carry = temp / base | 0;
10919
- }
10920
- if (carry)
10921
- x.unshift(carry);
10922
- return x;
10923
- }
10924
- function compare(a, b, aL, bL) {
10925
- var i, r;
10926
- if (aL != bL) {
10927
- r = aL > bL ? 1 : -1;
10928
- } else {
10929
- for (i = r = 0;i < aL; i++) {
10930
- if (a[i] != b[i]) {
10931
- r = a[i] > b[i] ? 1 : -1;
10932
- break;
10933
- }
10934
- }
10935
- }
10936
- return r;
10937
- }
10938
- function subtract(a, b, aL, base) {
10939
- var i = 0;
10940
- for (;aL--; ) {
10941
- a[aL] -= i;
10942
- i = a[aL] < b[aL] ? 1 : 0;
10943
- a[aL] = i * base + a[aL] - b[aL];
10944
- }
10945
- for (;!a[0] && a.length > 1; )
10946
- a.shift();
10947
- }
10948
- return function(x, y, pr, rm, dp, base) {
10949
- var cmp, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
10950
- if (!xd || !xd[0] || !yd || !yd[0]) {
10951
- return new Ctor(!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : xd && xd[0] == 0 || !yd ? sign * 0 : sign / 0);
10952
- }
10953
- if (base) {
10954
- logBase = 1;
10955
- e = x.e - y.e;
10956
- } else {
10957
- base = BASE;
10958
- logBase = LOG_BASE;
10959
- e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
10960
- }
10961
- yL = yd.length;
10962
- xL = xd.length;
10963
- q = new Ctor(sign);
10964
- qd = q.d = [];
10965
- for (i = 0;yd[i] == (xd[i] || 0); i++)
10966
- ;
10967
- if (yd[i] > (xd[i] || 0))
10968
- e--;
10969
- if (pr == null) {
10970
- sd = pr = Ctor.precision;
10971
- rm = Ctor.rounding;
10972
- } else if (dp) {
10973
- sd = pr + (x.e - y.e) + 1;
10974
- } else {
10975
- sd = pr;
10976
- }
10977
- if (sd < 0) {
10978
- qd.push(1);
10979
- more = true;
10980
- } else {
10981
- sd = sd / logBase + 2 | 0;
10982
- i = 0;
10983
- if (yL == 1) {
10984
- k = 0;
10985
- yd = yd[0];
10986
- sd++;
10987
- for (;(i < xL || k) && sd--; i++) {
10988
- t = k * base + (xd[i] || 0);
10989
- qd[i] = t / yd | 0;
10990
- k = t % yd | 0;
10991
- }
10992
- more = k || i < xL;
10993
- } else {
10994
- k = base / (yd[0] + 1) | 0;
10995
- if (k > 1) {
10996
- yd = multiplyInteger(yd, k, base);
10997
- xd = multiplyInteger(xd, k, base);
10998
- yL = yd.length;
10999
- xL = xd.length;
11000
- }
11001
- xi = yL;
11002
- rem = xd.slice(0, yL);
11003
- remL = rem.length;
11004
- for (;remL < yL; )
11005
- rem[remL++] = 0;
11006
- yz = yd.slice();
11007
- yz.unshift(0);
11008
- yd0 = yd[0];
11009
- if (yd[1] >= base / 2)
11010
- ++yd0;
11011
- do {
11012
- k = 0;
11013
- cmp = compare(yd, rem, yL, remL);
11014
- if (cmp < 0) {
11015
- rem0 = rem[0];
11016
- if (yL != remL)
11017
- rem0 = rem0 * base + (rem[1] || 0);
11018
- k = rem0 / yd0 | 0;
11019
- if (k > 1) {
11020
- if (k >= base)
11021
- k = base - 1;
11022
- prod = multiplyInteger(yd, k, base);
11023
- prodL = prod.length;
11024
- remL = rem.length;
11025
- cmp = compare(prod, rem, prodL, remL);
11026
- if (cmp == 1) {
11027
- k--;
11028
- subtract(prod, yL < prodL ? yz : yd, prodL, base);
11029
- }
11030
- } else {
11031
- if (k == 0)
11032
- cmp = k = 1;
11033
- prod = yd.slice();
11034
- }
11035
- prodL = prod.length;
11036
- if (prodL < remL)
11037
- prod.unshift(0);
11038
- subtract(rem, prod, remL, base);
11039
- if (cmp == -1) {
11040
- remL = rem.length;
11041
- cmp = compare(yd, rem, yL, remL);
11042
- if (cmp < 1) {
11043
- k++;
11044
- subtract(rem, yL < remL ? yz : yd, remL, base);
11045
- }
11046
- }
11047
- remL = rem.length;
11048
- } else if (cmp === 0) {
11049
- k++;
11050
- rem = [0];
11051
- }
11052
- qd[i++] = k;
11053
- if (cmp && rem[0]) {
11054
- rem[remL++] = xd[xi] || 0;
11055
- } else {
11056
- rem = [xd[xi]];
11057
- remL = 1;
11058
- }
11059
- } while ((xi++ < xL || rem[0] !== undefined) && sd--);
11060
- more = rem[0] !== undefined;
11061
- }
11062
- if (!qd[0])
11063
- qd.shift();
11064
- }
11065
- if (logBase == 1) {
11066
- q.e = e;
11067
- inexact = more;
11068
- } else {
11069
- for (i = 1, k = qd[0];k >= 10; k /= 10)
11070
- i++;
11071
- q.e = i + e * logBase - 1;
11072
- finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
11073
- }
11074
- return q;
11075
- };
11076
- }();
11077
- function finalise(x, sd, rm, isTruncated) {
11078
- var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
11079
- out:
11080
- if (sd != null) {
11081
- xd = x.d;
11082
- if (!xd)
11083
- return x;
11084
- for (digits = 1, k = xd[0];k >= 10; k /= 10)
11085
- digits++;
11086
- i = sd - digits;
11087
- if (i < 0) {
11088
- i += LOG_BASE;
11089
- j = sd;
11090
- w = xd[xdi = 0];
11091
- rd = w / mathpow(10, digits - j - 1) % 10 | 0;
11092
- } else {
11093
- xdi = Math.ceil((i + 1) / LOG_BASE);
11094
- k = xd.length;
11095
- if (xdi >= k) {
11096
- if (isTruncated) {
11097
- for (;k++ <= xdi; )
11098
- xd.push(0);
11099
- w = rd = 0;
11100
- digits = 1;
11101
- i %= LOG_BASE;
11102
- j = i - LOG_BASE + 1;
11103
- } else {
11104
- break out;
11105
- }
11106
- } else {
11107
- w = k = xd[xdi];
11108
- for (digits = 1;k >= 10; k /= 10)
11109
- digits++;
11110
- i %= LOG_BASE;
11111
- j = i - LOG_BASE + digits;
11112
- rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
11113
- }
11114
- }
11115
- isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== undefined || (j < 0 ? w : w % mathpow(10, digits - j - 1));
11116
- roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && (i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
11117
- if (sd < 1 || !xd[0]) {
11118
- xd.length = 0;
11119
- if (roundUp) {
11120
- sd -= x.e + 1;
11121
- xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
11122
- x.e = -sd || 0;
11123
- } else {
11124
- xd[0] = x.e = 0;
11125
- }
11126
- return x;
11127
- }
11128
- if (i == 0) {
11129
- xd.length = xdi;
11130
- k = 1;
11131
- xdi--;
11132
- } else {
11133
- xd.length = xdi + 1;
11134
- k = mathpow(10, LOG_BASE - i);
11135
- xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
11136
- }
11137
- if (roundUp) {
11138
- for (;; ) {
11139
- if (xdi == 0) {
11140
- for (i = 1, j = xd[0];j >= 10; j /= 10)
11141
- i++;
11142
- j = xd[0] += k;
11143
- for (k = 1;j >= 10; j /= 10)
11144
- k++;
11145
- if (i != k) {
11146
- x.e++;
11147
- if (xd[0] == BASE)
11148
- xd[0] = 1;
11149
- }
11150
- break;
11151
- } else {
11152
- xd[xdi] += k;
11153
- if (xd[xdi] != BASE)
11154
- break;
11155
- xd[xdi--] = 0;
11156
- k = 1;
11157
- }
11158
- }
11159
- }
11160
- for (i = xd.length;xd[--i] === 0; )
11161
- xd.pop();
11162
- }
11163
- if (external2) {
11164
- if (x.e > Ctor.maxE) {
11165
- x.d = null;
11166
- x.e = NaN;
11167
- } else if (x.e < Ctor.minE) {
11168
- x.e = 0;
11169
- x.d = [0];
11170
- }
11171
- }
11172
- return x;
11173
- }
11174
- function finiteToString(x, isExp, sd) {
11175
- if (!x.isFinite())
11176
- return nonFiniteToString(x);
11177
- var k, e = x.e, str = digitsToString(x.d), len = str.length;
11178
- if (isExp) {
11179
- if (sd && (k = sd - len) > 0) {
11180
- str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
11181
- } else if (len > 1) {
11182
- str = str.charAt(0) + "." + str.slice(1);
11183
- }
11184
- str = str + (x.e < 0 ? "e" : "e+") + x.e;
11185
- } else if (e < 0) {
11186
- str = "0." + getZeroString(-e - 1) + str;
11187
- if (sd && (k = sd - len) > 0)
11188
- str += getZeroString(k);
11189
- } else if (e >= len) {
11190
- str += getZeroString(e + 1 - len);
11191
- if (sd && (k = sd - e - 1) > 0)
11192
- str = str + "." + getZeroString(k);
11193
- } else {
11194
- if ((k = e + 1) < len)
11195
- str = str.slice(0, k) + "." + str.slice(k);
11196
- if (sd && (k = sd - len) > 0) {
11197
- if (e + 1 === len)
11198
- str += ".";
11199
- str += getZeroString(k);
11200
- }
11201
- }
11202
- return str;
11203
- }
11204
- function getBase10Exponent(digits, e) {
11205
- var w = digits[0];
11206
- for (e *= LOG_BASE;w >= 10; w /= 10)
11207
- e++;
11208
- return e;
11209
- }
11210
- function getLn10(Ctor, sd, pr) {
11211
- if (sd > LN10_PRECISION) {
11212
- external2 = true;
11213
- if (pr)
11214
- Ctor.precision = pr;
11215
- throw Error(precisionLimitExceeded);
11216
- }
11217
- return finalise(new Ctor(LN10), sd, 1, true);
11218
- }
11219
- function getPi(Ctor, sd, rm) {
11220
- if (sd > PI_PRECISION)
11221
- throw Error(precisionLimitExceeded);
11222
- return finalise(new Ctor(PI), sd, rm, true);
11223
- }
11224
- function getPrecision(digits) {
11225
- var w = digits.length - 1, len = w * LOG_BASE + 1;
11226
- w = digits[w];
11227
- if (w) {
11228
- for (;w % 10 == 0; w /= 10)
11229
- len--;
11230
- for (w = digits[0];w >= 10; w /= 10)
11231
- len++;
11232
- }
11233
- return len;
11234
- }
11235
- function getZeroString(k) {
11236
- var zs = "";
11237
- for (;k--; )
11238
- zs += "0";
11239
- return zs;
11240
- }
11241
- function intPow(Ctor, x, n, pr) {
11242
- var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
11243
- external2 = false;
11244
- for (;; ) {
11245
- if (n % 2) {
11246
- r = r.times(x);
11247
- if (truncate(r.d, k))
11248
- isTruncated = true;
11249
- }
11250
- n = mathfloor(n / 2);
11251
- if (n === 0) {
11252
- n = r.d.length - 1;
11253
- if (isTruncated && r.d[n] === 0)
11254
- ++r.d[n];
11255
- break;
11256
- }
11257
- x = x.times(x);
11258
- truncate(x.d, k);
11259
- }
11260
- external2 = true;
11261
- return r;
11262
- }
11263
- function isOdd(n) {
11264
- return n.d[n.d.length - 1] & 1;
11265
- }
11266
- function maxOrMin(Ctor, args, n) {
11267
- var k, y, x = new Ctor(args[0]), i = 0;
11268
- for (;++i < args.length; ) {
11269
- y = new Ctor(args[i]);
11270
- if (!y.s) {
11271
- x = y;
11272
- break;
11273
- }
11274
- k = x.cmp(y);
11275
- if (k === n || k === 0 && x.s === n) {
11276
- x = y;
11277
- }
11278
- }
11279
- return x;
11280
- }
11281
- function naturalExponential(x, sd) {
11282
- var denominator, guard, j, pow, sum, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
11283
- if (!x.d || !x.d[0] || x.e > 17) {
11284
- return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
11285
- }
11286
- if (sd == null) {
11287
- external2 = false;
11288
- wpr = pr;
11289
- } else {
11290
- wpr = sd;
11291
- }
11292
- t = new Ctor(0.03125);
11293
- while (x.e > -2) {
11294
- x = x.times(t);
11295
- k += 5;
11296
- }
11297
- guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
11298
- wpr += guard;
11299
- denominator = pow = sum = new Ctor(1);
11300
- Ctor.precision = wpr;
11301
- for (;; ) {
11302
- pow = finalise(pow.times(x), wpr, 1);
11303
- denominator = denominator.times(++i);
11304
- t = sum.plus(divide(pow, denominator, wpr, 1));
11305
- if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
11306
- j = k;
11307
- while (j--)
11308
- sum = finalise(sum.times(sum), wpr, 1);
11309
- if (sd == null) {
11310
- if (rep < 3 && checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
11311
- Ctor.precision = wpr += 10;
11312
- denominator = pow = t = new Ctor(1);
11313
- i = 0;
11314
- rep++;
11315
- } else {
11316
- return finalise(sum, Ctor.precision = pr, rm, external2 = true);
11317
- }
11318
- } else {
11319
- Ctor.precision = pr;
11320
- return sum;
11321
- }
11322
- }
11323
- sum = t;
11324
- }
11325
- }
11326
- function naturalLogarithm(y, sd) {
11327
- var c, c0, denominator, e, numerator, rep, sum, t, wpr, x1, x2, n = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
11328
- if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
11329
- return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
11330
- }
11331
- if (sd == null) {
11332
- external2 = false;
11333
- wpr = pr;
11334
- } else {
11335
- wpr = sd;
11336
- }
11337
- Ctor.precision = wpr += guard;
11338
- c = digitsToString(xd);
11339
- c0 = c.charAt(0);
11340
- if (Math.abs(e = x.e) < 1500000000000000) {
11341
- while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
11342
- x = x.times(y);
11343
- c = digitsToString(x.d);
11344
- c0 = c.charAt(0);
11345
- n++;
11346
- }
11347
- e = x.e;
11348
- if (c0 > 1) {
11349
- x = new Ctor("0." + c);
11350
- e++;
11351
- } else {
11352
- x = new Ctor(c0 + "." + c.slice(1));
11353
- }
11354
- } else {
11355
- t = getLn10(Ctor, wpr + 2, pr).times(e + "");
11356
- x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
11357
- Ctor.precision = pr;
11358
- return sd == null ? finalise(x, pr, rm, external2 = true) : x;
11359
- }
11360
- x1 = x;
11361
- sum = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
11362
- x2 = finalise(x.times(x), wpr, 1);
11363
- denominator = 3;
11364
- for (;; ) {
11365
- numerator = finalise(numerator.times(x2), wpr, 1);
11366
- t = sum.plus(divide(numerator, new Ctor(denominator), wpr, 1));
11367
- if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
11368
- sum = sum.times(2);
11369
- if (e !== 0)
11370
- sum = sum.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
11371
- sum = divide(sum, new Ctor(n), wpr, 1);
11372
- if (sd == null) {
11373
- if (checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
11374
- Ctor.precision = wpr += guard;
11375
- t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
11376
- x2 = finalise(x.times(x), wpr, 1);
11377
- denominator = rep = 1;
11378
- } else {
11379
- return finalise(sum, Ctor.precision = pr, rm, external2 = true);
11380
- }
11381
- } else {
11382
- Ctor.precision = pr;
11383
- return sum;
11384
- }
11385
- }
11386
- sum = t;
11387
- denominator += 2;
11388
- }
11389
- }
11390
- function nonFiniteToString(x) {
11391
- return String(x.s * x.s / 0);
11392
- }
11393
- function parseDecimal(x, str) {
11394
- var e, i, len;
11395
- if ((e = str.indexOf(".")) > -1)
11396
- str = str.replace(".", "");
11397
- if ((i = str.search(/e/i)) > 0) {
11398
- if (e < 0)
11399
- e = i;
11400
- e += +str.slice(i + 1);
11401
- str = str.substring(0, i);
11402
- } else if (e < 0) {
11403
- e = str.length;
11404
- }
11405
- for (i = 0;str.charCodeAt(i) === 48; i++)
11406
- ;
11407
- for (len = str.length;str.charCodeAt(len - 1) === 48; --len)
11408
- ;
11409
- str = str.slice(i, len);
11410
- if (str) {
11411
- len -= i;
11412
- x.e = e = e - i - 1;
11413
- x.d = [];
11414
- i = (e + 1) % LOG_BASE;
11415
- if (e < 0)
11416
- i += LOG_BASE;
11417
- if (i < len) {
11418
- if (i)
11419
- x.d.push(+str.slice(0, i));
11420
- for (len -= LOG_BASE;i < len; )
11421
- x.d.push(+str.slice(i, i += LOG_BASE));
11422
- str = str.slice(i);
11423
- i = LOG_BASE - str.length;
11424
- } else {
11425
- i -= len;
11426
- }
11427
- for (;i--; )
11428
- str += "0";
11429
- x.d.push(+str);
11430
- if (external2) {
11431
- if (x.e > x.constructor.maxE) {
11432
- x.d = null;
11433
- x.e = NaN;
11434
- } else if (x.e < x.constructor.minE) {
11435
- x.e = 0;
11436
- x.d = [0];
11437
- }
11438
- }
11439
- } else {
11440
- x.e = 0;
11441
- x.d = [0];
11442
- }
11443
- return x;
11444
- }
11445
- function parseOther(x, str) {
11446
- var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
11447
- if (str.indexOf("_") > -1) {
11448
- str = str.replace(/(\d)_(?=\d)/g, "$1");
11449
- if (isDecimal.test(str))
11450
- return parseDecimal(x, str);
11451
- } else if (str === "Infinity" || str === "NaN") {
11452
- if (!+str)
11453
- x.s = NaN;
11454
- x.e = NaN;
11455
- x.d = null;
11456
- return x;
11457
- }
11458
- if (isHex.test(str)) {
11459
- base = 16;
11460
- str = str.toLowerCase();
11461
- } else if (isBinary.test(str)) {
11462
- base = 2;
11463
- } else if (isOctal.test(str)) {
11464
- base = 8;
11465
- } else {
11466
- throw Error(invalidArgument + str);
11467
- }
11468
- i = str.search(/p/i);
11469
- if (i > 0) {
11470
- p = +str.slice(i + 1);
11471
- str = str.substring(2, i);
11472
- } else {
11473
- str = str.slice(2);
11474
- }
11475
- i = str.indexOf(".");
11476
- isFloat = i >= 0;
11477
- Ctor = x.constructor;
11478
- if (isFloat) {
11479
- str = str.replace(".", "");
11480
- len = str.length;
11481
- i = len - i;
11482
- divisor = intPow(Ctor, new Ctor(base), i, i * 2);
11483
- }
11484
- xd = convertBase(str, base, BASE);
11485
- xe = xd.length - 1;
11486
- for (i = xe;xd[i] === 0; --i)
11487
- xd.pop();
11488
- if (i < 0)
11489
- return new Ctor(x.s * 0);
11490
- x.e = getBase10Exponent(xd, xe);
11491
- x.d = xd;
11492
- external2 = false;
11493
- if (isFloat)
11494
- x = divide(x, divisor, len * 4);
11495
- if (p)
11496
- x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
11497
- external2 = true;
11498
- return x;
11499
- }
11500
- function sine(Ctor, x) {
11501
- var k, len = x.d.length;
11502
- if (len < 3) {
11503
- return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
11504
- }
11505
- k = 1.4 * Math.sqrt(len);
11506
- k = k > 16 ? 16 : k | 0;
11507
- x = x.times(1 / tinyPow(5, k));
11508
- x = taylorSeries(Ctor, 2, x, x);
11509
- var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
11510
- for (;k--; ) {
11511
- sin2_x = x.times(x);
11512
- x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
11513
- }
11514
- return x;
11515
- }
11516
- function taylorSeries(Ctor, n, x, y, isHyperbolic) {
11517
- var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
11518
- external2 = false;
11519
- x2 = x.times(x);
11520
- u = new Ctor(y);
11521
- for (;; ) {
11522
- t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
11523
- u = isHyperbolic ? y.plus(t) : y.minus(t);
11524
- y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
11525
- t = u.plus(y);
11526
- if (t.d[k] !== undefined) {
11527
- for (j = k;t.d[j] === u.d[j] && j--; )
11528
- ;
11529
- if (j == -1)
11530
- break;
11531
- }
11532
- j = u;
11533
- u = y;
11534
- y = t;
11535
- t = j;
11536
- i++;
11537
- }
11538
- external2 = true;
11539
- t.d.length = k + 1;
11540
- return t;
11541
- }
11542
- function tinyPow(b, e) {
11543
- var n = b;
11544
- while (--e)
11545
- n *= b;
11546
- return n;
11547
- }
11548
- function toLessThanHalfPi(Ctor, x) {
11549
- var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
11550
- x = x.abs();
11551
- if (x.lte(halfPi)) {
11552
- quadrant = isNeg ? 4 : 1;
11553
- return x;
11554
- }
11555
- t = x.divToInt(pi);
11556
- if (t.isZero()) {
11557
- quadrant = isNeg ? 3 : 2;
11558
- } else {
11559
- x = x.minus(t.times(pi));
11560
- if (x.lte(halfPi)) {
11561
- quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
11562
- return x;
11563
- }
11564
- quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
11565
- }
11566
- return x.minus(pi).abs();
11567
- }
11568
- function toStringBinary(x, baseOut, sd, rm) {
11569
- var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== undefined;
11570
- if (isExp) {
11571
- checkInt32(sd, 1, MAX_DIGITS);
11572
- if (rm === undefined)
11573
- rm = Ctor.rounding;
11574
- else
11575
- checkInt32(rm, 0, 8);
11576
- } else {
11577
- sd = Ctor.precision;
11578
- rm = Ctor.rounding;
11579
- }
11580
- if (!x.isFinite()) {
11581
- str = nonFiniteToString(x);
11582
- } else {
11583
- str = finiteToString(x);
11584
- i = str.indexOf(".");
11585
- if (isExp) {
11586
- base = 2;
11587
- if (baseOut == 16) {
11588
- sd = sd * 4 - 3;
11589
- } else if (baseOut == 8) {
11590
- sd = sd * 3 - 2;
11591
- }
11592
- } else {
11593
- base = baseOut;
11594
- }
11595
- if (i >= 0) {
11596
- str = str.replace(".", "");
11597
- y = new Ctor(1);
11598
- y.e = str.length - i;
11599
- y.d = convertBase(finiteToString(y), 10, base);
11600
- y.e = y.d.length;
11601
- }
11602
- xd = convertBase(str, 10, base);
11603
- e = len = xd.length;
11604
- for (;xd[--len] == 0; )
11605
- xd.pop();
11606
- if (!xd[0]) {
11607
- str = isExp ? "0p+0" : "0";
11608
- } else {
11609
- if (i < 0) {
11610
- e--;
11611
- } else {
11612
- x = new Ctor(x);
11613
- x.d = xd;
11614
- x.e = e;
11615
- x = divide(x, y, sd, rm, 0, base);
11616
- xd = x.d;
11617
- e = x.e;
11618
- roundUp = inexact;
11619
- }
11620
- i = xd[sd];
11621
- k = base / 2;
11622
- roundUp = roundUp || xd[sd + 1] !== undefined;
11623
- roundUp = rm < 4 ? (i !== undefined || roundUp) && (rm === 0 || rm === (x.s < 0 ? 3 : 2)) : i > k || i === k && (rm === 4 || roundUp || rm === 6 && xd[sd - 1] & 1 || rm === (x.s < 0 ? 8 : 7));
11624
- xd.length = sd;
11625
- if (roundUp) {
11626
- for (;++xd[--sd] > base - 1; ) {
11627
- xd[sd] = 0;
11628
- if (!sd) {
11629
- ++e;
11630
- xd.unshift(1);
11631
- }
11632
- }
11633
- }
11634
- for (len = xd.length;!xd[len - 1]; --len)
11635
- ;
11636
- for (i = 0, str = "";i < len; i++)
11637
- str += NUMERALS.charAt(xd[i]);
11638
- if (isExp) {
11639
- if (len > 1) {
11640
- if (baseOut == 16 || baseOut == 8) {
11641
- i = baseOut == 16 ? 4 : 3;
11642
- for (--len;len % i; len++)
11643
- str += "0";
11644
- xd = convertBase(str, base, baseOut);
11645
- for (len = xd.length;!xd[len - 1]; --len)
11646
- ;
11647
- for (i = 1, str = "1.";i < len; i++)
11648
- str += NUMERALS.charAt(xd[i]);
11649
- } else {
11650
- str = str.charAt(0) + "." + str.slice(1);
11651
- }
11652
- }
11653
- str = str + (e < 0 ? "p" : "p+") + e;
11654
- } else if (e < 0) {
11655
- for (;++e; )
11656
- str = "0" + str;
11657
- str = "0." + str;
11658
- } else {
11659
- if (++e > len)
11660
- for (e -= len;e--; )
11661
- str += "0";
11662
- else if (e < len)
11663
- str = str.slice(0, e) + "." + str.slice(e);
11664
- }
11665
- }
11666
- str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
11667
- }
11668
- return x.s < 0 ? "-" + str : str;
11669
- }
11670
- function truncate(arr, len) {
11671
- if (arr.length > len) {
11672
- arr.length = len;
11673
- return true;
11674
- }
11675
- }
11676
- function abs(x) {
11677
- return new this(x).abs();
11678
- }
11679
- function acos(x) {
11680
- return new this(x).acos();
11681
- }
11682
- function acosh(x) {
11683
- return new this(x).acosh();
11684
- }
11685
- function add(x, y) {
11686
- return new this(x).plus(y);
11687
- }
11688
- function asin(x) {
11689
- return new this(x).asin();
11690
- }
11691
- function asinh(x) {
11692
- return new this(x).asinh();
11693
- }
11694
- function atan(x) {
11695
- return new this(x).atan();
11696
- }
11697
- function atanh(x) {
11698
- return new this(x).atanh();
11699
- }
11700
- function atan2(y, x) {
11701
- y = new this(y);
11702
- x = new this(x);
11703
- var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
11704
- if (!y.s || !x.s) {
11705
- r = new this(NaN);
11706
- } else if (!y.d && !x.d) {
11707
- r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
11708
- r.s = y.s;
11709
- } else if (!x.d || y.isZero()) {
11710
- r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
11711
- r.s = y.s;
11712
- } else if (!y.d || x.isZero()) {
11713
- r = getPi(this, wpr, 1).times(0.5);
11714
- r.s = y.s;
11715
- } else if (x.s < 0) {
11716
- this.precision = wpr;
11717
- this.rounding = 1;
11718
- r = this.atan(divide(y, x, wpr, 1));
11719
- x = getPi(this, wpr, 1);
11720
- this.precision = pr;
11721
- this.rounding = rm;
11722
- r = y.s < 0 ? r.minus(x) : r.plus(x);
11723
- } else {
11724
- r = this.atan(divide(y, x, wpr, 1));
11725
- }
11726
- return r;
11727
- }
11728
- function cbrt(x) {
11729
- return new this(x).cbrt();
11730
- }
11731
- function ceil(x) {
11732
- return finalise(x = new this(x), x.e + 1, 2);
11733
- }
11734
- function clamp(x, min, max) {
11735
- return new this(x).clamp(min, max);
11736
- }
11737
- function config(obj) {
11738
- if (!obj || typeof obj !== "object")
11739
- throw Error(decimalError + "Object expected");
11740
- var i, p, v, useDefaults = obj.defaults === true, ps = [
11741
- "precision",
11742
- 1,
11743
- MAX_DIGITS,
11744
- "rounding",
11745
- 0,
11746
- 8,
11747
- "toExpNeg",
11748
- -EXP_LIMIT,
11749
- 0,
11750
- "toExpPos",
11751
- 0,
11752
- EXP_LIMIT,
11753
- "maxE",
11754
- 0,
11755
- EXP_LIMIT,
11756
- "minE",
11757
- -EXP_LIMIT,
11758
- 0,
11759
- "modulo",
11760
- 0,
11761
- 9
11762
- ];
11763
- for (i = 0;i < ps.length; i += 3) {
11764
- if (p = ps[i], useDefaults)
11765
- this[p] = DEFAULTS[p];
11766
- if ((v = obj[p]) !== undefined) {
11767
- if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
11768
- this[p] = v;
11769
- else
11770
- throw Error(invalidArgument + p + ": " + v);
11771
- }
11772
- }
11773
- if (p = "crypto", useDefaults)
11774
- this[p] = DEFAULTS[p];
11775
- if ((v = obj[p]) !== undefined) {
11776
- if (v === true || v === false || v === 0 || v === 1) {
11777
- if (v) {
11778
- if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
11779
- this[p] = true;
11780
- } else {
11781
- throw Error(cryptoUnavailable);
11782
- }
11783
- } else {
11784
- this[p] = false;
11785
- }
11786
- } else {
11787
- throw Error(invalidArgument + p + ": " + v);
11788
- }
11789
- }
11790
- return this;
11791
- }
11792
- function cos(x) {
11793
- return new this(x).cos();
11794
- }
11795
- function cosh(x) {
11796
- return new this(x).cosh();
11797
- }
11798
- function clone(obj) {
11799
- var i, p, ps;
11800
- function Decimal(v) {
11801
- var e, i2, t, x = this;
11802
- if (!(x instanceof Decimal))
11803
- return new Decimal(v);
11804
- x.constructor = Decimal;
11805
- if (isDecimalInstance(v)) {
11806
- x.s = v.s;
11807
- if (external2) {
11808
- if (!v.d || v.e > Decimal.maxE) {
11809
- x.e = NaN;
11810
- x.d = null;
11811
- } else if (v.e < Decimal.minE) {
11812
- x.e = 0;
11813
- x.d = [0];
11814
- } else {
11815
- x.e = v.e;
11816
- x.d = v.d.slice();
11817
- }
11818
- } else {
11819
- x.e = v.e;
11820
- x.d = v.d ? v.d.slice() : v.d;
11821
- }
11822
- return;
11823
- }
11824
- t = typeof v;
11825
- if (t === "number") {
11826
- if (v === 0) {
11827
- x.s = 1 / v < 0 ? -1 : 1;
11828
- x.e = 0;
11829
- x.d = [0];
11830
- return;
11831
- }
11832
- if (v < 0) {
11833
- v = -v;
11834
- x.s = -1;
11835
- } else {
11836
- x.s = 1;
11837
- }
11838
- if (v === ~~v && v < 1e7) {
11839
- for (e = 0, i2 = v;i2 >= 10; i2 /= 10)
11840
- e++;
11841
- if (external2) {
11842
- if (e > Decimal.maxE) {
11843
- x.e = NaN;
11844
- x.d = null;
11845
- } else if (e < Decimal.minE) {
11846
- x.e = 0;
11847
- x.d = [0];
11848
- } else {
11849
- x.e = e;
11850
- x.d = [v];
11851
- }
11852
- } else {
11853
- x.e = e;
11854
- x.d = [v];
11855
- }
11856
- return;
11857
- }
11858
- if (v * 0 !== 0) {
11859
- if (!v)
11860
- x.s = NaN;
11861
- x.e = NaN;
11862
- x.d = null;
11863
- return;
11864
- }
11865
- return parseDecimal(x, v.toString());
11866
- }
11867
- if (t === "string") {
11868
- if ((i2 = v.charCodeAt(0)) === 45) {
11869
- v = v.slice(1);
11870
- x.s = -1;
11871
- } else {
11872
- if (i2 === 43)
11873
- v = v.slice(1);
11874
- x.s = 1;
11875
- }
11876
- return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
11877
- }
11878
- if (t === "bigint") {
11879
- if (v < 0) {
11880
- v = -v;
11881
- x.s = -1;
11882
- } else {
11883
- x.s = 1;
11884
- }
11885
- return parseDecimal(x, v.toString());
11886
- }
11887
- throw Error(invalidArgument + v);
11888
- }
11889
- Decimal.prototype = P;
11890
- Decimal.ROUND_UP = 0;
11891
- Decimal.ROUND_DOWN = 1;
11892
- Decimal.ROUND_CEIL = 2;
11893
- Decimal.ROUND_FLOOR = 3;
11894
- Decimal.ROUND_HALF_UP = 4;
11895
- Decimal.ROUND_HALF_DOWN = 5;
11896
- Decimal.ROUND_HALF_EVEN = 6;
11897
- Decimal.ROUND_HALF_CEIL = 7;
11898
- Decimal.ROUND_HALF_FLOOR = 8;
11899
- Decimal.EUCLID = 9;
11900
- Decimal.config = Decimal.set = config;
11901
- Decimal.clone = clone;
11902
- Decimal.isDecimal = isDecimalInstance;
11903
- Decimal.abs = abs;
11904
- Decimal.acos = acos;
11905
- Decimal.acosh = acosh;
11906
- Decimal.add = add;
11907
- Decimal.asin = asin;
11908
- Decimal.asinh = asinh;
11909
- Decimal.atan = atan;
11910
- Decimal.atanh = atanh;
11911
- Decimal.atan2 = atan2;
11912
- Decimal.cbrt = cbrt;
11913
- Decimal.ceil = ceil;
11914
- Decimal.clamp = clamp;
11915
- Decimal.cos = cos;
11916
- Decimal.cosh = cosh;
11917
- Decimal.div = div;
11918
- Decimal.exp = exp;
11919
- Decimal.floor = floor;
11920
- Decimal.hypot = hypot;
11921
- Decimal.ln = ln;
11922
- Decimal.log = log;
11923
- Decimal.log10 = log10;
11924
- Decimal.log2 = log2;
11925
- Decimal.max = max;
11926
- Decimal.min = min;
11927
- Decimal.mod = mod;
11928
- Decimal.mul = mul;
11929
- Decimal.pow = pow;
11930
- Decimal.random = random;
11931
- Decimal.round = round;
11932
- Decimal.sign = sign;
11933
- Decimal.sin = sin;
11934
- Decimal.sinh = sinh;
11935
- Decimal.sqrt = sqrt;
11936
- Decimal.sub = sub;
11937
- Decimal.sum = sum;
11938
- Decimal.tan = tan;
11939
- Decimal.tanh = tanh;
11940
- Decimal.trunc = trunc;
11941
- if (obj === undefined)
11942
- obj = {};
11943
- if (obj) {
11944
- if (obj.defaults !== true) {
11945
- ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
11946
- for (i = 0;i < ps.length; )
11947
- if (!obj.hasOwnProperty(p = ps[i++]))
11948
- obj[p] = this[p];
11949
- }
11950
- }
11951
- Decimal.config(obj);
11952
- return Decimal;
11953
- }
11954
- function div(x, y) {
11955
- return new this(x).div(y);
11956
- }
11957
- function exp(x) {
11958
- return new this(x).exp();
11959
- }
11960
- function floor(x) {
11961
- return finalise(x = new this(x), x.e + 1, 3);
11962
- }
11963
- function hypot() {
11964
- var i, n, t = new this(0);
11965
- external2 = false;
11966
- for (i = 0;i < arguments.length; ) {
11967
- n = new this(arguments[i++]);
11968
- if (!n.d) {
11969
- if (n.s) {
11970
- external2 = true;
11971
- return new this(1 / 0);
11972
- }
11973
- t = n;
11974
- } else if (t.d) {
11975
- t = t.plus(n.times(n));
11976
- }
11977
- }
11978
- external2 = true;
11979
- return t.sqrt();
11980
- }
11981
- function isDecimalInstance(obj) {
11982
- return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
11983
- }
11984
- function ln(x) {
11985
- return new this(x).ln();
11986
- }
11987
- function log(x, y) {
11988
- return new this(x).log(y);
11989
- }
11990
- function log2(x) {
11991
- return new this(x).log(2);
11992
- }
11993
- function log10(x) {
11994
- return new this(x).log(10);
11995
- }
11996
- function max() {
11997
- return maxOrMin(this, arguments, -1);
11998
- }
11999
- function min() {
12000
- return maxOrMin(this, arguments, 1);
12001
- }
12002
- function mod(x, y) {
12003
- return new this(x).mod(y);
12004
- }
12005
- function mul(x, y) {
12006
- return new this(x).mul(y);
12007
- }
12008
- function pow(x, y) {
12009
- return new this(x).pow(y);
12010
- }
12011
- function random(sd) {
12012
- var d, e, k, n, i = 0, r = new this(1), rd = [];
12013
- if (sd === undefined)
12014
- sd = this.precision;
12015
- else
12016
- checkInt32(sd, 1, MAX_DIGITS);
12017
- k = Math.ceil(sd / LOG_BASE);
12018
- if (!this.crypto) {
12019
- for (;i < k; )
12020
- rd[i++] = Math.random() * 1e7 | 0;
12021
- } else if (crypto.getRandomValues) {
12022
- d = crypto.getRandomValues(new Uint32Array(k));
12023
- for (;i < k; ) {
12024
- n = d[i];
12025
- if (n >= 4290000000) {
12026
- d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
12027
- } else {
12028
- rd[i++] = n % 1e7;
12029
- }
12030
- }
12031
- } else if (crypto.randomBytes) {
12032
- d = crypto.randomBytes(k *= 4);
12033
- for (;i < k; ) {
12034
- n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
12035
- if (n >= 2140000000) {
12036
- crypto.randomBytes(4).copy(d, i);
12037
- } else {
12038
- rd.push(n % 1e7);
12039
- i += 4;
12040
- }
12041
- }
12042
- i = k / 4;
12043
- } else {
12044
- throw Error(cryptoUnavailable);
12045
- }
12046
- k = rd[--i];
12047
- sd %= LOG_BASE;
12048
- if (k && sd) {
12049
- n = mathpow(10, LOG_BASE - sd);
12050
- rd[i] = (k / n | 0) * n;
12051
- }
12052
- for (;rd[i] === 0; i--)
12053
- rd.pop();
12054
- if (i < 0) {
12055
- e = 0;
12056
- rd = [0];
12057
- } else {
12058
- e = -1;
12059
- for (;rd[0] === 0; e -= LOG_BASE)
12060
- rd.shift();
12061
- for (k = 1, n = rd[0];n >= 10; n /= 10)
12062
- k++;
12063
- if (k < LOG_BASE)
12064
- e -= LOG_BASE - k;
12065
- }
12066
- r.e = e;
12067
- r.d = rd;
12068
- return r;
12069
- }
12070
- function round(x) {
12071
- return finalise(x = new this(x), x.e + 1, this.rounding);
12072
- }
12073
- function sign(x) {
12074
- x = new this(x);
12075
- return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
12076
- }
12077
- function sin(x) {
12078
- return new this(x).sin();
12079
- }
12080
- function sinh(x) {
12081
- return new this(x).sinh();
12082
- }
12083
- function sqrt(x) {
12084
- return new this(x).sqrt();
12085
- }
12086
- function sub(x, y) {
12087
- return new this(x).sub(y);
12088
- }
12089
- function sum() {
12090
- var i = 0, args = arguments, x = new this(args[i]);
12091
- external2 = false;
12092
- for (;x.s && ++i < args.length; )
12093
- x = x.plus(args[i]);
12094
- external2 = true;
12095
- return finalise(x, this.precision, this.rounding);
12096
- }
12097
- function tan(x) {
12098
- return new this(x).tan();
12099
- }
12100
- function tanh(x) {
12101
- return new this(x).tanh();
12102
- }
12103
- function trunc(x) {
12104
- return finalise(x = new this(x), x.e + 1, 1);
12105
- }
12106
- P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
12107
- P[Symbol.toStringTag] = "Decimal";
12108
- var Decimal = P.constructor = clone(DEFAULTS);
12109
- LN10 = new Decimal(LN10);
12110
- PI = new Decimal(PI);
12111
- var decimal_default = Decimal;
12112
-
12113
- // src/common/other.ts
12114
- var delay = (time = 1000) => {
12115
- return new Promise((resolve) => setTimeout(resolve, time));
12116
- };
12117
- var calcJsText = (expr, context) => {
12118
- const keys = Object.keys(context);
12119
- const values = keys.map((key) => context[key]);
12120
- return Function(...keys, `return (${expr})`)(...values);
12121
- };
12122
- var optionsToEnum = (options, text, key) => {
12123
- return options.reduce((acc, cur) => {
12124
- acc[cur[key]] = {
12125
- text: cur[text]
12126
- };
12127
- return acc;
12128
- }, {});
12129
- };
12130
- var performDecimalOperation = (num1, num2, operator) => {
12131
- if (num1 === undefined || num2 === undefined || !operator) {
12132
- return;
12133
- }
12134
- const decimalNum1 = new decimal_default(Number(num1));
12135
- const decimalNum2 = new decimal_default(Number(num2));
12136
- switch (operator) {
12137
- case "+":
12138
- return decimalNum1.plus(decimalNum2).toNumber();
12139
- case "-":
12140
- return decimalNum1.minus(decimalNum2).toNumber();
12141
- case "*":
12142
- return decimalNum1.times(decimalNum2).toNumber();
12143
- case "/":
12144
- if (num2 !== 0) {
12145
- return decimalNum1.dividedBy(decimalNum2).toNumber();
12146
- } else {
12147
- console.error("Division by zero is not allowed.");
12148
- return NaN;
12149
- }
12150
- default:
12151
- console.error("Invalid operator:", operator);
12152
- return NaN;
12153
- }
12154
- };
12155
- var printConsoleLog = (type, path, params, response) => {
12156
- const styles = {
12157
- header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
12158
- value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
12159
- separator: "color: #409EFF; margin: 0 4px;"
12160
- };
12161
- console.groupCollapsed(`666 %c${type}%c${path}`, styles.header, styles.value);
12162
- if (params) {
12163
- console.table(params);
12164
- }
12165
- if (response) {
12166
- console.table(response);
12167
- }
12168
- console.groupEnd();
12169
- };
12170
- // src/common/number.ts
12171
- var getRandomNum = (min2, max2) => {
12172
- return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
12173
- };
12174
- var limitDecimals = (v, num = 2, isForce) => {
12175
- let value = parseFloat(v);
12176
- if (isNaN(value)) {
12177
- if (isForce) {
12178
- value = 0;
12179
- } else {
12180
- return "";
12181
- }
12182
- }
12183
- return value.toFixed(num).toString();
12184
- };
12185
- var getFileSize = (size) => {
12186
- let d = "G";
12187
- let s = size / 1024 / 1024 / 1024;
12188
- if (s < 1) {
12189
- d = "M";
12190
- s *= 1024;
12191
- }
12192
- return `${(s.toFixed(1) / 1).toString()}${d}`;
12193
- };
12194
- var isValidNumber = (value) => {
12195
- if (typeof value !== "number") {
12196
- return false;
12197
- }
12198
- if (isNaN(value)) {
12199
- return false;
12200
- }
12201
- if (value === Infinity || value === -Infinity) {
12202
- return false;
12203
- }
12204
- return true;
12205
- };
12206
- var numberWithCommas = (x) => {
12207
- if (x === undefined || x === null) {
12208
- return "";
12209
- }
12210
- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
12211
- };
12212
- // src/common/array.ts
12213
- var shuffleArray = (array) => {
12214
- const shuffledArray = [...array];
12215
- for (let i = shuffledArray.length - 1;i > 0; i--) {
12216
- const j = Math.floor(Math.random() * (i + 1));
12217
- [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
12218
- }
12219
- return shuffledArray;
12220
- };
12221
- var removeSimilarDuplicates = (arr, threshold, isLog) => {
12222
- const uniqueArray = [];
12223
- const similarPairs = [];
12224
- for (const str of arr) {
12225
- const isSimilar = uniqueArray.some((uniqueStr) => {
12226
- const distance = levenshteinDistance(str, uniqueStr);
12227
- if (distance <= threshold) {
12228
- similarPairs.push([str, uniqueStr]);
12229
- return true;
12230
- }
12231
- return false;
12232
- });
12233
- if (!isSimilar) {
12234
- uniqueArray.push(str);
12235
- }
12236
- }
12237
- if (isLog) {
12238
- if (similarPairs.length > 0) {
12239
- similarPairs.forEach((pair) => {
12240
- console.log(pair[0]);
12241
- console.log(pair[1]);
12242
- console.log();
12243
- });
12244
- } else {
12245
- console.log("没有找到类似的字符串");
12246
- }
12247
- }
12248
- return uniqueArray;
12249
- };
12250
- var getTotal = (arr, key) => {
12251
- if (!Array.isArray(arr) || !key) {
12252
- return 0;
12253
- }
12254
- return arr.reduce((total, item) => {
12255
- const itemValue = Number(item[key]);
12256
- if (!isNaN(itemValue)) {
12257
- return performDecimalOperation(total, itemValue, "+");
12258
- }
12259
- return total;
12260
- }, 0);
12261
- };
12262
- // src/common/image.ts
12263
- var import_axios = __toESM(require("axios"));
12264
- async function imageToBase64(url) {
12265
- try {
12266
- const response = await import_axios.default.get(url, {
12267
- responseType: "arraybuffer"
12268
- });
12269
- const base64String = Buffer.from(response.data).toString("base64");
12270
- return `data:image/*;base64,${base64String}`;
12271
- } catch (error) {
12272
- console.error("Failed to fetch the image:", error);
12273
- throw error;
12274
- }
12275
- }
12276
- // src/common/enum.ts
12277
- class EnumItem {
12278
- label;
12279
- value;
12280
- extra;
12281
- constructor(config2) {
12282
- this.value = config2.value;
12283
- this.label = config2.label;
12284
- this.extra = config2.extra;
9841
+ // src/common/enum.ts
9842
+ class EnumItem {
9843
+ label;
9844
+ value;
9845
+ extra;
9846
+ constructor(config) {
9847
+ this.value = config.value;
9848
+ this.label = config.label;
9849
+ this.extra = config.extra;
12285
9850
  }
12286
9851
  }
12287
9852
  var Enum = {
@@ -12293,8 +9858,8 @@ var Enum = {
12293
9858
  const extras = new Map;
12294
9859
  const labels = new Map;
12295
9860
  const enums = {};
12296
- for (const key in members) {
12297
- const member = members[key];
9861
+ for (const key2 in members) {
9862
+ const member = members[key2];
12298
9863
  if (!member)
12299
9864
  continue;
12300
9865
  if (usedValues.has(member.value)) {
@@ -12302,7 +9867,7 @@ var Enum = {
12302
9867
  }
12303
9868
  usedValues.add(member.value);
12304
9869
  const item = new EnumItem(member);
12305
- enumObj[key] = item;
9870
+ enumObj[key2] = item;
12306
9871
  map.set(item.value, item);
12307
9872
  labels.set(item.value, item.label);
12308
9873
  options.push(item);
@@ -12360,51 +9925,7 @@ var initChinaDayjs = () => {
12360
9925
  };
12361
9926
  var chinaDayjs = initChinaDayjs();
12362
9927
  var dayjs_default = import_dayjs.default;
12363
- // src/ai/302/index.ts
12364
- var exports_302 = {};
12365
- __export(exports_302, {
12366
- chat: () => chat
12367
- });
12368
-
12369
- // src/ai/302/axios.ts
12370
- var import_axios3 = __toESM(require("axios"));
12371
- var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
12372
- var axios2 = import_axios3.default.create({
12373
- baseURL: "https://api.302.ai",
12374
- headers: {
12375
- "mj-api-secret": key,
12376
- Authorization: `Bearer ${key}`
12377
- }
12378
- });
12379
-
12380
- // src/ai/302/chat/index.ts
12381
- var import_json52 = __toESM(require("json5"));
12382
- var chat = async (message, model = "gpt-4.1", isParse = true) => {
12383
- try {
12384
- let { data } = await axios2({
12385
- url: "/v1/chat/completions",
12386
- method: "post",
12387
- data: {
12388
- model,
12389
- message
12390
- }
12391
- });
12392
- console.log(666, typeof data, data);
12393
- const output = typeof data === "string" ? import_json52.default.parse(data)?.output : data?.output;
12394
- if (isParse) {
12395
- const match = /```(json)?(.*)```/s.exec(output);
12396
- if (!match) {
12397
- return import_json52.default.parse(output);
12398
- } else {
12399
- return import_json52.default.parse(match[2]);
12400
- }
12401
- }
12402
- return output;
12403
- } catch (error) {
12404
- throw new Error(error?.response?.statusText || error?.message || "未知原因");
12405
- }
12406
- };
12407
- // src/node/mail/index.ts
9928
+ // src/node/mail.ts
12408
9929
  var import_nodemailer = __toESM(require("nodemailer"));
12409
9930
  var authMap = {
12410
9931
  163: {
@@ -12422,17 +9943,17 @@ var transporter = import_nodemailer.default.createTransport({
12422
9943
  secure: true,
12423
9944
  auth: authMap.gmail
12424
9945
  });
12425
- var sendMail = (config2) => {
9946
+ var sendMail = (config) => {
12426
9947
  return transporter.sendMail({
12427
9948
  from: authMap.gmail.user,
12428
- ...config2
9949
+ ...config
12429
9950
  });
12430
9951
  };
12431
- // src/node/file/index.ts
9952
+ // src/node/file.ts
12432
9953
  var import_fs_extra = __toESM(require("fs-extra"));
12433
- var import_axios5 = __toESM(require("axios"));
9954
+ var import_axios7 = __toESM(require("axios"));
12434
9955
  var import_url = __toESM(require("url"));
12435
- var path = __toESM(require("path"));
9956
+ var path2 = __toESM(require("path"));
12436
9957
  var replaceContentInFile = async (filePath, targetContent, replacement) => {
12437
9958
  try {
12438
9959
  const data = await import_fs_extra.default.readFile(filePath, "utf8");
@@ -12455,14 +9976,14 @@ var replaceContentInFile = async (filePath, targetContent, replacement) => {
12455
9976
  var downloadFile = async (httpUrl, outputPath) => {
12456
9977
  try {
12457
9978
  let parsedUrl = import_url.default.parse(httpUrl);
12458
- let fileName = path.basename(parsedUrl.pathname);
9979
+ let fileName = path2.basename(parsedUrl.pathname);
12459
9980
  if (!outputPath) {
12460
9981
  if (!import_fs_extra.default.existsSync(".tmp")) {
12461
9982
  import_fs_extra.default.mkdirSync(".tmp", { recursive: true });
12462
9983
  }
12463
9984
  outputPath = ".tmp/" + decodeURIComponent(fileName);
12464
9985
  }
12465
- const response = await import_axios5.default({
9986
+ const response = await import_axios7.default({
12466
9987
  url: httpUrl,
12467
9988
  method: "get",
12468
9989
  responseType: "stream"
@@ -12479,11 +10000,11 @@ var downloadFile = async (httpUrl, outputPath) => {
12479
10000
  throw error;
12480
10001
  }
12481
10002
  };
12482
- // src/node/oss/index.ts
10003
+ // src/node/oss.ts
12483
10004
  var import_ali_oss = __toESM(require("ali-oss"));
12484
- var import_axios6 = __toESM(require("axios"));
10005
+ var import_axios8 = __toESM(require("axios"));
12485
10006
  var import_fs_extra2 = __toESM(require("fs-extra"));
12486
- var path2 = __toESM(require("path"));
10007
+ var path3 = __toESM(require("path"));
12487
10008
  var oss = new import_ali_oss.default({
12488
10009
  region: process.env.VITE_OSS_REGION,
12489
10010
  accessKeyId: process.env.VITE_OSS_ACCESS_KEY_ID,
@@ -12496,14 +10017,14 @@ async function uploadFile(file, filename) {
12496
10017
  if (typeof file === "string") {
12497
10018
  if (/^https?:\/\//.test(file)) {
12498
10019
  try {
12499
- const response = await import_axios6.default.get(file, { responseType: "arraybuffer" });
10020
+ const response = await import_axios8.default.get(file, { responseType: "arraybuffer" });
12500
10021
  buffer = Buffer.from(response.data);
12501
10022
  } catch (error) {
12502
10023
  throw new Error(`无法从 URL 下载文件: ${error}`);
12503
10024
  }
12504
- const originalName = path2.basename(new URL(file).pathname);
12505
- const ext = path2.extname(originalName);
12506
- const nameWithoutExt = path2.basename(originalName, ext);
10025
+ const originalName = path3.basename(new URL(file).pathname);
10026
+ const ext = path3.extname(originalName);
10027
+ const nameWithoutExt = path3.basename(originalName, ext);
12507
10028
  finalFilename = `${nameWithoutExt}_${Date.now()}${ext}`;
12508
10029
  } else {
12509
10030
  try {
@@ -12511,9 +10032,9 @@ async function uploadFile(file, filename) {
12511
10032
  } catch (error) {
12512
10033
  throw new Error(`无法读取文件路径: ${error}`);
12513
10034
  }
12514
- const originalName = path2.basename(file);
12515
- const ext = path2.extname(originalName);
12516
- const nameWithoutExt = path2.basename(originalName, ext);
10035
+ const originalName = path3.basename(file);
10036
+ const ext = path3.extname(originalName);
10037
+ const nameWithoutExt = path3.basename(originalName, ext);
12517
10038
  finalFilename = `${nameWithoutExt}_${Date.now()}${ext}`;
12518
10039
  }
12519
10040
  } else if (Buffer.isBuffer(file)) {
@@ -12536,7 +10057,7 @@ async function uploadFile(file, filename) {
12536
10057
  throw new Error(`上传到 OSS 失败: ${error}`);
12537
10058
  }
12538
10059
  }
12539
- // src/node/cron/index.ts
10060
+ // src/node/cron.ts
12540
10061
  var import_node_cron = __toESM(require("node-cron"));
12541
10062
  var interval = (intervalMinutes, immediately, fn) => {
12542
10063
  console.log(`定时任务已启动,将每${intervalMinutes}分钟执行一次`);
@@ -12558,7 +10079,3 @@ var schedule = (cronExpression, immediately, fn) => {
12558
10079
  timezone: "Asia/Shanghai"
12559
10080
  });
12560
10081
  };
12561
-
12562
- // src/node/index.ts
12563
- var import_nedb = __toESM(require("nedb"));
12564
- var cheerio = __toESM(require("cheerio"));