@wzyjs/utils 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/ai/302/audio/doubao.d.ts +29 -0
- package/dist/common/ai/302/audio/index.d.ts +2 -0
- package/dist/common/ai/302/audio/tts.d.ts +51 -0
- package/dist/common/ai/302/image/gpt.d.ts +97 -0
- package/dist/{ai → common/ai}/302/image/index.d.ts +1 -0
- package/dist/common/ai/302/index.d.ts +3 -0
- package/dist/common/ai/doubao/index.d.ts +2 -0
- package/dist/common/ai/doubao/tts.d.ts +30 -0
- package/dist/common/ai/doubao/vc.d.ts +21 -0
- package/dist/common/base/index.d.ts +6 -0
- package/dist/common/index.d.ts +5 -11
- package/dist/node.cjs.js +838 -190
- package/dist/node.d.ts +11 -2
- package/dist/node.esm.js +844 -194
- package/dist/{browser.cjs.js → web.cjs.js} +20887 -19828
- package/dist/web.d.ts +15 -0
- package/dist/{browser.esm.js → web.esm.js} +20394 -19333
- package/package.json +14 -14
- package/dist/ai/302/index.d.ts +0 -1
- package/dist/ai/index.d.ts +0 -1
- package/dist/ai/midjourney/index.d.ts +0 -1
- package/dist/ai/midjourney/utils.d.ts +0 -12
- package/dist/browser/index.d.ts +0 -10
- package/dist/browser.d.ts +0 -2
- package/dist/node/index.d.ts +0 -6
- /package/dist/{ai → common/ai}/302/axios.d.ts +0 -0
- /package/dist/{ai → common/ai}/302/chat/index.d.ts +0 -0
- /package/dist/{ai → common/ai}/302/image/midjourney.d.ts +0 -0
- /package/dist/{ai → common/ai}/keling/axios.d.ts +0 -0
- /package/dist/{ai → common/ai}/keling/index.d.ts +0 -0
- /package/dist/{ai → common/ai}/keling/utils.d.ts +0 -0
- /package/dist/common/{array.d.ts → base/array.d.ts} +0 -0
- /package/dist/common/{number.d.ts → base/number.d.ts} +0 -0
- /package/dist/common/{object.d.ts → base/object.d.ts} +0 -0
- /package/dist/common/{other.d.ts → base/other.d.ts} +0 -0
- /package/dist/common/{promise.d.ts → base/promise.d.ts} +0 -0
- /package/dist/common/{string.d.ts → base/string.d.ts} +0 -0
- /package/dist/node/{cron/index.d.ts → cron.d.ts} +0 -0
- /package/dist/node/{file/index.d.ts → file.d.ts} +0 -0
- /package/dist/node/{mail/index.d.ts → mail.d.ts} +0 -0
- /package/dist/node/{oss/index.d.ts → oss.d.ts} +0 -0
- /package/dist/{common → web}/antd.d.ts +0 -0
- /package/dist/{browser/other.d.ts → web/clipboard.d.ts} +0 -0
- /package/dist/{browser → web}/download.d.ts +0 -0
- /package/dist/{browser → web}/element.d.ts +0 -0
- /package/dist/{browser → web}/location.d.ts +0 -0
- /package/dist/{browser → web}/style.d.ts +0 -0
package/dist/node.cjs.js
CHANGED
|
@@ -738,7 +738,7 @@ var require_lodash = __commonJS((exports2, module2) => {
|
|
|
738
738
|
var objectCtorString = funcToString.call(Object2);
|
|
739
739
|
var oldDash = root._;
|
|
740
740
|
var reIsNative = RegExp2("^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$");
|
|
741
|
-
var Buffer2 = moduleExports ? context.Buffer : undefined2, Symbol2 = context.Symbol,
|
|
741
|
+
var Buffer2 = moduleExports ? context.Buffer : undefined2, Symbol2 = context.Symbol, Uint8Array2 = context.Uint8Array, allocUnsafe = Buffer2 ? Buffer2.allocUnsafe : undefined2, getPrototype = overArg(Object2.getPrototypeOf, Object2), objectCreate = Object2.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, splice = arrayProto.splice, spreadableSymbol = Symbol2 ? Symbol2.isConcatSpreadable : undefined2, symIterator = Symbol2 ? Symbol2.iterator : undefined2, symToStringTag = Symbol2 ? Symbol2.toStringTag : undefined2;
|
|
742
742
|
var defineProperty = function() {
|
|
743
743
|
try {
|
|
744
744
|
var func = getNative(Object2, "defineProperty");
|
|
@@ -1996,7 +1996,7 @@ var require_lodash = __commonJS((exports2, module2) => {
|
|
|
1996
1996
|
}
|
|
1997
1997
|
function cloneArrayBuffer(arrayBuffer) {
|
|
1998
1998
|
var result2 = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
|
1999
|
-
new
|
|
1999
|
+
new Uint8Array2(result2).set(new Uint8Array2(arrayBuffer));
|
|
2000
2000
|
return result2;
|
|
2001
2001
|
}
|
|
2002
2002
|
function cloneDataView(dataView, isDeep) {
|
|
@@ -2578,7 +2578,7 @@ var require_lodash = __commonJS((exports2, module2) => {
|
|
|
2578
2578
|
object = object.buffer;
|
|
2579
2579
|
other = other.buffer;
|
|
2580
2580
|
case arrayBufferTag:
|
|
2581
|
-
if (object.byteLength != other.byteLength || !equalFunc(new
|
|
2581
|
+
if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array2(object), new Uint8Array2(other))) {
|
|
2582
2582
|
return false;
|
|
2583
2583
|
}
|
|
2584
2584
|
return true;
|
|
@@ -5478,6 +5478,7 @@ __export(exports_node, {
|
|
|
5478
5478
|
set: () => setType,
|
|
5479
5479
|
sendMail: () => sendMail,
|
|
5480
5480
|
schedule: () => schedule,
|
|
5481
|
+
retryPromise: () => retryPromise,
|
|
5481
5482
|
replaceContentInFile: () => replaceContentInFile,
|
|
5482
5483
|
replaceByVariables: () => replaceByVariables,
|
|
5483
5484
|
replaceByRules: () => replaceByRules,
|
|
@@ -5511,8 +5512,9 @@ __export(exports_node, {
|
|
|
5511
5512
|
levenshteinDistance: () => levenshteinDistance,
|
|
5512
5513
|
lazy: () => lazyType,
|
|
5513
5514
|
late: () => late,
|
|
5515
|
+
keling: () => exports_keling,
|
|
5514
5516
|
jsonParse: () => jsonParse,
|
|
5515
|
-
json5: () =>
|
|
5517
|
+
json5: () => import_json52.default,
|
|
5516
5518
|
isValidNumber: () => isValidNumber,
|
|
5517
5519
|
isValid: () => isValid,
|
|
5518
5520
|
isJson: () => isJson,
|
|
@@ -5544,9 +5546,11 @@ __export(exports_node, {
|
|
|
5544
5546
|
function: () => functionType,
|
|
5545
5547
|
findItem: () => findItem,
|
|
5546
5548
|
filterParams: () => filterParams,
|
|
5549
|
+
executePromise: () => executePromise,
|
|
5547
5550
|
enum: () => enumType,
|
|
5548
5551
|
effect: () => effectsType,
|
|
5549
5552
|
downloadFile: () => downloadFile,
|
|
5553
|
+
doubao: () => exports_doubao2,
|
|
5550
5554
|
discriminatedUnion: () => discriminatedUnionType,
|
|
5551
5555
|
delay: () => delay,
|
|
5552
5556
|
defaultErrorMap: () => en_default,
|
|
@@ -5561,7 +5565,7 @@ __export(exports_node, {
|
|
|
5561
5565
|
calcJsText: () => calcJsText,
|
|
5562
5566
|
boolean: () => booleanType,
|
|
5563
5567
|
bigint: () => bigIntType,
|
|
5564
|
-
axios: () =>
|
|
5568
|
+
axios: () => import_axios15.default,
|
|
5565
5569
|
array: () => arrayType,
|
|
5566
5570
|
any: () => anyType,
|
|
5567
5571
|
amount: () => amount,
|
|
@@ -5626,11 +5630,11 @@ __export(exports_node, {
|
|
|
5626
5630
|
BRAND: () => BRAND
|
|
5627
5631
|
});
|
|
5628
5632
|
module.exports = __toCommonJS(exports_node);
|
|
5629
|
-
|
|
5630
|
-
|
|
5633
|
+
var import_nedb = __toESM(require("nedb"));
|
|
5634
|
+
var cheerio = __toESM(require("cheerio"));
|
|
5631
5635
|
var import_lodash = __toESM(require_lodash());
|
|
5632
|
-
var
|
|
5633
|
-
var
|
|
5636
|
+
var import_axios15 = __toESM(require("axios"));
|
|
5637
|
+
var import_json52 = __toESM(require("json5"));
|
|
5634
5638
|
var import_consola = __toESM(require("consola"));
|
|
5635
5639
|
|
|
5636
5640
|
// ../../node_modules/zod/v3/external.js
|
|
@@ -9606,7 +9610,673 @@ var coerce = {
|
|
|
9606
9610
|
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
9607
9611
|
};
|
|
9608
9612
|
var NEVER = INVALID;
|
|
9609
|
-
// src/common/
|
|
9613
|
+
// src/common/ai/302/index.ts
|
|
9614
|
+
var exports_302 = {};
|
|
9615
|
+
__export(exports_302, {
|
|
9616
|
+
image: () => exports_image,
|
|
9617
|
+
chat: () => chat,
|
|
9618
|
+
audio: () => exports_audio
|
|
9619
|
+
});
|
|
9620
|
+
|
|
9621
|
+
// src/common/ai/302/axios.ts
|
|
9622
|
+
var import_axios = __toESM(require("axios"));
|
|
9623
|
+
var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
|
|
9624
|
+
var axios = import_axios.default.create({
|
|
9625
|
+
baseURL: "https://api.302.ai",
|
|
9626
|
+
headers: {
|
|
9627
|
+
"mj-api-secret": key,
|
|
9628
|
+
Authorization: `Bearer ${key}`
|
|
9629
|
+
}
|
|
9630
|
+
});
|
|
9631
|
+
|
|
9632
|
+
// src/common/ai/302/chat/index.ts
|
|
9633
|
+
var import_json5 = __toESM(require("json5"));
|
|
9634
|
+
var chat = async (message, model = "gpt-4.1", isParse = true) => {
|
|
9635
|
+
try {
|
|
9636
|
+
let { data } = await axios({
|
|
9637
|
+
url: "/v1/chat/completions",
|
|
9638
|
+
method: "post",
|
|
9639
|
+
data: {
|
|
9640
|
+
model,
|
|
9641
|
+
message
|
|
9642
|
+
}
|
|
9643
|
+
});
|
|
9644
|
+
console.log(666, "302 chat res", typeof data, data);
|
|
9645
|
+
const output = typeof data === "string" ? import_json5.default.parse(data)?.output : data?.output;
|
|
9646
|
+
if (isParse) {
|
|
9647
|
+
const match = /```(json)?(.*)```/s.exec(output);
|
|
9648
|
+
if (!match) {
|
|
9649
|
+
return import_json5.default.parse(output);
|
|
9650
|
+
} else {
|
|
9651
|
+
return import_json5.default.parse(match[2]);
|
|
9652
|
+
}
|
|
9653
|
+
}
|
|
9654
|
+
return output;
|
|
9655
|
+
} catch (error) {
|
|
9656
|
+
const responseData = error?.response?.data;
|
|
9657
|
+
const message2 = responseData?.error?.message_cn || responseData?.error?.message || responseData?.message || error?.response?.statusText || error?.message || "未知原因";
|
|
9658
|
+
throw new Error(message2);
|
|
9659
|
+
}
|
|
9660
|
+
};
|
|
9661
|
+
// src/common/ai/302/audio/index.ts
|
|
9662
|
+
var exports_audio = {};
|
|
9663
|
+
__export(exports_audio, {
|
|
9664
|
+
tts: () => exports_tts,
|
|
9665
|
+
doubao: () => exports_doubao
|
|
9666
|
+
});
|
|
9667
|
+
|
|
9668
|
+
// src/common/ai/302/audio/tts.ts
|
|
9669
|
+
var exports_tts = {};
|
|
9670
|
+
__export(exports_tts, {
|
|
9671
|
+
textToSpeech: () => textToSpeech,
|
|
9672
|
+
fetchTask: () => fetchTask,
|
|
9673
|
+
fetchProviders: () => fetchProviders
|
|
9674
|
+
});
|
|
9675
|
+
var fetchProviders = async () => {
|
|
9676
|
+
try {
|
|
9677
|
+
const { data } = await axios({
|
|
9678
|
+
url: "/302/tts/provider",
|
|
9679
|
+
method: "get"
|
|
9680
|
+
});
|
|
9681
|
+
return data;
|
|
9682
|
+
} catch (error) {
|
|
9683
|
+
throw error;
|
|
9684
|
+
}
|
|
9685
|
+
};
|
|
9686
|
+
var textToSpeech = async (request) => {
|
|
9687
|
+
try {
|
|
9688
|
+
const { webhook, run_async, ...body } = request;
|
|
9689
|
+
const { data } = await axios({
|
|
9690
|
+
url: "/302/v2/audio/tts",
|
|
9691
|
+
method: "post",
|
|
9692
|
+
params: {
|
|
9693
|
+
webhook,
|
|
9694
|
+
run_async
|
|
9695
|
+
},
|
|
9696
|
+
data: {
|
|
9697
|
+
...body,
|
|
9698
|
+
speed: body.speed ?? 1,
|
|
9699
|
+
volume: body.volume ?? 1,
|
|
9700
|
+
timeout: body.timeout ?? 180
|
|
9701
|
+
}
|
|
9702
|
+
});
|
|
9703
|
+
return data;
|
|
9704
|
+
} catch (error) {
|
|
9705
|
+
throw error;
|
|
9706
|
+
}
|
|
9707
|
+
};
|
|
9708
|
+
var fetchTask = async (taskId) => {
|
|
9709
|
+
if (!taskId) {
|
|
9710
|
+
throw new Error("taskId 不能为空");
|
|
9711
|
+
}
|
|
9712
|
+
try {
|
|
9713
|
+
const { data } = await axios({
|
|
9714
|
+
url: `/302/v2/audio/fetch/${encodeURIComponent(taskId)}`,
|
|
9715
|
+
method: "get"
|
|
9716
|
+
});
|
|
9717
|
+
return data;
|
|
9718
|
+
} catch (error) {
|
|
9719
|
+
throw error;
|
|
9720
|
+
}
|
|
9721
|
+
};
|
|
9722
|
+
// src/common/ai/302/audio/doubao.ts
|
|
9723
|
+
var exports_doubao = {};
|
|
9724
|
+
__export(exports_doubao, {
|
|
9725
|
+
ttsHd: () => ttsHd
|
|
9726
|
+
});
|
|
9727
|
+
var createReqid = () => {
|
|
9728
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
9729
|
+
return crypto.randomUUID();
|
|
9730
|
+
}
|
|
9731
|
+
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
9732
|
+
};
|
|
9733
|
+
var getUtf8ByteLength = (value) => {
|
|
9734
|
+
return new TextEncoder().encode(value).length;
|
|
9735
|
+
};
|
|
9736
|
+
var assertNonEmptyString = (value, label) => {
|
|
9737
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
9738
|
+
throw new Error(`${label} 不能为空`);
|
|
9739
|
+
}
|
|
9740
|
+
};
|
|
9741
|
+
var assertSpeedRatio = (value) => {
|
|
9742
|
+
if (value === undefined)
|
|
9743
|
+
return;
|
|
9744
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
9745
|
+
throw new Error("speed_ratio 必须为数字");
|
|
9746
|
+
}
|
|
9747
|
+
if (value < 0.8 || value > 2) {
|
|
9748
|
+
throw new Error("speed_ratio 取值范围为 [0.8, 2]");
|
|
9749
|
+
}
|
|
9750
|
+
};
|
|
9751
|
+
var ttsHd = async (payload) => {
|
|
9752
|
+
const { audio, request } = payload;
|
|
9753
|
+
const { voice_type, encoding, speed_ratio } = audio;
|
|
9754
|
+
const { text, reqid: rawReqid, operation } = request;
|
|
9755
|
+
assertNonEmptyString(voice_type, "voice_type");
|
|
9756
|
+
assertNonEmptyString(text, "text");
|
|
9757
|
+
assertSpeedRatio(speed_ratio);
|
|
9758
|
+
const textByteLength = getUtf8ByteLength(text);
|
|
9759
|
+
if (textByteLength > 1024) {
|
|
9760
|
+
throw new Error(`text 超出长度限制:${textByteLength}/1024 字节`);
|
|
9761
|
+
}
|
|
9762
|
+
const reqid = rawReqid?.trim() || createReqid();
|
|
9763
|
+
const { data } = await axios({
|
|
9764
|
+
url: "/doubao/tts_hd",
|
|
9765
|
+
method: "post",
|
|
9766
|
+
data: {
|
|
9767
|
+
audio: {
|
|
9768
|
+
voice_type,
|
|
9769
|
+
encoding: encoding ?? "pcm",
|
|
9770
|
+
speed_ratio: speed_ratio ?? 1
|
|
9771
|
+
},
|
|
9772
|
+
request: {
|
|
9773
|
+
reqid,
|
|
9774
|
+
text,
|
|
9775
|
+
operation: operation ?? "query"
|
|
9776
|
+
}
|
|
9777
|
+
}
|
|
9778
|
+
});
|
|
9779
|
+
return data;
|
|
9780
|
+
};
|
|
9781
|
+
// src/common/ai/302/image/index.ts
|
|
9782
|
+
var exports_image = {};
|
|
9783
|
+
__export(exports_image, {
|
|
9784
|
+
midjourney: () => exports_midjourney,
|
|
9785
|
+
gpt: () => exports_gpt
|
|
9786
|
+
});
|
|
9787
|
+
|
|
9788
|
+
// src/common/ai/302/image/midjourney.ts
|
|
9789
|
+
var exports_midjourney = {};
|
|
9790
|
+
__export(exports_midjourney, {
|
|
9791
|
+
getImageStatus: () => getImageStatus,
|
|
9792
|
+
generateImage: () => generateImage
|
|
9793
|
+
});
|
|
9794
|
+
var generateImage = async (prompt, base64Array) => {
|
|
9795
|
+
try {
|
|
9796
|
+
const { data } = await axios({
|
|
9797
|
+
url: "/mj/submit/imagine",
|
|
9798
|
+
method: "post",
|
|
9799
|
+
data: {
|
|
9800
|
+
prompt,
|
|
9801
|
+
base64Array,
|
|
9802
|
+
botType: "MID_JOURNEY",
|
|
9803
|
+
notifyHook: "",
|
|
9804
|
+
state: ""
|
|
9805
|
+
}
|
|
9806
|
+
});
|
|
9807
|
+
return data;
|
|
9808
|
+
} catch (error) {
|
|
9809
|
+
throw error;
|
|
9810
|
+
}
|
|
9811
|
+
};
|
|
9812
|
+
var getImageStatus = async (taskId) => {
|
|
9813
|
+
try {
|
|
9814
|
+
const { data } = await axios({
|
|
9815
|
+
url: `/mj/task/${taskId}/fetch`,
|
|
9816
|
+
method: "get"
|
|
9817
|
+
});
|
|
9818
|
+
return data;
|
|
9819
|
+
} catch (error) {
|
|
9820
|
+
throw error;
|
|
9821
|
+
}
|
|
9822
|
+
};
|
|
9823
|
+
// src/common/ai/302/image/gpt.ts
|
|
9824
|
+
var exports_gpt = {};
|
|
9825
|
+
__export(exports_gpt, {
|
|
9826
|
+
generateImage: () => generateImage2
|
|
9827
|
+
});
|
|
9828
|
+
var generateImage2 = async (params) => {
|
|
9829
|
+
if (params.model === "gpt-4o-plus") {
|
|
9830
|
+
const { data: data2 } = await axios.post("/v1/chat/completions", {
|
|
9831
|
+
model: params.model,
|
|
9832
|
+
messages: [{ role: "user", content: params.prompt }]
|
|
9833
|
+
});
|
|
9834
|
+
const content = data2?.choices?.[0]?.message?.content || "";
|
|
9835
|
+
const urlMatch = content.match(/!\[.*?\]\((.*?)\)/) || content.match(/(https?:\/\/[^\s]+)/);
|
|
9836
|
+
const url = urlMatch ? urlMatch[1] : content;
|
|
9837
|
+
return {
|
|
9838
|
+
background: "",
|
|
9839
|
+
created: data2.created,
|
|
9840
|
+
data: [{ url }],
|
|
9841
|
+
output_format: "",
|
|
9842
|
+
quality: "",
|
|
9843
|
+
size: "",
|
|
9844
|
+
usage: {
|
|
9845
|
+
input_tokens: data2.usage?.prompt_tokens || 0,
|
|
9846
|
+
input_tokens_details: {
|
|
9847
|
+
image_tokens: data2.usage?.prompt_tokens_details?.image_tokens || 0,
|
|
9848
|
+
text_tokens: data2.usage?.prompt_tokens_details?.text_tokens || 0
|
|
9849
|
+
},
|
|
9850
|
+
output_tokens: data2.usage?.completion_tokens || 0,
|
|
9851
|
+
output_tokens_details: {
|
|
9852
|
+
image_tokens: data2.usage?.completion_tokens_details?.image_tokens || 0,
|
|
9853
|
+
text_tokens: data2.usage?.completion_tokens_details?.content_tokens || 0
|
|
9854
|
+
},
|
|
9855
|
+
total_tokens: data2.usage?.total_tokens || 0
|
|
9856
|
+
}
|
|
9857
|
+
};
|
|
9858
|
+
}
|
|
9859
|
+
const { data } = await axios.post("/v1/images/generations", params);
|
|
9860
|
+
return data;
|
|
9861
|
+
};
|
|
9862
|
+
// src/common/ai/doubao/index.ts
|
|
9863
|
+
var exports_doubao2 = {};
|
|
9864
|
+
__export(exports_doubao2, {
|
|
9865
|
+
vc: () => vc,
|
|
9866
|
+
tts: () => tts
|
|
9867
|
+
});
|
|
9868
|
+
|
|
9869
|
+
// src/common/ai/doubao/tts.ts
|
|
9870
|
+
var import_axios7 = __toESM(require("axios"));
|
|
9871
|
+
var createReqid2 = () => {
|
|
9872
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
9873
|
+
return crypto.randomUUID();
|
|
9874
|
+
}
|
|
9875
|
+
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
9876
|
+
};
|
|
9877
|
+
var decodeBase64ToArrayBuffer = (value) => {
|
|
9878
|
+
if (typeof window !== "undefined" && typeof window.atob === "function") {
|
|
9879
|
+
const binary = window.atob(value);
|
|
9880
|
+
const bytes = new Uint8Array(binary.length);
|
|
9881
|
+
for (let i = 0;i < binary.length; i++) {
|
|
9882
|
+
bytes[i] = binary.charCodeAt(i);
|
|
9883
|
+
}
|
|
9884
|
+
return bytes.buffer;
|
|
9885
|
+
}
|
|
9886
|
+
const buf = Buffer.from(value, "base64");
|
|
9887
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
9888
|
+
};
|
|
9889
|
+
var tts = async (params) => {
|
|
9890
|
+
const { app, user, audio, request } = params;
|
|
9891
|
+
const url = "https://openspeech.bytedance.com/api/v3/tts/unidirectional";
|
|
9892
|
+
const reqid = request.reqid || createReqid2();
|
|
9893
|
+
const speechRate = audio.speed_ratio ? Math.round((audio.speed_ratio - 1) * 100) : 0;
|
|
9894
|
+
const loudnessRate = audio.volume_ratio ? Math.round((audio.volume_ratio - 1) * 100) : 0;
|
|
9895
|
+
const headers = {
|
|
9896
|
+
"X-Api-App-Id": app.appid || "",
|
|
9897
|
+
"X-Api-Access-Key": app.accessToken || "",
|
|
9898
|
+
"Content-Type": "application/json",
|
|
9899
|
+
"X-Api-Resource-Id": app.resourceId || "seed-tts-2.0",
|
|
9900
|
+
"X-Api-Request-Id": reqid
|
|
9901
|
+
};
|
|
9902
|
+
const payload = {
|
|
9903
|
+
user: {
|
|
9904
|
+
uid: user?.uid || "uid"
|
|
9905
|
+
},
|
|
9906
|
+
req_params: {
|
|
9907
|
+
text: request.text,
|
|
9908
|
+
speaker: audio.voice_type,
|
|
9909
|
+
audio_params: {
|
|
9910
|
+
format: audio.encoding || "pcm",
|
|
9911
|
+
sample_rate: 24000,
|
|
9912
|
+
speech_rate: speechRate,
|
|
9913
|
+
loudness_rate: loudnessRate,
|
|
9914
|
+
emotion: audio.emotion,
|
|
9915
|
+
emotion_scale: audio.emotion_scale
|
|
9916
|
+
}
|
|
9917
|
+
}
|
|
9918
|
+
};
|
|
9919
|
+
if (audio.context_texts) {
|
|
9920
|
+
payload.req_params.additions = JSON.stringify({
|
|
9921
|
+
context_texts: audio.context_texts
|
|
9922
|
+
});
|
|
9923
|
+
}
|
|
9924
|
+
try {
|
|
9925
|
+
const response = await import_axios7.default.post(url, payload, {
|
|
9926
|
+
headers,
|
|
9927
|
+
responseType: "arraybuffer"
|
|
9928
|
+
});
|
|
9929
|
+
const responseText = new TextDecoder().decode(response.data);
|
|
9930
|
+
const jsonObjects = [];
|
|
9931
|
+
let depth = 0;
|
|
9932
|
+
let start = 0;
|
|
9933
|
+
for (let i = 0;i < responseText.length; i++) {
|
|
9934
|
+
if (responseText[i] === "{") {
|
|
9935
|
+
if (depth === 0)
|
|
9936
|
+
start = i;
|
|
9937
|
+
depth++;
|
|
9938
|
+
} else if (responseText[i] === "}") {
|
|
9939
|
+
depth--;
|
|
9940
|
+
if (depth === 0) {
|
|
9941
|
+
try {
|
|
9942
|
+
const jsonStr = responseText.substring(start, i + 1);
|
|
9943
|
+
const jsonObj = JSON.parse(jsonStr);
|
|
9944
|
+
jsonObjects.push(jsonObj);
|
|
9945
|
+
} catch (e) {
|
|
9946
|
+
console.warn("Failed to parse JSON chunk", e);
|
|
9947
|
+
}
|
|
9948
|
+
}
|
|
9949
|
+
}
|
|
9950
|
+
}
|
|
9951
|
+
if (jsonObjects.length === 0) {
|
|
9952
|
+
try {
|
|
9953
|
+
jsonObjects.push(JSON.parse(responseText));
|
|
9954
|
+
} catch (e) {
|
|
9955
|
+
console.error("Doubao TTS Response Parse Error:", responseText);
|
|
9956
|
+
throw new Error("Invalid response format");
|
|
9957
|
+
}
|
|
9958
|
+
}
|
|
9959
|
+
const audioChunks = [];
|
|
9960
|
+
let totalLength = 0;
|
|
9961
|
+
for (const data of jsonObjects) {
|
|
9962
|
+
const code = data.code;
|
|
9963
|
+
const message = data.message;
|
|
9964
|
+
if (typeof code === "number" && code !== 0 && code !== 20000000) {
|
|
9965
|
+
console.error("Doubao TTS Error Response:", JSON.stringify(data, null, 2));
|
|
9966
|
+
const err = new Error(`豆包语音合成失败: ${message} (code: ${code})`);
|
|
9967
|
+
err.code = code;
|
|
9968
|
+
err.reqid = data.reqid;
|
|
9969
|
+
throw err;
|
|
9970
|
+
}
|
|
9971
|
+
if (data.data) {
|
|
9972
|
+
const chunkBuffer = decodeBase64ToArrayBuffer(data.data);
|
|
9973
|
+
audioChunks.push(chunkBuffer);
|
|
9974
|
+
totalLength += chunkBuffer.byteLength;
|
|
9975
|
+
}
|
|
9976
|
+
}
|
|
9977
|
+
if (totalLength === 0) {
|
|
9978
|
+
throw new Error("豆包语音合成失败:未返回音频数据");
|
|
9979
|
+
}
|
|
9980
|
+
const resultBuffer = new Uint8Array(totalLength);
|
|
9981
|
+
let offset = 0;
|
|
9982
|
+
for (const chunk of audioChunks) {
|
|
9983
|
+
resultBuffer.set(new Uint8Array(chunk), offset);
|
|
9984
|
+
offset += chunk.byteLength;
|
|
9985
|
+
}
|
|
9986
|
+
return resultBuffer.buffer;
|
|
9987
|
+
} catch (error) {
|
|
9988
|
+
if (error.response) {
|
|
9989
|
+
try {
|
|
9990
|
+
let errorData = error.response.data;
|
|
9991
|
+
if (errorData instanceof ArrayBuffer || typeof Buffer !== "undefined" && Buffer.isBuffer(errorData)) {
|
|
9992
|
+
errorData = new TextDecoder().decode(errorData);
|
|
9993
|
+
} else if (typeof errorData === "object") {
|
|
9994
|
+
errorData = JSON.stringify(errorData);
|
|
9995
|
+
}
|
|
9996
|
+
throw new Error(`Doubao TTS Error: ${error.response.status} - ${errorData}`);
|
|
9997
|
+
} catch (e) {
|
|
9998
|
+
if (e.message && e.message.startsWith("Doubao TTS Error")) {
|
|
9999
|
+
throw e;
|
|
10000
|
+
}
|
|
10001
|
+
throw new Error(`Doubao TTS Error: ${error.response.status} ${error.message}`);
|
|
10002
|
+
}
|
|
10003
|
+
}
|
|
10004
|
+
throw error;
|
|
10005
|
+
}
|
|
10006
|
+
};
|
|
10007
|
+
// src/common/ai/doubao/vc.ts
|
|
10008
|
+
var import_axios8 = __toESM(require("axios"));
|
|
10009
|
+
var getHeaders = (accessToken, contentType) => {
|
|
10010
|
+
const headers = {
|
|
10011
|
+
Authorization: `Bearer; ${accessToken}`
|
|
10012
|
+
};
|
|
10013
|
+
if (contentType) {
|
|
10014
|
+
headers["content-type"] = contentType;
|
|
10015
|
+
}
|
|
10016
|
+
return headers;
|
|
10017
|
+
};
|
|
10018
|
+
var handleResponse = (data) => {
|
|
10019
|
+
if (data instanceof ArrayBuffer) {
|
|
10020
|
+
return data;
|
|
10021
|
+
}
|
|
10022
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
|
|
10023
|
+
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
10024
|
+
}
|
|
10025
|
+
return data;
|
|
10026
|
+
};
|
|
10027
|
+
var vc = {
|
|
10028
|
+
submit: async (params) => {
|
|
10029
|
+
const { app, audio, options = {} } = params;
|
|
10030
|
+
const url = new URL("https://openspeech.bytedance.com/api/v1/vc/submit");
|
|
10031
|
+
url.searchParams.set("appid", app.appid);
|
|
10032
|
+
Object.entries(options).forEach(([key2, value]) => {
|
|
10033
|
+
if (value !== undefined && value !== null) {
|
|
10034
|
+
url.searchParams.set(key2, String(value));
|
|
10035
|
+
}
|
|
10036
|
+
});
|
|
10037
|
+
const response = await import_axios8.default.post(url.toString(), audio.data, {
|
|
10038
|
+
headers: getHeaders(app.accessToken, audio.contentType || "audio/wav"),
|
|
10039
|
+
responseType: "arraybuffer"
|
|
10040
|
+
});
|
|
10041
|
+
return handleResponse(response.data);
|
|
10042
|
+
},
|
|
10043
|
+
query: async (params) => {
|
|
10044
|
+
const { app, id, blocking } = params;
|
|
10045
|
+
const url = new URL("https://openspeech.bytedance.com/api/v1/vc/query");
|
|
10046
|
+
url.searchParams.set("appid", app.appid);
|
|
10047
|
+
url.searchParams.set("id", id);
|
|
10048
|
+
if (blocking !== undefined) {
|
|
10049
|
+
url.searchParams.set("blocking", String(blocking));
|
|
10050
|
+
}
|
|
10051
|
+
const response = await import_axios8.default.get(url.toString(), {
|
|
10052
|
+
headers: getHeaders(app.accessToken),
|
|
10053
|
+
responseType: "arraybuffer"
|
|
10054
|
+
});
|
|
10055
|
+
return handleResponse(response.data);
|
|
10056
|
+
}
|
|
10057
|
+
};
|
|
10058
|
+
// src/common/ai/keling/index.ts
|
|
10059
|
+
var exports_keling = {};
|
|
10060
|
+
__export(exports_keling, {
|
|
10061
|
+
setCookie: () => setCookie,
|
|
10062
|
+
getVideoStatus: () => getVideoStatus,
|
|
10063
|
+
generateVideo: () => generateVideo
|
|
10064
|
+
});
|
|
10065
|
+
|
|
10066
|
+
// src/common/ai/keling/utils.ts
|
|
10067
|
+
var url = __toESM(require("url"));
|
|
10068
|
+
var path = __toESM(require("path"));
|
|
10069
|
+
|
|
10070
|
+
// src/common/ai/keling/axios.ts
|
|
10071
|
+
var import_axios9 = __toESM(require("axios"));
|
|
10072
|
+
var axios4 = import_axios9.default.create({
|
|
10073
|
+
headers: {
|
|
10074
|
+
"Content-Type": "application/json",
|
|
10075
|
+
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"
|
|
10076
|
+
}
|
|
10077
|
+
});
|
|
10078
|
+
|
|
10079
|
+
// src/common/ai/keling/utils.ts
|
|
10080
|
+
var getToken = async (filename) => {
|
|
10081
|
+
try {
|
|
10082
|
+
const response = await axios4.get("https://klingai.kuaishou.com/api/upload/issue/token", {
|
|
10083
|
+
params: { filename }
|
|
10084
|
+
});
|
|
10085
|
+
return response.data.data.token;
|
|
10086
|
+
} catch (error) {
|
|
10087
|
+
console.error("获取 token 失败:", error);
|
|
10088
|
+
throw error;
|
|
10089
|
+
}
|
|
10090
|
+
};
|
|
10091
|
+
var uploadFragment = async (uploadToken, imageBuffer) => {
|
|
10092
|
+
try {
|
|
10093
|
+
const response = await axios4.post("https://upload.kuaishouzt.com/api/upload/fragment", imageBuffer, {
|
|
10094
|
+
params: {
|
|
10095
|
+
upload_token: uploadToken,
|
|
10096
|
+
fragment_id: 0
|
|
10097
|
+
},
|
|
10098
|
+
headers: {
|
|
10099
|
+
"Content-Type": "application/octet-stream"
|
|
10100
|
+
}
|
|
10101
|
+
});
|
|
10102
|
+
return response.data;
|
|
10103
|
+
} catch (error) {
|
|
10104
|
+
console.error("上传片段失败:", error);
|
|
10105
|
+
throw error;
|
|
10106
|
+
}
|
|
10107
|
+
};
|
|
10108
|
+
var completeUpload = async (uploadToken) => {
|
|
10109
|
+
try {
|
|
10110
|
+
const response = await axios4.post("https://upload.kuaishouzt.com/api/upload/complete", null, {
|
|
10111
|
+
params: {
|
|
10112
|
+
upload_token: uploadToken,
|
|
10113
|
+
fragment_count: 1
|
|
10114
|
+
}
|
|
10115
|
+
});
|
|
10116
|
+
return response.data;
|
|
10117
|
+
} catch (error) {
|
|
10118
|
+
console.error("完成上传失败:", error);
|
|
10119
|
+
throw error;
|
|
10120
|
+
}
|
|
10121
|
+
};
|
|
10122
|
+
var verifyUpload = async (token) => {
|
|
10123
|
+
try {
|
|
10124
|
+
const response = await axios4.get("https://klingai.kuaishou.com/api/upload/verify/token", {
|
|
10125
|
+
params: { token }
|
|
10126
|
+
});
|
|
10127
|
+
if (response.data?.result === 1 && response.data?.data?.status === 3) {
|
|
10128
|
+
return response.data.data?.url;
|
|
10129
|
+
} else {
|
|
10130
|
+
throw new Error(`上传验证失败: ${response.data.message}`);
|
|
10131
|
+
}
|
|
10132
|
+
} catch (error) {
|
|
10133
|
+
console.error("获取上传结果失败:", error);
|
|
10134
|
+
throw error;
|
|
10135
|
+
}
|
|
10136
|
+
};
|
|
10137
|
+
var downloadImage = async (imageUrl) => {
|
|
10138
|
+
try {
|
|
10139
|
+
const response = await axios4.get(imageUrl, {
|
|
10140
|
+
responseType: "arraybuffer"
|
|
10141
|
+
});
|
|
10142
|
+
return Buffer.from(response.data, "binary");
|
|
10143
|
+
} catch (error) {
|
|
10144
|
+
console.error("下载图片失败:", error);
|
|
10145
|
+
throw error;
|
|
10146
|
+
}
|
|
10147
|
+
};
|
|
10148
|
+
var uploadImage = async (imageUrl) => {
|
|
10149
|
+
try {
|
|
10150
|
+
const parsedUrl = url.parse(imageUrl);
|
|
10151
|
+
if (!parsedUrl.pathname) {
|
|
10152
|
+
return;
|
|
10153
|
+
}
|
|
10154
|
+
const filename = path.basename(parsedUrl.pathname);
|
|
10155
|
+
const imageBuffer = await downloadImage(imageUrl);
|
|
10156
|
+
const token = await getToken(filename);
|
|
10157
|
+
await uploadFragment(token, imageBuffer);
|
|
10158
|
+
await completeUpload(token);
|
|
10159
|
+
return await verifyUpload(token);
|
|
10160
|
+
} catch (error) {
|
|
10161
|
+
console.error("上传图片失败:", error);
|
|
10162
|
+
throw error;
|
|
10163
|
+
}
|
|
10164
|
+
};
|
|
10165
|
+
var sbumit = async (imageUrl, prompt) => {
|
|
10166
|
+
try {
|
|
10167
|
+
var data = JSON.stringify({
|
|
10168
|
+
arguments: [
|
|
10169
|
+
{
|
|
10170
|
+
name: "prompt",
|
|
10171
|
+
value: prompt || ""
|
|
10172
|
+
},
|
|
10173
|
+
{
|
|
10174
|
+
name: "negative_prompt",
|
|
10175
|
+
value: "闪烁、动画、模糊、变形、毁容、低质量、拼贴、颗粒状、抽象、计算机生成、扭曲"
|
|
10176
|
+
},
|
|
10177
|
+
{
|
|
10178
|
+
name: "cfg",
|
|
10179
|
+
value: "0.5"
|
|
10180
|
+
},
|
|
10181
|
+
{
|
|
10182
|
+
name: "duration",
|
|
10183
|
+
value: "5"
|
|
10184
|
+
},
|
|
10185
|
+
{
|
|
10186
|
+
name: "imageCount",
|
|
10187
|
+
value: "1"
|
|
10188
|
+
},
|
|
10189
|
+
{
|
|
10190
|
+
name: "kling_version",
|
|
10191
|
+
value: "1.5"
|
|
10192
|
+
},
|
|
10193
|
+
{
|
|
10194
|
+
name: "tail_image_enabled",
|
|
10195
|
+
value: "false"
|
|
10196
|
+
},
|
|
10197
|
+
{
|
|
10198
|
+
name: "camera_json",
|
|
10199
|
+
value: '{"type":"empty","horizontal":0,"vertical":0,"zoom":0,"tilt":0,"pan":0,"roll":0}'
|
|
10200
|
+
},
|
|
10201
|
+
{
|
|
10202
|
+
name: "camera_control_enabled",
|
|
10203
|
+
value: "false"
|
|
10204
|
+
},
|
|
10205
|
+
{
|
|
10206
|
+
name: "biz",
|
|
10207
|
+
value: "klingai"
|
|
10208
|
+
}
|
|
10209
|
+
],
|
|
10210
|
+
inputs: [
|
|
10211
|
+
{
|
|
10212
|
+
inputType: "URL",
|
|
10213
|
+
url: imageUrl,
|
|
10214
|
+
name: "input"
|
|
10215
|
+
}
|
|
10216
|
+
],
|
|
10217
|
+
type: "m2v_img2video_hq"
|
|
10218
|
+
});
|
|
10219
|
+
const response = await axios4({
|
|
10220
|
+
method: "POST",
|
|
10221
|
+
url: "https://klingai.kuaishou.com/api/task/submit",
|
|
10222
|
+
data
|
|
10223
|
+
});
|
|
10224
|
+
return response.data?.data?.task?.id;
|
|
10225
|
+
} catch (error) {
|
|
10226
|
+
console.error("完成上传失败:", error);
|
|
10227
|
+
throw error;
|
|
10228
|
+
}
|
|
10229
|
+
};
|
|
10230
|
+
var calculateProgress = (taskData) => {
|
|
10231
|
+
const createTime = taskData?.task?.createTime;
|
|
10232
|
+
const etaTime = taskData?.etaTime;
|
|
10233
|
+
const currentTime = Date.now();
|
|
10234
|
+
if (!createTime || !etaTime) {
|
|
10235
|
+
return 0;
|
|
10236
|
+
}
|
|
10237
|
+
const totalTimeSpan = etaTime - createTime;
|
|
10238
|
+
const timeElapsed = currentTime - createTime;
|
|
10239
|
+
if (totalTimeSpan <= 0) {
|
|
10240
|
+
return 0;
|
|
10241
|
+
}
|
|
10242
|
+
let progressRatio = timeElapsed / totalTimeSpan;
|
|
10243
|
+
if (progressRatio >= 1) {
|
|
10244
|
+
progressRatio = 0.99;
|
|
10245
|
+
}
|
|
10246
|
+
return progressRatio;
|
|
10247
|
+
};
|
|
10248
|
+
var setCookie = (newCookieValue) => {
|
|
10249
|
+
axios4.defaults.headers.Cookie = newCookieValue;
|
|
10250
|
+
};
|
|
10251
|
+
|
|
10252
|
+
// src/common/ai/keling/index.ts
|
|
10253
|
+
var getVideoStatus = async (taskId) => {
|
|
10254
|
+
if (!taskId) {
|
|
10255
|
+
return;
|
|
10256
|
+
}
|
|
10257
|
+
try {
|
|
10258
|
+
const response = await axios4.get("https://klingai.kuaishou.com/api/task/status", {
|
|
10259
|
+
params: { taskId }
|
|
10260
|
+
});
|
|
10261
|
+
return {
|
|
10262
|
+
status: response.data?.data?.status,
|
|
10263
|
+
url: response.data?.data?.works?.[0]?.resource?.resource,
|
|
10264
|
+
cover: response.data?.data?.works?.[0]?.cover?.resource,
|
|
10265
|
+
progress: calculateProgress(response.data?.data) * 100
|
|
10266
|
+
};
|
|
10267
|
+
} catch (error) {
|
|
10268
|
+
console.error("获取 status 失败:", error);
|
|
10269
|
+
throw error;
|
|
10270
|
+
}
|
|
10271
|
+
};
|
|
10272
|
+
var generateVideo = async (imageUrl, prompt) => {
|
|
10273
|
+
const uploadedUrl = await uploadImage(imageUrl);
|
|
10274
|
+
console.log("图片上传成功,URL:", uploadedUrl);
|
|
10275
|
+
const taskId = await sbumit(uploadedUrl, prompt);
|
|
10276
|
+
console.log(666, "任务 id", taskId);
|
|
10277
|
+
return taskId;
|
|
10278
|
+
};
|
|
10279
|
+
// src/common/base/string.ts
|
|
9610
10280
|
var getChineseByStr = (str) => {
|
|
9611
10281
|
if (!str) {
|
|
9612
10282
|
return "";
|
|
@@ -9701,9 +10371,9 @@ var getChinese = (str) => {
|
|
|
9701
10371
|
var getSliceStr = (str, before, after) => {
|
|
9702
10372
|
return str.slice(str.indexOf(before) + before.length, str.lastIndexOf(after));
|
|
9703
10373
|
};
|
|
9704
|
-
var getProxyUrl = (
|
|
10374
|
+
var getProxyUrl = (url2) => {
|
|
9705
10375
|
const beforeUrl = "https://1141871752167714.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/a.LATEST/proxy/?url=";
|
|
9706
|
-
return beforeUrl +
|
|
10376
|
+
return beforeUrl + url2;
|
|
9707
10377
|
};
|
|
9708
10378
|
var getLength = (value) => {
|
|
9709
10379
|
const chineseLength = getChinese(value).length;
|
|
@@ -9749,54 +10419,7 @@ var generateUniqueFileName = (name) => {
|
|
|
9749
10419
|
}
|
|
9750
10420
|
throw new Error("Invalid filename format.");
|
|
9751
10421
|
};
|
|
9752
|
-
|
|
9753
|
-
var findItem = (list, attr, value) => {
|
|
9754
|
-
return list.find((item) => value === undefined ? item[attr] : item[attr] === value);
|
|
9755
|
-
};
|
|
9756
|
-
var filterParams = (params, deep = false) => {
|
|
9757
|
-
const clean = (value) => {
|
|
9758
|
-
if (value === undefined || value === null) {
|
|
9759
|
-
return;
|
|
9760
|
-
}
|
|
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
|
-
});
|
|
9798
|
-
}
|
|
9799
|
-
};
|
|
10422
|
+
|
|
9800
10423
|
// ../../node_modules/decimal.js/decimal.mjs
|
|
9801
10424
|
/*!
|
|
9802
10425
|
* decimal.js v10.6.0
|
|
@@ -12110,18 +12733,18 @@ LN10 = new Decimal(LN10);
|
|
|
12110
12733
|
PI = new Decimal(PI);
|
|
12111
12734
|
var decimal_default = Decimal;
|
|
12112
12735
|
|
|
12113
|
-
// src/common/other.ts
|
|
12736
|
+
// src/common/base/other.ts
|
|
12114
12737
|
var delay = (time = 1000) => {
|
|
12115
12738
|
return new Promise((resolve) => setTimeout(resolve, time));
|
|
12116
12739
|
};
|
|
12117
12740
|
var calcJsText = (expr, context) => {
|
|
12118
12741
|
const keys = Object.keys(context);
|
|
12119
|
-
const values = keys.map((
|
|
12742
|
+
const values = keys.map((key2) => context[key2]);
|
|
12120
12743
|
return Function(...keys, `return (${expr})`)(...values);
|
|
12121
12744
|
};
|
|
12122
|
-
var optionsToEnum = (options, text,
|
|
12745
|
+
var optionsToEnum = (options, text, key2) => {
|
|
12123
12746
|
return options.reduce((acc, cur) => {
|
|
12124
|
-
acc[cur[
|
|
12747
|
+
acc[cur[key2]] = {
|
|
12125
12748
|
text: cur[text]
|
|
12126
12749
|
};
|
|
12127
12750
|
return acc;
|
|
@@ -12152,13 +12775,13 @@ var performDecimalOperation = (num1, num2, operator) => {
|
|
|
12152
12775
|
return NaN;
|
|
12153
12776
|
}
|
|
12154
12777
|
};
|
|
12155
|
-
var printConsoleLog = (type,
|
|
12778
|
+
var printConsoleLog = (type, path2, params, response) => {
|
|
12156
12779
|
const styles = {
|
|
12157
12780
|
header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
|
|
12158
12781
|
value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
|
|
12159
12782
|
separator: "color: #409EFF; margin: 0 4px;"
|
|
12160
12783
|
};
|
|
12161
|
-
console.groupCollapsed(`666 %c${type}%c${
|
|
12784
|
+
console.groupCollapsed(`666 %c${type}%c${path2}`, styles.header, styles.value);
|
|
12162
12785
|
if (params) {
|
|
12163
12786
|
console.table(params);
|
|
12164
12787
|
}
|
|
@@ -12167,7 +12790,59 @@ var printConsoleLog = (type, path, params, response) => {
|
|
|
12167
12790
|
}
|
|
12168
12791
|
console.groupEnd();
|
|
12169
12792
|
};
|
|
12170
|
-
|
|
12793
|
+
|
|
12794
|
+
// src/common/base/array.ts
|
|
12795
|
+
var shuffleArray = (array) => {
|
|
12796
|
+
const shuffledArray = [...array];
|
|
12797
|
+
for (let i = shuffledArray.length - 1;i > 0; i--) {
|
|
12798
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
12799
|
+
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
|
|
12800
|
+
}
|
|
12801
|
+
return shuffledArray;
|
|
12802
|
+
};
|
|
12803
|
+
var removeSimilarDuplicates = (arr, threshold, isLog) => {
|
|
12804
|
+
const uniqueArray = [];
|
|
12805
|
+
const similarPairs = [];
|
|
12806
|
+
for (const str of arr) {
|
|
12807
|
+
const isSimilar = uniqueArray.some((uniqueStr) => {
|
|
12808
|
+
const distance = levenshteinDistance(str, uniqueStr);
|
|
12809
|
+
if (distance <= threshold) {
|
|
12810
|
+
similarPairs.push([str, uniqueStr]);
|
|
12811
|
+
return true;
|
|
12812
|
+
}
|
|
12813
|
+
return false;
|
|
12814
|
+
});
|
|
12815
|
+
if (!isSimilar) {
|
|
12816
|
+
uniqueArray.push(str);
|
|
12817
|
+
}
|
|
12818
|
+
}
|
|
12819
|
+
if (isLog) {
|
|
12820
|
+
if (similarPairs.length > 0) {
|
|
12821
|
+
similarPairs.forEach((pair) => {
|
|
12822
|
+
console.log(pair[0]);
|
|
12823
|
+
console.log(pair[1]);
|
|
12824
|
+
console.log();
|
|
12825
|
+
});
|
|
12826
|
+
} else {
|
|
12827
|
+
console.log("没有找到类似的字符串");
|
|
12828
|
+
}
|
|
12829
|
+
}
|
|
12830
|
+
return uniqueArray;
|
|
12831
|
+
};
|
|
12832
|
+
var getTotal = (arr, key2) => {
|
|
12833
|
+
if (!Array.isArray(arr) || !key2) {
|
|
12834
|
+
return 0;
|
|
12835
|
+
}
|
|
12836
|
+
return arr.reduce((total, item) => {
|
|
12837
|
+
const itemValue = Number(item[key2]);
|
|
12838
|
+
if (!isNaN(itemValue)) {
|
|
12839
|
+
return performDecimalOperation(total, itemValue, "+");
|
|
12840
|
+
}
|
|
12841
|
+
return total;
|
|
12842
|
+
}, 0);
|
|
12843
|
+
};
|
|
12844
|
+
|
|
12845
|
+
// src/common/base/number.ts
|
|
12171
12846
|
var getRandomNum = (min2, max2) => {
|
|
12172
12847
|
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
12173
12848
|
};
|
|
@@ -12209,70 +12884,77 @@ var numberWithCommas = (x) => {
|
|
|
12209
12884
|
}
|
|
12210
12885
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
12211
12886
|
};
|
|
12212
|
-
|
|
12213
|
-
|
|
12214
|
-
|
|
12215
|
-
|
|
12216
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
12217
|
-
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
|
|
12218
|
-
}
|
|
12219
|
-
return shuffledArray;
|
|
12887
|
+
|
|
12888
|
+
// src/common/base/object.ts
|
|
12889
|
+
var findItem = (list, attr, value) => {
|
|
12890
|
+
return list.find((item) => value === undefined ? item[attr] : item[attr] === value);
|
|
12220
12891
|
};
|
|
12221
|
-
var
|
|
12222
|
-
const
|
|
12223
|
-
|
|
12224
|
-
|
|
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);
|
|
12892
|
+
var filterParams = (params, deep = false) => {
|
|
12893
|
+
const clean = (value) => {
|
|
12894
|
+
if (value === undefined || value === null) {
|
|
12895
|
+
return;
|
|
12235
12896
|
}
|
|
12236
|
-
|
|
12237
|
-
|
|
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("没有找到类似的字符串");
|
|
12897
|
+
if (!deep) {
|
|
12898
|
+
return value;
|
|
12246
12899
|
}
|
|
12247
|
-
|
|
12248
|
-
|
|
12900
|
+
if (Array.isArray(value)) {
|
|
12901
|
+
return value.map((v) => clean(v)).filter((v) => v !== undefined);
|
|
12902
|
+
}
|
|
12903
|
+
if (typeof value === "object") {
|
|
12904
|
+
return Object.entries(value).reduce((acc, [k, v]) => {
|
|
12905
|
+
const cleaned = clean(v);
|
|
12906
|
+
if (cleaned !== undefined)
|
|
12907
|
+
acc[k] = cleaned;
|
|
12908
|
+
return acc;
|
|
12909
|
+
}, {});
|
|
12910
|
+
}
|
|
12911
|
+
return value;
|
|
12912
|
+
};
|
|
12913
|
+
return clean(params);
|
|
12249
12914
|
};
|
|
12250
|
-
var
|
|
12251
|
-
|
|
12252
|
-
|
|
12915
|
+
var watch = {
|
|
12916
|
+
observe(obj, key2, watchFun) {
|
|
12917
|
+
const val = obj[key2];
|
|
12918
|
+
Object.defineProperty(obj, key2, {
|
|
12919
|
+
configurable: true,
|
|
12920
|
+
enumerable: true,
|
|
12921
|
+
set(value) {
|
|
12922
|
+
obj[key2] = value;
|
|
12923
|
+
watchFun(value, val);
|
|
12924
|
+
},
|
|
12925
|
+
get() {
|
|
12926
|
+
return val;
|
|
12927
|
+
}
|
|
12928
|
+
});
|
|
12929
|
+
},
|
|
12930
|
+
setWatcher(data = {}, watch2 = {}) {
|
|
12931
|
+
Object.keys(watch2).forEach((v) => {
|
|
12932
|
+
this.observe(data, v, watch2[v]);
|
|
12933
|
+
});
|
|
12253
12934
|
}
|
|
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
12935
|
};
|
|
12262
|
-
|
|
12263
|
-
|
|
12264
|
-
async
|
|
12936
|
+
|
|
12937
|
+
// src/common/base/promise.ts
|
|
12938
|
+
var executePromise = async (promise) => {
|
|
12939
|
+
const start = Date.now();
|
|
12940
|
+
const result = await promise;
|
|
12941
|
+
const time = Date.now() - start;
|
|
12942
|
+
return {
|
|
12943
|
+
result,
|
|
12944
|
+
time
|
|
12945
|
+
};
|
|
12946
|
+
};
|
|
12947
|
+
var retryPromise = async (promiseFn, retryInterval = 1000, retryCount = 3) => {
|
|
12265
12948
|
try {
|
|
12266
|
-
|
|
12267
|
-
responseType: "arraybuffer"
|
|
12268
|
-
});
|
|
12269
|
-
const base64String = Buffer.from(response.data).toString("base64");
|
|
12270
|
-
return `data:image/*;base64,${base64String}`;
|
|
12949
|
+
return await promiseFn();
|
|
12271
12950
|
} catch (error) {
|
|
12272
|
-
|
|
12273
|
-
|
|
12951
|
+
if (retryCount <= 0) {
|
|
12952
|
+
throw error;
|
|
12953
|
+
}
|
|
12954
|
+
await new Promise((resolve) => setTimeout(resolve, retryInterval));
|
|
12955
|
+
return retryPromise(promiseFn, retryCount - 1, retryInterval);
|
|
12274
12956
|
}
|
|
12275
|
-
}
|
|
12957
|
+
};
|
|
12276
12958
|
// src/common/enum.ts
|
|
12277
12959
|
class EnumItem {
|
|
12278
12960
|
label;
|
|
@@ -12293,8 +12975,8 @@ var Enum = {
|
|
|
12293
12975
|
const extras = new Map;
|
|
12294
12976
|
const labels = new Map;
|
|
12295
12977
|
const enums = {};
|
|
12296
|
-
for (const
|
|
12297
|
-
const member = members[
|
|
12978
|
+
for (const key2 in members) {
|
|
12979
|
+
const member = members[key2];
|
|
12298
12980
|
if (!member)
|
|
12299
12981
|
continue;
|
|
12300
12982
|
if (usedValues.has(member.value)) {
|
|
@@ -12302,7 +12984,7 @@ var Enum = {
|
|
|
12302
12984
|
}
|
|
12303
12985
|
usedValues.add(member.value);
|
|
12304
12986
|
const item = new EnumItem(member);
|
|
12305
|
-
enumObj[
|
|
12987
|
+
enumObj[key2] = item;
|
|
12306
12988
|
map.set(item.value, item);
|
|
12307
12989
|
labels.set(item.value, item.label);
|
|
12308
12990
|
options.push(item);
|
|
@@ -12320,6 +13002,20 @@ var Enum = {
|
|
|
12320
13002
|
return enumObj;
|
|
12321
13003
|
}
|
|
12322
13004
|
};
|
|
13005
|
+
// src/common/image.ts
|
|
13006
|
+
var import_axios12 = __toESM(require("axios"));
|
|
13007
|
+
async function imageToBase64(url2) {
|
|
13008
|
+
try {
|
|
13009
|
+
const response = await import_axios12.default.get(url2, {
|
|
13010
|
+
responseType: "arraybuffer"
|
|
13011
|
+
});
|
|
13012
|
+
const base64String = Buffer.from(response.data).toString("base64");
|
|
13013
|
+
return `data:image/*;base64,${base64String}`;
|
|
13014
|
+
} catch (error) {
|
|
13015
|
+
console.error("Failed to fetch the image:", error);
|
|
13016
|
+
throw error;
|
|
13017
|
+
}
|
|
13018
|
+
}
|
|
12323
13019
|
// src/common/dayjs.ts
|
|
12324
13020
|
var import_dayjs = __toESM(require("dayjs"));
|
|
12325
13021
|
var import_isBetween = __toESM(require("dayjs/plugin/isBetween"));
|
|
@@ -12360,51 +13056,7 @@ var initChinaDayjs = () => {
|
|
|
12360
13056
|
};
|
|
12361
13057
|
var chinaDayjs = initChinaDayjs();
|
|
12362
13058
|
var dayjs_default = import_dayjs.default;
|
|
12363
|
-
// src/
|
|
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
|
|
13059
|
+
// src/node/mail.ts
|
|
12408
13060
|
var import_nodemailer = __toESM(require("nodemailer"));
|
|
12409
13061
|
var authMap = {
|
|
12410
13062
|
163: {
|
|
@@ -12428,11 +13080,11 @@ var sendMail = (config2) => {
|
|
|
12428
13080
|
...config2
|
|
12429
13081
|
});
|
|
12430
13082
|
};
|
|
12431
|
-
// src/node/file
|
|
13083
|
+
// src/node/file.ts
|
|
12432
13084
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
12433
|
-
var
|
|
13085
|
+
var import_axios13 = __toESM(require("axios"));
|
|
12434
13086
|
var import_url = __toESM(require("url"));
|
|
12435
|
-
var
|
|
13087
|
+
var path2 = __toESM(require("path"));
|
|
12436
13088
|
var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
12437
13089
|
try {
|
|
12438
13090
|
const data = await import_fs_extra.default.readFile(filePath, "utf8");
|
|
@@ -12455,14 +13107,14 @@ var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
|
12455
13107
|
var downloadFile = async (httpUrl, outputPath) => {
|
|
12456
13108
|
try {
|
|
12457
13109
|
let parsedUrl = import_url.default.parse(httpUrl);
|
|
12458
|
-
let fileName =
|
|
13110
|
+
let fileName = path2.basename(parsedUrl.pathname);
|
|
12459
13111
|
if (!outputPath) {
|
|
12460
13112
|
if (!import_fs_extra.default.existsSync(".tmp")) {
|
|
12461
13113
|
import_fs_extra.default.mkdirSync(".tmp", { recursive: true });
|
|
12462
13114
|
}
|
|
12463
13115
|
outputPath = ".tmp/" + decodeURIComponent(fileName);
|
|
12464
13116
|
}
|
|
12465
|
-
const response = await
|
|
13117
|
+
const response = await import_axios13.default({
|
|
12466
13118
|
url: httpUrl,
|
|
12467
13119
|
method: "get",
|
|
12468
13120
|
responseType: "stream"
|
|
@@ -12479,11 +13131,11 @@ var downloadFile = async (httpUrl, outputPath) => {
|
|
|
12479
13131
|
throw error;
|
|
12480
13132
|
}
|
|
12481
13133
|
};
|
|
12482
|
-
// src/node/oss
|
|
13134
|
+
// src/node/oss.ts
|
|
12483
13135
|
var import_ali_oss = __toESM(require("ali-oss"));
|
|
12484
|
-
var
|
|
13136
|
+
var import_axios14 = __toESM(require("axios"));
|
|
12485
13137
|
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
12486
|
-
var
|
|
13138
|
+
var path3 = __toESM(require("path"));
|
|
12487
13139
|
var oss = new import_ali_oss.default({
|
|
12488
13140
|
region: process.env.VITE_OSS_REGION,
|
|
12489
13141
|
accessKeyId: process.env.VITE_OSS_ACCESS_KEY_ID,
|
|
@@ -12496,14 +13148,14 @@ async function uploadFile(file, filename) {
|
|
|
12496
13148
|
if (typeof file === "string") {
|
|
12497
13149
|
if (/^https?:\/\//.test(file)) {
|
|
12498
13150
|
try {
|
|
12499
|
-
const response = await
|
|
13151
|
+
const response = await import_axios14.default.get(file, { responseType: "arraybuffer" });
|
|
12500
13152
|
buffer = Buffer.from(response.data);
|
|
12501
13153
|
} catch (error) {
|
|
12502
13154
|
throw new Error(`无法从 URL 下载文件: ${error}`);
|
|
12503
13155
|
}
|
|
12504
|
-
const originalName =
|
|
12505
|
-
const ext =
|
|
12506
|
-
const nameWithoutExt =
|
|
13156
|
+
const originalName = path3.basename(new URL(file).pathname);
|
|
13157
|
+
const ext = path3.extname(originalName);
|
|
13158
|
+
const nameWithoutExt = path3.basename(originalName, ext);
|
|
12507
13159
|
finalFilename = `${nameWithoutExt}_${Date.now()}${ext}`;
|
|
12508
13160
|
} else {
|
|
12509
13161
|
try {
|
|
@@ -12511,9 +13163,9 @@ async function uploadFile(file, filename) {
|
|
|
12511
13163
|
} catch (error) {
|
|
12512
13164
|
throw new Error(`无法读取文件路径: ${error}`);
|
|
12513
13165
|
}
|
|
12514
|
-
const originalName =
|
|
12515
|
-
const ext =
|
|
12516
|
-
const nameWithoutExt =
|
|
13166
|
+
const originalName = path3.basename(file);
|
|
13167
|
+
const ext = path3.extname(originalName);
|
|
13168
|
+
const nameWithoutExt = path3.basename(originalName, ext);
|
|
12517
13169
|
finalFilename = `${nameWithoutExt}_${Date.now()}${ext}`;
|
|
12518
13170
|
}
|
|
12519
13171
|
} else if (Buffer.isBuffer(file)) {
|
|
@@ -12536,7 +13188,7 @@ async function uploadFile(file, filename) {
|
|
|
12536
13188
|
throw new Error(`上传到 OSS 失败: ${error}`);
|
|
12537
13189
|
}
|
|
12538
13190
|
}
|
|
12539
|
-
// src/node/cron
|
|
13191
|
+
// src/node/cron.ts
|
|
12540
13192
|
var import_node_cron = __toESM(require("node-cron"));
|
|
12541
13193
|
var interval = (intervalMinutes, immediately, fn) => {
|
|
12542
13194
|
console.log(`定时任务已启动,将每${intervalMinutes}分钟执行一次`);
|
|
@@ -12558,7 +13210,3 @@ var schedule = (cronExpression, immediately, fn) => {
|
|
|
12558
13210
|
timezone: "Asia/Shanghai"
|
|
12559
13211
|
});
|
|
12560
13212
|
};
|
|
12561
|
-
|
|
12562
|
-
// src/node/index.ts
|
|
12563
|
-
var import_nedb = __toESM(require("nedb"));
|
|
12564
|
-
var cheerio = __toESM(require("cheerio"));
|