@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.esm.js
CHANGED
|
@@ -723,7 +723,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
723
723
|
var objectCtorString = funcToString.call(Object2);
|
|
724
724
|
var oldDash = root._;
|
|
725
725
|
var reIsNative = RegExp2("^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$");
|
|
726
|
-
var Buffer2 = moduleExports ? context.Buffer : undefined2, Symbol2 = context.Symbol,
|
|
726
|
+
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;
|
|
727
727
|
var defineProperty = function() {
|
|
728
728
|
try {
|
|
729
729
|
var func = getNative(Object2, "defineProperty");
|
|
@@ -1981,7 +1981,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
1981
1981
|
}
|
|
1982
1982
|
function cloneArrayBuffer(arrayBuffer) {
|
|
1983
1983
|
var result2 = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
|
1984
|
-
new
|
|
1984
|
+
new Uint8Array2(result2).set(new Uint8Array2(arrayBuffer));
|
|
1985
1985
|
return result2;
|
|
1986
1986
|
}
|
|
1987
1987
|
function cloneDataView(dataView, isDeep) {
|
|
@@ -2563,7 +2563,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
2563
2563
|
object = object.buffer;
|
|
2564
2564
|
other = other.buffer;
|
|
2565
2565
|
case arrayBufferTag:
|
|
2566
|
-
if (object.byteLength != other.byteLength || !equalFunc(new
|
|
2566
|
+
if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array2(object), new Uint8Array2(other))) {
|
|
2567
2567
|
return false;
|
|
2568
2568
|
}
|
|
2569
2569
|
return true;
|
|
@@ -5441,11 +5441,13 @@ __p += '`;
|
|
|
5441
5441
|
}).call(exports);
|
|
5442
5442
|
});
|
|
5443
5443
|
|
|
5444
|
-
// src/
|
|
5444
|
+
// src/node.ts
|
|
5445
5445
|
var import_lodash = __toESM(require_lodash(), 1);
|
|
5446
|
-
import { default as
|
|
5447
|
-
import
|
|
5448
|
-
import { default as
|
|
5446
|
+
import { default as default2, DataStoreOptions } from "nedb";
|
|
5447
|
+
import * as cheerio from "cheerio";
|
|
5448
|
+
import { default as default4 } from "axios";
|
|
5449
|
+
import { default as default5 } from "json5";
|
|
5450
|
+
import { default as default6 } from "consola";
|
|
5449
5451
|
|
|
5450
5452
|
// ../../node_modules/zod/v3/external.js
|
|
5451
5453
|
var exports_external = {};
|
|
@@ -9420,7 +9422,673 @@ var coerce = {
|
|
|
9420
9422
|
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
9421
9423
|
};
|
|
9422
9424
|
var NEVER = INVALID;
|
|
9423
|
-
// src/common/
|
|
9425
|
+
// src/common/ai/302/index.ts
|
|
9426
|
+
var exports_302 = {};
|
|
9427
|
+
__export(exports_302, {
|
|
9428
|
+
image: () => exports_image,
|
|
9429
|
+
chat: () => chat,
|
|
9430
|
+
audio: () => exports_audio
|
|
9431
|
+
});
|
|
9432
|
+
|
|
9433
|
+
// src/common/ai/302/axios.ts
|
|
9434
|
+
import axios_ from "axios";
|
|
9435
|
+
var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
|
|
9436
|
+
var axios = axios_.create({
|
|
9437
|
+
baseURL: "https://api.302.ai",
|
|
9438
|
+
headers: {
|
|
9439
|
+
"mj-api-secret": key,
|
|
9440
|
+
Authorization: `Bearer ${key}`
|
|
9441
|
+
}
|
|
9442
|
+
});
|
|
9443
|
+
|
|
9444
|
+
// src/common/ai/302/chat/index.ts
|
|
9445
|
+
import json5 from "json5";
|
|
9446
|
+
var chat = async (message, model = "gpt-4.1", isParse = true) => {
|
|
9447
|
+
try {
|
|
9448
|
+
let { data } = await axios({
|
|
9449
|
+
url: "/v1/chat/completions",
|
|
9450
|
+
method: "post",
|
|
9451
|
+
data: {
|
|
9452
|
+
model,
|
|
9453
|
+
message
|
|
9454
|
+
}
|
|
9455
|
+
});
|
|
9456
|
+
console.log(666, "302 chat res", typeof data, data);
|
|
9457
|
+
const output = typeof data === "string" ? json5.parse(data)?.output : data?.output;
|
|
9458
|
+
if (isParse) {
|
|
9459
|
+
const match = /```(json)?(.*)```/s.exec(output);
|
|
9460
|
+
if (!match) {
|
|
9461
|
+
return json5.parse(output);
|
|
9462
|
+
} else {
|
|
9463
|
+
return json5.parse(match[2]);
|
|
9464
|
+
}
|
|
9465
|
+
}
|
|
9466
|
+
return output;
|
|
9467
|
+
} catch (error) {
|
|
9468
|
+
const responseData = error?.response?.data;
|
|
9469
|
+
const message2 = responseData?.error?.message_cn || responseData?.error?.message || responseData?.message || error?.response?.statusText || error?.message || "未知原因";
|
|
9470
|
+
throw new Error(message2);
|
|
9471
|
+
}
|
|
9472
|
+
};
|
|
9473
|
+
// src/common/ai/302/audio/index.ts
|
|
9474
|
+
var exports_audio = {};
|
|
9475
|
+
__export(exports_audio, {
|
|
9476
|
+
tts: () => exports_tts,
|
|
9477
|
+
doubao: () => exports_doubao
|
|
9478
|
+
});
|
|
9479
|
+
|
|
9480
|
+
// src/common/ai/302/audio/tts.ts
|
|
9481
|
+
var exports_tts = {};
|
|
9482
|
+
__export(exports_tts, {
|
|
9483
|
+
textToSpeech: () => textToSpeech,
|
|
9484
|
+
fetchTask: () => fetchTask,
|
|
9485
|
+
fetchProviders: () => fetchProviders
|
|
9486
|
+
});
|
|
9487
|
+
var fetchProviders = async () => {
|
|
9488
|
+
try {
|
|
9489
|
+
const { data } = await axios({
|
|
9490
|
+
url: "/302/tts/provider",
|
|
9491
|
+
method: "get"
|
|
9492
|
+
});
|
|
9493
|
+
return data;
|
|
9494
|
+
} catch (error) {
|
|
9495
|
+
throw error;
|
|
9496
|
+
}
|
|
9497
|
+
};
|
|
9498
|
+
var textToSpeech = async (request) => {
|
|
9499
|
+
try {
|
|
9500
|
+
const { webhook, run_async, ...body } = request;
|
|
9501
|
+
const { data } = await axios({
|
|
9502
|
+
url: "/302/v2/audio/tts",
|
|
9503
|
+
method: "post",
|
|
9504
|
+
params: {
|
|
9505
|
+
webhook,
|
|
9506
|
+
run_async
|
|
9507
|
+
},
|
|
9508
|
+
data: {
|
|
9509
|
+
...body,
|
|
9510
|
+
speed: body.speed ?? 1,
|
|
9511
|
+
volume: body.volume ?? 1,
|
|
9512
|
+
timeout: body.timeout ?? 180
|
|
9513
|
+
}
|
|
9514
|
+
});
|
|
9515
|
+
return data;
|
|
9516
|
+
} catch (error) {
|
|
9517
|
+
throw error;
|
|
9518
|
+
}
|
|
9519
|
+
};
|
|
9520
|
+
var fetchTask = async (taskId) => {
|
|
9521
|
+
if (!taskId) {
|
|
9522
|
+
throw new Error("taskId 不能为空");
|
|
9523
|
+
}
|
|
9524
|
+
try {
|
|
9525
|
+
const { data } = await axios({
|
|
9526
|
+
url: `/302/v2/audio/fetch/${encodeURIComponent(taskId)}`,
|
|
9527
|
+
method: "get"
|
|
9528
|
+
});
|
|
9529
|
+
return data;
|
|
9530
|
+
} catch (error) {
|
|
9531
|
+
throw error;
|
|
9532
|
+
}
|
|
9533
|
+
};
|
|
9534
|
+
// src/common/ai/302/audio/doubao.ts
|
|
9535
|
+
var exports_doubao = {};
|
|
9536
|
+
__export(exports_doubao, {
|
|
9537
|
+
ttsHd: () => ttsHd
|
|
9538
|
+
});
|
|
9539
|
+
var createReqid = () => {
|
|
9540
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
9541
|
+
return crypto.randomUUID();
|
|
9542
|
+
}
|
|
9543
|
+
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
9544
|
+
};
|
|
9545
|
+
var getUtf8ByteLength = (value) => {
|
|
9546
|
+
return new TextEncoder().encode(value).length;
|
|
9547
|
+
};
|
|
9548
|
+
var assertNonEmptyString = (value, label) => {
|
|
9549
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
9550
|
+
throw new Error(`${label} 不能为空`);
|
|
9551
|
+
}
|
|
9552
|
+
};
|
|
9553
|
+
var assertSpeedRatio = (value) => {
|
|
9554
|
+
if (value === undefined)
|
|
9555
|
+
return;
|
|
9556
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
9557
|
+
throw new Error("speed_ratio 必须为数字");
|
|
9558
|
+
}
|
|
9559
|
+
if (value < 0.8 || value > 2) {
|
|
9560
|
+
throw new Error("speed_ratio 取值范围为 [0.8, 2]");
|
|
9561
|
+
}
|
|
9562
|
+
};
|
|
9563
|
+
var ttsHd = async (payload) => {
|
|
9564
|
+
const { audio, request } = payload;
|
|
9565
|
+
const { voice_type, encoding, speed_ratio } = audio;
|
|
9566
|
+
const { text, reqid: rawReqid, operation } = request;
|
|
9567
|
+
assertNonEmptyString(voice_type, "voice_type");
|
|
9568
|
+
assertNonEmptyString(text, "text");
|
|
9569
|
+
assertSpeedRatio(speed_ratio);
|
|
9570
|
+
const textByteLength = getUtf8ByteLength(text);
|
|
9571
|
+
if (textByteLength > 1024) {
|
|
9572
|
+
throw new Error(`text 超出长度限制:${textByteLength}/1024 字节`);
|
|
9573
|
+
}
|
|
9574
|
+
const reqid = rawReqid?.trim() || createReqid();
|
|
9575
|
+
const { data } = await axios({
|
|
9576
|
+
url: "/doubao/tts_hd",
|
|
9577
|
+
method: "post",
|
|
9578
|
+
data: {
|
|
9579
|
+
audio: {
|
|
9580
|
+
voice_type,
|
|
9581
|
+
encoding: encoding ?? "pcm",
|
|
9582
|
+
speed_ratio: speed_ratio ?? 1
|
|
9583
|
+
},
|
|
9584
|
+
request: {
|
|
9585
|
+
reqid,
|
|
9586
|
+
text,
|
|
9587
|
+
operation: operation ?? "query"
|
|
9588
|
+
}
|
|
9589
|
+
}
|
|
9590
|
+
});
|
|
9591
|
+
return data;
|
|
9592
|
+
};
|
|
9593
|
+
// src/common/ai/302/image/index.ts
|
|
9594
|
+
var exports_image = {};
|
|
9595
|
+
__export(exports_image, {
|
|
9596
|
+
midjourney: () => exports_midjourney,
|
|
9597
|
+
gpt: () => exports_gpt
|
|
9598
|
+
});
|
|
9599
|
+
|
|
9600
|
+
// src/common/ai/302/image/midjourney.ts
|
|
9601
|
+
var exports_midjourney = {};
|
|
9602
|
+
__export(exports_midjourney, {
|
|
9603
|
+
getImageStatus: () => getImageStatus,
|
|
9604
|
+
generateImage: () => generateImage
|
|
9605
|
+
});
|
|
9606
|
+
var generateImage = async (prompt, base64Array) => {
|
|
9607
|
+
try {
|
|
9608
|
+
const { data } = await axios({
|
|
9609
|
+
url: "/mj/submit/imagine",
|
|
9610
|
+
method: "post",
|
|
9611
|
+
data: {
|
|
9612
|
+
prompt,
|
|
9613
|
+
base64Array,
|
|
9614
|
+
botType: "MID_JOURNEY",
|
|
9615
|
+
notifyHook: "",
|
|
9616
|
+
state: ""
|
|
9617
|
+
}
|
|
9618
|
+
});
|
|
9619
|
+
return data;
|
|
9620
|
+
} catch (error) {
|
|
9621
|
+
throw error;
|
|
9622
|
+
}
|
|
9623
|
+
};
|
|
9624
|
+
var getImageStatus = async (taskId) => {
|
|
9625
|
+
try {
|
|
9626
|
+
const { data } = await axios({
|
|
9627
|
+
url: `/mj/task/${taskId}/fetch`,
|
|
9628
|
+
method: "get"
|
|
9629
|
+
});
|
|
9630
|
+
return data;
|
|
9631
|
+
} catch (error) {
|
|
9632
|
+
throw error;
|
|
9633
|
+
}
|
|
9634
|
+
};
|
|
9635
|
+
// src/common/ai/302/image/gpt.ts
|
|
9636
|
+
var exports_gpt = {};
|
|
9637
|
+
__export(exports_gpt, {
|
|
9638
|
+
generateImage: () => generateImage2
|
|
9639
|
+
});
|
|
9640
|
+
var generateImage2 = async (params) => {
|
|
9641
|
+
if (params.model === "gpt-4o-plus") {
|
|
9642
|
+
const { data: data2 } = await axios.post("/v1/chat/completions", {
|
|
9643
|
+
model: params.model,
|
|
9644
|
+
messages: [{ role: "user", content: params.prompt }]
|
|
9645
|
+
});
|
|
9646
|
+
const content = data2?.choices?.[0]?.message?.content || "";
|
|
9647
|
+
const urlMatch = content.match(/!\[.*?\]\((.*?)\)/) || content.match(/(https?:\/\/[^\s]+)/);
|
|
9648
|
+
const url = urlMatch ? urlMatch[1] : content;
|
|
9649
|
+
return {
|
|
9650
|
+
background: "",
|
|
9651
|
+
created: data2.created,
|
|
9652
|
+
data: [{ url }],
|
|
9653
|
+
output_format: "",
|
|
9654
|
+
quality: "",
|
|
9655
|
+
size: "",
|
|
9656
|
+
usage: {
|
|
9657
|
+
input_tokens: data2.usage?.prompt_tokens || 0,
|
|
9658
|
+
input_tokens_details: {
|
|
9659
|
+
image_tokens: data2.usage?.prompt_tokens_details?.image_tokens || 0,
|
|
9660
|
+
text_tokens: data2.usage?.prompt_tokens_details?.text_tokens || 0
|
|
9661
|
+
},
|
|
9662
|
+
output_tokens: data2.usage?.completion_tokens || 0,
|
|
9663
|
+
output_tokens_details: {
|
|
9664
|
+
image_tokens: data2.usage?.completion_tokens_details?.image_tokens || 0,
|
|
9665
|
+
text_tokens: data2.usage?.completion_tokens_details?.content_tokens || 0
|
|
9666
|
+
},
|
|
9667
|
+
total_tokens: data2.usage?.total_tokens || 0
|
|
9668
|
+
}
|
|
9669
|
+
};
|
|
9670
|
+
}
|
|
9671
|
+
const { data } = await axios.post("/v1/images/generations", params);
|
|
9672
|
+
return data;
|
|
9673
|
+
};
|
|
9674
|
+
// src/common/ai/doubao/index.ts
|
|
9675
|
+
var exports_doubao2 = {};
|
|
9676
|
+
__export(exports_doubao2, {
|
|
9677
|
+
vc: () => vc,
|
|
9678
|
+
tts: () => tts
|
|
9679
|
+
});
|
|
9680
|
+
|
|
9681
|
+
// src/common/ai/doubao/tts.ts
|
|
9682
|
+
import axios2 from "axios";
|
|
9683
|
+
var createReqid2 = () => {
|
|
9684
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
9685
|
+
return crypto.randomUUID();
|
|
9686
|
+
}
|
|
9687
|
+
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
9688
|
+
};
|
|
9689
|
+
var decodeBase64ToArrayBuffer = (value) => {
|
|
9690
|
+
if (typeof window !== "undefined" && typeof window.atob === "function") {
|
|
9691
|
+
const binary = window.atob(value);
|
|
9692
|
+
const bytes = new Uint8Array(binary.length);
|
|
9693
|
+
for (let i = 0;i < binary.length; i++) {
|
|
9694
|
+
bytes[i] = binary.charCodeAt(i);
|
|
9695
|
+
}
|
|
9696
|
+
return bytes.buffer;
|
|
9697
|
+
}
|
|
9698
|
+
const buf = Buffer.from(value, "base64");
|
|
9699
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
9700
|
+
};
|
|
9701
|
+
var tts = async (params) => {
|
|
9702
|
+
const { app, user, audio, request } = params;
|
|
9703
|
+
const url = "https://openspeech.bytedance.com/api/v3/tts/unidirectional";
|
|
9704
|
+
const reqid = request.reqid || createReqid2();
|
|
9705
|
+
const speechRate = audio.speed_ratio ? Math.round((audio.speed_ratio - 1) * 100) : 0;
|
|
9706
|
+
const loudnessRate = audio.volume_ratio ? Math.round((audio.volume_ratio - 1) * 100) : 0;
|
|
9707
|
+
const headers = {
|
|
9708
|
+
"X-Api-App-Id": app.appid || "",
|
|
9709
|
+
"X-Api-Access-Key": app.accessToken || "",
|
|
9710
|
+
"Content-Type": "application/json",
|
|
9711
|
+
"X-Api-Resource-Id": app.resourceId || "seed-tts-2.0",
|
|
9712
|
+
"X-Api-Request-Id": reqid
|
|
9713
|
+
};
|
|
9714
|
+
const payload = {
|
|
9715
|
+
user: {
|
|
9716
|
+
uid: user?.uid || "uid"
|
|
9717
|
+
},
|
|
9718
|
+
req_params: {
|
|
9719
|
+
text: request.text,
|
|
9720
|
+
speaker: audio.voice_type,
|
|
9721
|
+
audio_params: {
|
|
9722
|
+
format: audio.encoding || "pcm",
|
|
9723
|
+
sample_rate: 24000,
|
|
9724
|
+
speech_rate: speechRate,
|
|
9725
|
+
loudness_rate: loudnessRate,
|
|
9726
|
+
emotion: audio.emotion,
|
|
9727
|
+
emotion_scale: audio.emotion_scale
|
|
9728
|
+
}
|
|
9729
|
+
}
|
|
9730
|
+
};
|
|
9731
|
+
if (audio.context_texts) {
|
|
9732
|
+
payload.req_params.additions = JSON.stringify({
|
|
9733
|
+
context_texts: audio.context_texts
|
|
9734
|
+
});
|
|
9735
|
+
}
|
|
9736
|
+
try {
|
|
9737
|
+
const response = await axios2.post(url, payload, {
|
|
9738
|
+
headers,
|
|
9739
|
+
responseType: "arraybuffer"
|
|
9740
|
+
});
|
|
9741
|
+
const responseText = new TextDecoder().decode(response.data);
|
|
9742
|
+
const jsonObjects = [];
|
|
9743
|
+
let depth = 0;
|
|
9744
|
+
let start = 0;
|
|
9745
|
+
for (let i = 0;i < responseText.length; i++) {
|
|
9746
|
+
if (responseText[i] === "{") {
|
|
9747
|
+
if (depth === 0)
|
|
9748
|
+
start = i;
|
|
9749
|
+
depth++;
|
|
9750
|
+
} else if (responseText[i] === "}") {
|
|
9751
|
+
depth--;
|
|
9752
|
+
if (depth === 0) {
|
|
9753
|
+
try {
|
|
9754
|
+
const jsonStr = responseText.substring(start, i + 1);
|
|
9755
|
+
const jsonObj = JSON.parse(jsonStr);
|
|
9756
|
+
jsonObjects.push(jsonObj);
|
|
9757
|
+
} catch (e) {
|
|
9758
|
+
console.warn("Failed to parse JSON chunk", e);
|
|
9759
|
+
}
|
|
9760
|
+
}
|
|
9761
|
+
}
|
|
9762
|
+
}
|
|
9763
|
+
if (jsonObjects.length === 0) {
|
|
9764
|
+
try {
|
|
9765
|
+
jsonObjects.push(JSON.parse(responseText));
|
|
9766
|
+
} catch (e) {
|
|
9767
|
+
console.error("Doubao TTS Response Parse Error:", responseText);
|
|
9768
|
+
throw new Error("Invalid response format");
|
|
9769
|
+
}
|
|
9770
|
+
}
|
|
9771
|
+
const audioChunks = [];
|
|
9772
|
+
let totalLength = 0;
|
|
9773
|
+
for (const data of jsonObjects) {
|
|
9774
|
+
const code = data.code;
|
|
9775
|
+
const message = data.message;
|
|
9776
|
+
if (typeof code === "number" && code !== 0 && code !== 20000000) {
|
|
9777
|
+
console.error("Doubao TTS Error Response:", JSON.stringify(data, null, 2));
|
|
9778
|
+
const err = new Error(`豆包语音合成失败: ${message} (code: ${code})`);
|
|
9779
|
+
err.code = code;
|
|
9780
|
+
err.reqid = data.reqid;
|
|
9781
|
+
throw err;
|
|
9782
|
+
}
|
|
9783
|
+
if (data.data) {
|
|
9784
|
+
const chunkBuffer = decodeBase64ToArrayBuffer(data.data);
|
|
9785
|
+
audioChunks.push(chunkBuffer);
|
|
9786
|
+
totalLength += chunkBuffer.byteLength;
|
|
9787
|
+
}
|
|
9788
|
+
}
|
|
9789
|
+
if (totalLength === 0) {
|
|
9790
|
+
throw new Error("豆包语音合成失败:未返回音频数据");
|
|
9791
|
+
}
|
|
9792
|
+
const resultBuffer = new Uint8Array(totalLength);
|
|
9793
|
+
let offset = 0;
|
|
9794
|
+
for (const chunk of audioChunks) {
|
|
9795
|
+
resultBuffer.set(new Uint8Array(chunk), offset);
|
|
9796
|
+
offset += chunk.byteLength;
|
|
9797
|
+
}
|
|
9798
|
+
return resultBuffer.buffer;
|
|
9799
|
+
} catch (error) {
|
|
9800
|
+
if (error.response) {
|
|
9801
|
+
try {
|
|
9802
|
+
let errorData = error.response.data;
|
|
9803
|
+
if (errorData instanceof ArrayBuffer || typeof Buffer !== "undefined" && Buffer.isBuffer(errorData)) {
|
|
9804
|
+
errorData = new TextDecoder().decode(errorData);
|
|
9805
|
+
} else if (typeof errorData === "object") {
|
|
9806
|
+
errorData = JSON.stringify(errorData);
|
|
9807
|
+
}
|
|
9808
|
+
throw new Error(`Doubao TTS Error: ${error.response.status} - ${errorData}`);
|
|
9809
|
+
} catch (e) {
|
|
9810
|
+
if (e.message && e.message.startsWith("Doubao TTS Error")) {
|
|
9811
|
+
throw e;
|
|
9812
|
+
}
|
|
9813
|
+
throw new Error(`Doubao TTS Error: ${error.response.status} ${error.message}`);
|
|
9814
|
+
}
|
|
9815
|
+
}
|
|
9816
|
+
throw error;
|
|
9817
|
+
}
|
|
9818
|
+
};
|
|
9819
|
+
// src/common/ai/doubao/vc.ts
|
|
9820
|
+
import axios3 from "axios";
|
|
9821
|
+
var getHeaders = (accessToken, contentType) => {
|
|
9822
|
+
const headers = {
|
|
9823
|
+
Authorization: `Bearer; ${accessToken}`
|
|
9824
|
+
};
|
|
9825
|
+
if (contentType) {
|
|
9826
|
+
headers["content-type"] = contentType;
|
|
9827
|
+
}
|
|
9828
|
+
return headers;
|
|
9829
|
+
};
|
|
9830
|
+
var handleResponse = (data) => {
|
|
9831
|
+
if (data instanceof ArrayBuffer) {
|
|
9832
|
+
return data;
|
|
9833
|
+
}
|
|
9834
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
|
|
9835
|
+
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
9836
|
+
}
|
|
9837
|
+
return data;
|
|
9838
|
+
};
|
|
9839
|
+
var vc = {
|
|
9840
|
+
submit: async (params) => {
|
|
9841
|
+
const { app, audio, options = {} } = params;
|
|
9842
|
+
const url = new URL("https://openspeech.bytedance.com/api/v1/vc/submit");
|
|
9843
|
+
url.searchParams.set("appid", app.appid);
|
|
9844
|
+
Object.entries(options).forEach(([key2, value]) => {
|
|
9845
|
+
if (value !== undefined && value !== null) {
|
|
9846
|
+
url.searchParams.set(key2, String(value));
|
|
9847
|
+
}
|
|
9848
|
+
});
|
|
9849
|
+
const response = await axios3.post(url.toString(), audio.data, {
|
|
9850
|
+
headers: getHeaders(app.accessToken, audio.contentType || "audio/wav"),
|
|
9851
|
+
responseType: "arraybuffer"
|
|
9852
|
+
});
|
|
9853
|
+
return handleResponse(response.data);
|
|
9854
|
+
},
|
|
9855
|
+
query: async (params) => {
|
|
9856
|
+
const { app, id, blocking } = params;
|
|
9857
|
+
const url = new URL("https://openspeech.bytedance.com/api/v1/vc/query");
|
|
9858
|
+
url.searchParams.set("appid", app.appid);
|
|
9859
|
+
url.searchParams.set("id", id);
|
|
9860
|
+
if (blocking !== undefined) {
|
|
9861
|
+
url.searchParams.set("blocking", String(blocking));
|
|
9862
|
+
}
|
|
9863
|
+
const response = await axios3.get(url.toString(), {
|
|
9864
|
+
headers: getHeaders(app.accessToken),
|
|
9865
|
+
responseType: "arraybuffer"
|
|
9866
|
+
});
|
|
9867
|
+
return handleResponse(response.data);
|
|
9868
|
+
}
|
|
9869
|
+
};
|
|
9870
|
+
// src/common/ai/keling/index.ts
|
|
9871
|
+
var exports_keling = {};
|
|
9872
|
+
__export(exports_keling, {
|
|
9873
|
+
setCookie: () => setCookie,
|
|
9874
|
+
getVideoStatus: () => getVideoStatus,
|
|
9875
|
+
generateVideo: () => generateVideo
|
|
9876
|
+
});
|
|
9877
|
+
|
|
9878
|
+
// src/common/ai/keling/utils.ts
|
|
9879
|
+
import * as url from "url";
|
|
9880
|
+
import * as path from "path";
|
|
9881
|
+
|
|
9882
|
+
// src/common/ai/keling/axios.ts
|
|
9883
|
+
import axios_2 from "axios";
|
|
9884
|
+
var axios4 = axios_2.create({
|
|
9885
|
+
headers: {
|
|
9886
|
+
"Content-Type": "application/json",
|
|
9887
|
+
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"
|
|
9888
|
+
}
|
|
9889
|
+
});
|
|
9890
|
+
|
|
9891
|
+
// src/common/ai/keling/utils.ts
|
|
9892
|
+
var getToken = async (filename) => {
|
|
9893
|
+
try {
|
|
9894
|
+
const response = await axios4.get("https://klingai.kuaishou.com/api/upload/issue/token", {
|
|
9895
|
+
params: { filename }
|
|
9896
|
+
});
|
|
9897
|
+
return response.data.data.token;
|
|
9898
|
+
} catch (error) {
|
|
9899
|
+
console.error("获取 token 失败:", error);
|
|
9900
|
+
throw error;
|
|
9901
|
+
}
|
|
9902
|
+
};
|
|
9903
|
+
var uploadFragment = async (uploadToken, imageBuffer) => {
|
|
9904
|
+
try {
|
|
9905
|
+
const response = await axios4.post("https://upload.kuaishouzt.com/api/upload/fragment", imageBuffer, {
|
|
9906
|
+
params: {
|
|
9907
|
+
upload_token: uploadToken,
|
|
9908
|
+
fragment_id: 0
|
|
9909
|
+
},
|
|
9910
|
+
headers: {
|
|
9911
|
+
"Content-Type": "application/octet-stream"
|
|
9912
|
+
}
|
|
9913
|
+
});
|
|
9914
|
+
return response.data;
|
|
9915
|
+
} catch (error) {
|
|
9916
|
+
console.error("上传片段失败:", error);
|
|
9917
|
+
throw error;
|
|
9918
|
+
}
|
|
9919
|
+
};
|
|
9920
|
+
var completeUpload = async (uploadToken) => {
|
|
9921
|
+
try {
|
|
9922
|
+
const response = await axios4.post("https://upload.kuaishouzt.com/api/upload/complete", null, {
|
|
9923
|
+
params: {
|
|
9924
|
+
upload_token: uploadToken,
|
|
9925
|
+
fragment_count: 1
|
|
9926
|
+
}
|
|
9927
|
+
});
|
|
9928
|
+
return response.data;
|
|
9929
|
+
} catch (error) {
|
|
9930
|
+
console.error("完成上传失败:", error);
|
|
9931
|
+
throw error;
|
|
9932
|
+
}
|
|
9933
|
+
};
|
|
9934
|
+
var verifyUpload = async (token) => {
|
|
9935
|
+
try {
|
|
9936
|
+
const response = await axios4.get("https://klingai.kuaishou.com/api/upload/verify/token", {
|
|
9937
|
+
params: { token }
|
|
9938
|
+
});
|
|
9939
|
+
if (response.data?.result === 1 && response.data?.data?.status === 3) {
|
|
9940
|
+
return response.data.data?.url;
|
|
9941
|
+
} else {
|
|
9942
|
+
throw new Error(`上传验证失败: ${response.data.message}`);
|
|
9943
|
+
}
|
|
9944
|
+
} catch (error) {
|
|
9945
|
+
console.error("获取上传结果失败:", error);
|
|
9946
|
+
throw error;
|
|
9947
|
+
}
|
|
9948
|
+
};
|
|
9949
|
+
var downloadImage = async (imageUrl) => {
|
|
9950
|
+
try {
|
|
9951
|
+
const response = await axios4.get(imageUrl, {
|
|
9952
|
+
responseType: "arraybuffer"
|
|
9953
|
+
});
|
|
9954
|
+
return Buffer.from(response.data, "binary");
|
|
9955
|
+
} catch (error) {
|
|
9956
|
+
console.error("下载图片失败:", error);
|
|
9957
|
+
throw error;
|
|
9958
|
+
}
|
|
9959
|
+
};
|
|
9960
|
+
var uploadImage = async (imageUrl) => {
|
|
9961
|
+
try {
|
|
9962
|
+
const parsedUrl = url.parse(imageUrl);
|
|
9963
|
+
if (!parsedUrl.pathname) {
|
|
9964
|
+
return;
|
|
9965
|
+
}
|
|
9966
|
+
const filename = path.basename(parsedUrl.pathname);
|
|
9967
|
+
const imageBuffer = await downloadImage(imageUrl);
|
|
9968
|
+
const token = await getToken(filename);
|
|
9969
|
+
await uploadFragment(token, imageBuffer);
|
|
9970
|
+
await completeUpload(token);
|
|
9971
|
+
return await verifyUpload(token);
|
|
9972
|
+
} catch (error) {
|
|
9973
|
+
console.error("上传图片失败:", error);
|
|
9974
|
+
throw error;
|
|
9975
|
+
}
|
|
9976
|
+
};
|
|
9977
|
+
var sbumit = async (imageUrl, prompt) => {
|
|
9978
|
+
try {
|
|
9979
|
+
var data = JSON.stringify({
|
|
9980
|
+
arguments: [
|
|
9981
|
+
{
|
|
9982
|
+
name: "prompt",
|
|
9983
|
+
value: prompt || ""
|
|
9984
|
+
},
|
|
9985
|
+
{
|
|
9986
|
+
name: "negative_prompt",
|
|
9987
|
+
value: "闪烁、动画、模糊、变形、毁容、低质量、拼贴、颗粒状、抽象、计算机生成、扭曲"
|
|
9988
|
+
},
|
|
9989
|
+
{
|
|
9990
|
+
name: "cfg",
|
|
9991
|
+
value: "0.5"
|
|
9992
|
+
},
|
|
9993
|
+
{
|
|
9994
|
+
name: "duration",
|
|
9995
|
+
value: "5"
|
|
9996
|
+
},
|
|
9997
|
+
{
|
|
9998
|
+
name: "imageCount",
|
|
9999
|
+
value: "1"
|
|
10000
|
+
},
|
|
10001
|
+
{
|
|
10002
|
+
name: "kling_version",
|
|
10003
|
+
value: "1.5"
|
|
10004
|
+
},
|
|
10005
|
+
{
|
|
10006
|
+
name: "tail_image_enabled",
|
|
10007
|
+
value: "false"
|
|
10008
|
+
},
|
|
10009
|
+
{
|
|
10010
|
+
name: "camera_json",
|
|
10011
|
+
value: '{"type":"empty","horizontal":0,"vertical":0,"zoom":0,"tilt":0,"pan":0,"roll":0}'
|
|
10012
|
+
},
|
|
10013
|
+
{
|
|
10014
|
+
name: "camera_control_enabled",
|
|
10015
|
+
value: "false"
|
|
10016
|
+
},
|
|
10017
|
+
{
|
|
10018
|
+
name: "biz",
|
|
10019
|
+
value: "klingai"
|
|
10020
|
+
}
|
|
10021
|
+
],
|
|
10022
|
+
inputs: [
|
|
10023
|
+
{
|
|
10024
|
+
inputType: "URL",
|
|
10025
|
+
url: imageUrl,
|
|
10026
|
+
name: "input"
|
|
10027
|
+
}
|
|
10028
|
+
],
|
|
10029
|
+
type: "m2v_img2video_hq"
|
|
10030
|
+
});
|
|
10031
|
+
const response = await axios4({
|
|
10032
|
+
method: "POST",
|
|
10033
|
+
url: "https://klingai.kuaishou.com/api/task/submit",
|
|
10034
|
+
data
|
|
10035
|
+
});
|
|
10036
|
+
return response.data?.data?.task?.id;
|
|
10037
|
+
} catch (error) {
|
|
10038
|
+
console.error("完成上传失败:", error);
|
|
10039
|
+
throw error;
|
|
10040
|
+
}
|
|
10041
|
+
};
|
|
10042
|
+
var calculateProgress = (taskData) => {
|
|
10043
|
+
const createTime = taskData?.task?.createTime;
|
|
10044
|
+
const etaTime = taskData?.etaTime;
|
|
10045
|
+
const currentTime = Date.now();
|
|
10046
|
+
if (!createTime || !etaTime) {
|
|
10047
|
+
return 0;
|
|
10048
|
+
}
|
|
10049
|
+
const totalTimeSpan = etaTime - createTime;
|
|
10050
|
+
const timeElapsed = currentTime - createTime;
|
|
10051
|
+
if (totalTimeSpan <= 0) {
|
|
10052
|
+
return 0;
|
|
10053
|
+
}
|
|
10054
|
+
let progressRatio = timeElapsed / totalTimeSpan;
|
|
10055
|
+
if (progressRatio >= 1) {
|
|
10056
|
+
progressRatio = 0.99;
|
|
10057
|
+
}
|
|
10058
|
+
return progressRatio;
|
|
10059
|
+
};
|
|
10060
|
+
var setCookie = (newCookieValue) => {
|
|
10061
|
+
axios4.defaults.headers.Cookie = newCookieValue;
|
|
10062
|
+
};
|
|
10063
|
+
|
|
10064
|
+
// src/common/ai/keling/index.ts
|
|
10065
|
+
var getVideoStatus = async (taskId) => {
|
|
10066
|
+
if (!taskId) {
|
|
10067
|
+
return;
|
|
10068
|
+
}
|
|
10069
|
+
try {
|
|
10070
|
+
const response = await axios4.get("https://klingai.kuaishou.com/api/task/status", {
|
|
10071
|
+
params: { taskId }
|
|
10072
|
+
});
|
|
10073
|
+
return {
|
|
10074
|
+
status: response.data?.data?.status,
|
|
10075
|
+
url: response.data?.data?.works?.[0]?.resource?.resource,
|
|
10076
|
+
cover: response.data?.data?.works?.[0]?.cover?.resource,
|
|
10077
|
+
progress: calculateProgress(response.data?.data) * 100
|
|
10078
|
+
};
|
|
10079
|
+
} catch (error) {
|
|
10080
|
+
console.error("获取 status 失败:", error);
|
|
10081
|
+
throw error;
|
|
10082
|
+
}
|
|
10083
|
+
};
|
|
10084
|
+
var generateVideo = async (imageUrl, prompt) => {
|
|
10085
|
+
const uploadedUrl = await uploadImage(imageUrl);
|
|
10086
|
+
console.log("图片上传成功,URL:", uploadedUrl);
|
|
10087
|
+
const taskId = await sbumit(uploadedUrl, prompt);
|
|
10088
|
+
console.log(666, "任务 id", taskId);
|
|
10089
|
+
return taskId;
|
|
10090
|
+
};
|
|
10091
|
+
// src/common/base/string.ts
|
|
9424
10092
|
var getChineseByStr = (str) => {
|
|
9425
10093
|
if (!str) {
|
|
9426
10094
|
return "";
|
|
@@ -9515,9 +10183,9 @@ var getChinese = (str) => {
|
|
|
9515
10183
|
var getSliceStr = (str, before, after) => {
|
|
9516
10184
|
return str.slice(str.indexOf(before) + before.length, str.lastIndexOf(after));
|
|
9517
10185
|
};
|
|
9518
|
-
var getProxyUrl = (
|
|
10186
|
+
var getProxyUrl = (url2) => {
|
|
9519
10187
|
const beforeUrl = "https://1141871752167714.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/a.LATEST/proxy/?url=";
|
|
9520
|
-
return beforeUrl +
|
|
10188
|
+
return beforeUrl + url2;
|
|
9521
10189
|
};
|
|
9522
10190
|
var getLength = (value) => {
|
|
9523
10191
|
const chineseLength = getChinese(value).length;
|
|
@@ -9563,54 +10231,7 @@ var generateUniqueFileName = (name) => {
|
|
|
9563
10231
|
}
|
|
9564
10232
|
throw new Error("Invalid filename format.");
|
|
9565
10233
|
};
|
|
9566
|
-
|
|
9567
|
-
var findItem = (list, attr, value) => {
|
|
9568
|
-
return list.find((item) => value === undefined ? item[attr] : item[attr] === value);
|
|
9569
|
-
};
|
|
9570
|
-
var filterParams = (params, deep = false) => {
|
|
9571
|
-
const clean = (value) => {
|
|
9572
|
-
if (value === undefined || value === null) {
|
|
9573
|
-
return;
|
|
9574
|
-
}
|
|
9575
|
-
if (!deep) {
|
|
9576
|
-
return value;
|
|
9577
|
-
}
|
|
9578
|
-
if (Array.isArray(value)) {
|
|
9579
|
-
return value.map((v) => clean(v)).filter((v) => v !== undefined);
|
|
9580
|
-
}
|
|
9581
|
-
if (typeof value === "object") {
|
|
9582
|
-
return Object.entries(value).reduce((acc, [k, v]) => {
|
|
9583
|
-
const cleaned = clean(v);
|
|
9584
|
-
if (cleaned !== undefined)
|
|
9585
|
-
acc[k] = cleaned;
|
|
9586
|
-
return acc;
|
|
9587
|
-
}, {});
|
|
9588
|
-
}
|
|
9589
|
-
return value;
|
|
9590
|
-
};
|
|
9591
|
-
return clean(params);
|
|
9592
|
-
};
|
|
9593
|
-
var watch = {
|
|
9594
|
-
observe(obj, key, watchFun) {
|
|
9595
|
-
const val = obj[key];
|
|
9596
|
-
Object.defineProperty(obj, key, {
|
|
9597
|
-
configurable: true,
|
|
9598
|
-
enumerable: true,
|
|
9599
|
-
set(value) {
|
|
9600
|
-
obj[key] = value;
|
|
9601
|
-
watchFun(value, val);
|
|
9602
|
-
},
|
|
9603
|
-
get() {
|
|
9604
|
-
return val;
|
|
9605
|
-
}
|
|
9606
|
-
});
|
|
9607
|
-
},
|
|
9608
|
-
setWatcher(data = {}, watch2 = {}) {
|
|
9609
|
-
Object.keys(watch2).forEach((v) => {
|
|
9610
|
-
this.observe(data, v, watch2[v]);
|
|
9611
|
-
});
|
|
9612
|
-
}
|
|
9613
|
-
};
|
|
10234
|
+
|
|
9614
10235
|
// ../../node_modules/decimal.js/decimal.mjs
|
|
9615
10236
|
/*!
|
|
9616
10237
|
* decimal.js v10.6.0
|
|
@@ -11924,18 +12545,18 @@ LN10 = new Decimal(LN10);
|
|
|
11924
12545
|
PI = new Decimal(PI);
|
|
11925
12546
|
var decimal_default = Decimal;
|
|
11926
12547
|
|
|
11927
|
-
// src/common/other.ts
|
|
12548
|
+
// src/common/base/other.ts
|
|
11928
12549
|
var delay = (time = 1000) => {
|
|
11929
12550
|
return new Promise((resolve) => setTimeout(resolve, time));
|
|
11930
12551
|
};
|
|
11931
12552
|
var calcJsText = (expr, context) => {
|
|
11932
12553
|
const keys = Object.keys(context);
|
|
11933
|
-
const values = keys.map((
|
|
12554
|
+
const values = keys.map((key2) => context[key2]);
|
|
11934
12555
|
return Function(...keys, `return (${expr})`)(...values);
|
|
11935
12556
|
};
|
|
11936
|
-
var optionsToEnum = (options, text,
|
|
12557
|
+
var optionsToEnum = (options, text, key2) => {
|
|
11937
12558
|
return options.reduce((acc, cur) => {
|
|
11938
|
-
acc[cur[
|
|
12559
|
+
acc[cur[key2]] = {
|
|
11939
12560
|
text: cur[text]
|
|
11940
12561
|
};
|
|
11941
12562
|
return acc;
|
|
@@ -11966,13 +12587,13 @@ var performDecimalOperation = (num1, num2, operator) => {
|
|
|
11966
12587
|
return NaN;
|
|
11967
12588
|
}
|
|
11968
12589
|
};
|
|
11969
|
-
var printConsoleLog = (type,
|
|
12590
|
+
var printConsoleLog = (type, path2, params, response) => {
|
|
11970
12591
|
const styles = {
|
|
11971
12592
|
header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
|
|
11972
12593
|
value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
|
|
11973
12594
|
separator: "color: #409EFF; margin: 0 4px;"
|
|
11974
12595
|
};
|
|
11975
|
-
console.groupCollapsed(`666 %c${type}%c${
|
|
12596
|
+
console.groupCollapsed(`666 %c${type}%c${path2}`, styles.header, styles.value);
|
|
11976
12597
|
if (params) {
|
|
11977
12598
|
console.table(params);
|
|
11978
12599
|
}
|
|
@@ -11981,7 +12602,59 @@ var printConsoleLog = (type, path, params, response) => {
|
|
|
11981
12602
|
}
|
|
11982
12603
|
console.groupEnd();
|
|
11983
12604
|
};
|
|
11984
|
-
|
|
12605
|
+
|
|
12606
|
+
// src/common/base/array.ts
|
|
12607
|
+
var shuffleArray = (array) => {
|
|
12608
|
+
const shuffledArray = [...array];
|
|
12609
|
+
for (let i = shuffledArray.length - 1;i > 0; i--) {
|
|
12610
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
12611
|
+
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
|
|
12612
|
+
}
|
|
12613
|
+
return shuffledArray;
|
|
12614
|
+
};
|
|
12615
|
+
var removeSimilarDuplicates = (arr, threshold, isLog) => {
|
|
12616
|
+
const uniqueArray = [];
|
|
12617
|
+
const similarPairs = [];
|
|
12618
|
+
for (const str of arr) {
|
|
12619
|
+
const isSimilar = uniqueArray.some((uniqueStr) => {
|
|
12620
|
+
const distance = levenshteinDistance(str, uniqueStr);
|
|
12621
|
+
if (distance <= threshold) {
|
|
12622
|
+
similarPairs.push([str, uniqueStr]);
|
|
12623
|
+
return true;
|
|
12624
|
+
}
|
|
12625
|
+
return false;
|
|
12626
|
+
});
|
|
12627
|
+
if (!isSimilar) {
|
|
12628
|
+
uniqueArray.push(str);
|
|
12629
|
+
}
|
|
12630
|
+
}
|
|
12631
|
+
if (isLog) {
|
|
12632
|
+
if (similarPairs.length > 0) {
|
|
12633
|
+
similarPairs.forEach((pair) => {
|
|
12634
|
+
console.log(pair[0]);
|
|
12635
|
+
console.log(pair[1]);
|
|
12636
|
+
console.log();
|
|
12637
|
+
});
|
|
12638
|
+
} else {
|
|
12639
|
+
console.log("没有找到类似的字符串");
|
|
12640
|
+
}
|
|
12641
|
+
}
|
|
12642
|
+
return uniqueArray;
|
|
12643
|
+
};
|
|
12644
|
+
var getTotal = (arr, key2) => {
|
|
12645
|
+
if (!Array.isArray(arr) || !key2) {
|
|
12646
|
+
return 0;
|
|
12647
|
+
}
|
|
12648
|
+
return arr.reduce((total, item) => {
|
|
12649
|
+
const itemValue = Number(item[key2]);
|
|
12650
|
+
if (!isNaN(itemValue)) {
|
|
12651
|
+
return performDecimalOperation(total, itemValue, "+");
|
|
12652
|
+
}
|
|
12653
|
+
return total;
|
|
12654
|
+
}, 0);
|
|
12655
|
+
};
|
|
12656
|
+
|
|
12657
|
+
// src/common/base/number.ts
|
|
11985
12658
|
var getRandomNum = (min2, max2) => {
|
|
11986
12659
|
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
11987
12660
|
};
|
|
@@ -12023,70 +12696,77 @@ var numberWithCommas = (x) => {
|
|
|
12023
12696
|
}
|
|
12024
12697
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
12025
12698
|
};
|
|
12026
|
-
|
|
12027
|
-
|
|
12028
|
-
|
|
12029
|
-
|
|
12030
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
12031
|
-
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
|
|
12032
|
-
}
|
|
12033
|
-
return shuffledArray;
|
|
12699
|
+
|
|
12700
|
+
// src/common/base/object.ts
|
|
12701
|
+
var findItem = (list, attr, value) => {
|
|
12702
|
+
return list.find((item) => value === undefined ? item[attr] : item[attr] === value);
|
|
12034
12703
|
};
|
|
12035
|
-
var
|
|
12036
|
-
const
|
|
12037
|
-
|
|
12038
|
-
|
|
12039
|
-
const isSimilar = uniqueArray.some((uniqueStr) => {
|
|
12040
|
-
const distance = levenshteinDistance(str, uniqueStr);
|
|
12041
|
-
if (distance <= threshold) {
|
|
12042
|
-
similarPairs.push([str, uniqueStr]);
|
|
12043
|
-
return true;
|
|
12044
|
-
}
|
|
12045
|
-
return false;
|
|
12046
|
-
});
|
|
12047
|
-
if (!isSimilar) {
|
|
12048
|
-
uniqueArray.push(str);
|
|
12704
|
+
var filterParams = (params, deep = false) => {
|
|
12705
|
+
const clean = (value) => {
|
|
12706
|
+
if (value === undefined || value === null) {
|
|
12707
|
+
return;
|
|
12049
12708
|
}
|
|
12050
|
-
|
|
12051
|
-
|
|
12052
|
-
if (similarPairs.length > 0) {
|
|
12053
|
-
similarPairs.forEach((pair) => {
|
|
12054
|
-
console.log(pair[0]);
|
|
12055
|
-
console.log(pair[1]);
|
|
12056
|
-
console.log();
|
|
12057
|
-
});
|
|
12058
|
-
} else {
|
|
12059
|
-
console.log("没有找到类似的字符串");
|
|
12709
|
+
if (!deep) {
|
|
12710
|
+
return value;
|
|
12060
12711
|
}
|
|
12061
|
-
|
|
12062
|
-
|
|
12712
|
+
if (Array.isArray(value)) {
|
|
12713
|
+
return value.map((v) => clean(v)).filter((v) => v !== undefined);
|
|
12714
|
+
}
|
|
12715
|
+
if (typeof value === "object") {
|
|
12716
|
+
return Object.entries(value).reduce((acc, [k, v]) => {
|
|
12717
|
+
const cleaned = clean(v);
|
|
12718
|
+
if (cleaned !== undefined)
|
|
12719
|
+
acc[k] = cleaned;
|
|
12720
|
+
return acc;
|
|
12721
|
+
}, {});
|
|
12722
|
+
}
|
|
12723
|
+
return value;
|
|
12724
|
+
};
|
|
12725
|
+
return clean(params);
|
|
12063
12726
|
};
|
|
12064
|
-
var
|
|
12065
|
-
|
|
12066
|
-
|
|
12727
|
+
var watch = {
|
|
12728
|
+
observe(obj, key2, watchFun) {
|
|
12729
|
+
const val = obj[key2];
|
|
12730
|
+
Object.defineProperty(obj, key2, {
|
|
12731
|
+
configurable: true,
|
|
12732
|
+
enumerable: true,
|
|
12733
|
+
set(value) {
|
|
12734
|
+
obj[key2] = value;
|
|
12735
|
+
watchFun(value, val);
|
|
12736
|
+
},
|
|
12737
|
+
get() {
|
|
12738
|
+
return val;
|
|
12739
|
+
}
|
|
12740
|
+
});
|
|
12741
|
+
},
|
|
12742
|
+
setWatcher(data = {}, watch2 = {}) {
|
|
12743
|
+
Object.keys(watch2).forEach((v) => {
|
|
12744
|
+
this.observe(data, v, watch2[v]);
|
|
12745
|
+
});
|
|
12067
12746
|
}
|
|
12068
|
-
return arr.reduce((total, item) => {
|
|
12069
|
-
const itemValue = Number(item[key]);
|
|
12070
|
-
if (!isNaN(itemValue)) {
|
|
12071
|
-
return performDecimalOperation(total, itemValue, "+");
|
|
12072
|
-
}
|
|
12073
|
-
return total;
|
|
12074
|
-
}, 0);
|
|
12075
12747
|
};
|
|
12076
|
-
|
|
12077
|
-
|
|
12078
|
-
async
|
|
12748
|
+
|
|
12749
|
+
// src/common/base/promise.ts
|
|
12750
|
+
var executePromise = async (promise) => {
|
|
12751
|
+
const start = Date.now();
|
|
12752
|
+
const result = await promise;
|
|
12753
|
+
const time = Date.now() - start;
|
|
12754
|
+
return {
|
|
12755
|
+
result,
|
|
12756
|
+
time
|
|
12757
|
+
};
|
|
12758
|
+
};
|
|
12759
|
+
var retryPromise = async (promiseFn, retryInterval = 1000, retryCount = 3) => {
|
|
12079
12760
|
try {
|
|
12080
|
-
|
|
12081
|
-
responseType: "arraybuffer"
|
|
12082
|
-
});
|
|
12083
|
-
const base64String = Buffer.from(response.data).toString("base64");
|
|
12084
|
-
return `data:image/*;base64,${base64String}`;
|
|
12761
|
+
return await promiseFn();
|
|
12085
12762
|
} catch (error) {
|
|
12086
|
-
|
|
12087
|
-
|
|
12763
|
+
if (retryCount <= 0) {
|
|
12764
|
+
throw error;
|
|
12765
|
+
}
|
|
12766
|
+
await new Promise((resolve) => setTimeout(resolve, retryInterval));
|
|
12767
|
+
return retryPromise(promiseFn, retryCount - 1, retryInterval);
|
|
12088
12768
|
}
|
|
12089
|
-
}
|
|
12769
|
+
};
|
|
12090
12770
|
// src/common/enum.ts
|
|
12091
12771
|
class EnumItem {
|
|
12092
12772
|
label;
|
|
@@ -12107,8 +12787,8 @@ var Enum = {
|
|
|
12107
12787
|
const extras = new Map;
|
|
12108
12788
|
const labels = new Map;
|
|
12109
12789
|
const enums = {};
|
|
12110
|
-
for (const
|
|
12111
|
-
const member = members[
|
|
12790
|
+
for (const key2 in members) {
|
|
12791
|
+
const member = members[key2];
|
|
12112
12792
|
if (!member)
|
|
12113
12793
|
continue;
|
|
12114
12794
|
if (usedValues.has(member.value)) {
|
|
@@ -12116,7 +12796,7 @@ var Enum = {
|
|
|
12116
12796
|
}
|
|
12117
12797
|
usedValues.add(member.value);
|
|
12118
12798
|
const item = new EnumItem(member);
|
|
12119
|
-
enumObj[
|
|
12799
|
+
enumObj[key2] = item;
|
|
12120
12800
|
map.set(item.value, item);
|
|
12121
12801
|
labels.set(item.value, item.label);
|
|
12122
12802
|
options.push(item);
|
|
@@ -12134,6 +12814,20 @@ var Enum = {
|
|
|
12134
12814
|
return enumObj;
|
|
12135
12815
|
}
|
|
12136
12816
|
};
|
|
12817
|
+
// src/common/image.ts
|
|
12818
|
+
import axios5 from "axios";
|
|
12819
|
+
async function imageToBase64(url2) {
|
|
12820
|
+
try {
|
|
12821
|
+
const response = await axios5.get(url2, {
|
|
12822
|
+
responseType: "arraybuffer"
|
|
12823
|
+
});
|
|
12824
|
+
const base64String = Buffer.from(response.data).toString("base64");
|
|
12825
|
+
return `data:image/*;base64,${base64String}`;
|
|
12826
|
+
} catch (error) {
|
|
12827
|
+
console.error("Failed to fetch the image:", error);
|
|
12828
|
+
throw error;
|
|
12829
|
+
}
|
|
12830
|
+
}
|
|
12137
12831
|
// src/common/dayjs.ts
|
|
12138
12832
|
import dayjs from "dayjs";
|
|
12139
12833
|
import isBetween from "dayjs/plugin/isBetween";
|
|
@@ -12174,51 +12868,7 @@ var initChinaDayjs = () => {
|
|
|
12174
12868
|
};
|
|
12175
12869
|
var chinaDayjs = initChinaDayjs();
|
|
12176
12870
|
var dayjs_default = dayjs;
|
|
12177
|
-
// src/
|
|
12178
|
-
var exports_302 = {};
|
|
12179
|
-
__export(exports_302, {
|
|
12180
|
-
chat: () => chat
|
|
12181
|
-
});
|
|
12182
|
-
|
|
12183
|
-
// src/ai/302/axios.ts
|
|
12184
|
-
import axios_ from "axios";
|
|
12185
|
-
var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
|
|
12186
|
-
var axios2 = axios_.create({
|
|
12187
|
-
baseURL: "https://api.302.ai",
|
|
12188
|
-
headers: {
|
|
12189
|
-
"mj-api-secret": key,
|
|
12190
|
-
Authorization: `Bearer ${key}`
|
|
12191
|
-
}
|
|
12192
|
-
});
|
|
12193
|
-
|
|
12194
|
-
// src/ai/302/chat/index.ts
|
|
12195
|
-
import json5 from "json5";
|
|
12196
|
-
var chat = async (message, model = "gpt-4.1", isParse = true) => {
|
|
12197
|
-
try {
|
|
12198
|
-
let { data } = await axios2({
|
|
12199
|
-
url: "/v1/chat/completions",
|
|
12200
|
-
method: "post",
|
|
12201
|
-
data: {
|
|
12202
|
-
model,
|
|
12203
|
-
message
|
|
12204
|
-
}
|
|
12205
|
-
});
|
|
12206
|
-
console.log(666, typeof data, data);
|
|
12207
|
-
const output = typeof data === "string" ? json5.parse(data)?.output : data?.output;
|
|
12208
|
-
if (isParse) {
|
|
12209
|
-
const match = /```(json)?(.*)```/s.exec(output);
|
|
12210
|
-
if (!match) {
|
|
12211
|
-
return json5.parse(output);
|
|
12212
|
-
} else {
|
|
12213
|
-
return json5.parse(match[2]);
|
|
12214
|
-
}
|
|
12215
|
-
}
|
|
12216
|
-
return output;
|
|
12217
|
-
} catch (error) {
|
|
12218
|
-
throw new Error(error?.response?.statusText || error?.message || "未知原因");
|
|
12219
|
-
}
|
|
12220
|
-
};
|
|
12221
|
-
// src/node/mail/index.ts
|
|
12871
|
+
// src/node/mail.ts
|
|
12222
12872
|
import nodemailer from "nodemailer";
|
|
12223
12873
|
var authMap = {
|
|
12224
12874
|
163: {
|
|
@@ -12242,11 +12892,11 @@ var sendMail = (config2) => {
|
|
|
12242
12892
|
...config2
|
|
12243
12893
|
});
|
|
12244
12894
|
};
|
|
12245
|
-
// src/node/file
|
|
12895
|
+
// src/node/file.ts
|
|
12246
12896
|
import fs from "fs-extra";
|
|
12247
|
-
import
|
|
12248
|
-
import
|
|
12249
|
-
import * as
|
|
12897
|
+
import axios6 from "axios";
|
|
12898
|
+
import url2 from "url";
|
|
12899
|
+
import * as path2 from "path";
|
|
12250
12900
|
var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
12251
12901
|
try {
|
|
12252
12902
|
const data = await fs.readFile(filePath, "utf8");
|
|
@@ -12268,15 +12918,15 @@ var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
|
12268
12918
|
};
|
|
12269
12919
|
var downloadFile = async (httpUrl, outputPath) => {
|
|
12270
12920
|
try {
|
|
12271
|
-
let parsedUrl =
|
|
12272
|
-
let fileName =
|
|
12921
|
+
let parsedUrl = url2.parse(httpUrl);
|
|
12922
|
+
let fileName = path2.basename(parsedUrl.pathname);
|
|
12273
12923
|
if (!outputPath) {
|
|
12274
12924
|
if (!fs.existsSync(".tmp")) {
|
|
12275
12925
|
fs.mkdirSync(".tmp", { recursive: true });
|
|
12276
12926
|
}
|
|
12277
12927
|
outputPath = ".tmp/" + decodeURIComponent(fileName);
|
|
12278
12928
|
}
|
|
12279
|
-
const response = await
|
|
12929
|
+
const response = await axios6({
|
|
12280
12930
|
url: httpUrl,
|
|
12281
12931
|
method: "get",
|
|
12282
12932
|
responseType: "stream"
|
|
@@ -12293,11 +12943,11 @@ var downloadFile = async (httpUrl, outputPath) => {
|
|
|
12293
12943
|
throw error;
|
|
12294
12944
|
}
|
|
12295
12945
|
};
|
|
12296
|
-
// src/node/oss
|
|
12946
|
+
// src/node/oss.ts
|
|
12297
12947
|
import OSS from "ali-oss";
|
|
12298
|
-
import
|
|
12948
|
+
import axios7 from "axios";
|
|
12299
12949
|
import fs2 from "fs-extra";
|
|
12300
|
-
import * as
|
|
12950
|
+
import * as path3 from "path";
|
|
12301
12951
|
var oss = new OSS({
|
|
12302
12952
|
region: process.env.VITE_OSS_REGION,
|
|
12303
12953
|
accessKeyId: process.env.VITE_OSS_ACCESS_KEY_ID,
|
|
@@ -12310,14 +12960,14 @@ async function uploadFile(file, filename) {
|
|
|
12310
12960
|
if (typeof file === "string") {
|
|
12311
12961
|
if (/^https?:\/\//.test(file)) {
|
|
12312
12962
|
try {
|
|
12313
|
-
const response = await
|
|
12963
|
+
const response = await axios7.get(file, { responseType: "arraybuffer" });
|
|
12314
12964
|
buffer = Buffer.from(response.data);
|
|
12315
12965
|
} catch (error) {
|
|
12316
12966
|
throw new Error(`无法从 URL 下载文件: ${error}`);
|
|
12317
12967
|
}
|
|
12318
|
-
const originalName =
|
|
12319
|
-
const ext =
|
|
12320
|
-
const nameWithoutExt =
|
|
12968
|
+
const originalName = path3.basename(new URL(file).pathname);
|
|
12969
|
+
const ext = path3.extname(originalName);
|
|
12970
|
+
const nameWithoutExt = path3.basename(originalName, ext);
|
|
12321
12971
|
finalFilename = `${nameWithoutExt}_${Date.now()}${ext}`;
|
|
12322
12972
|
} else {
|
|
12323
12973
|
try {
|
|
@@ -12325,9 +12975,9 @@ async function uploadFile(file, filename) {
|
|
|
12325
12975
|
} catch (error) {
|
|
12326
12976
|
throw new Error(`无法读取文件路径: ${error}`);
|
|
12327
12977
|
}
|
|
12328
|
-
const originalName =
|
|
12329
|
-
const ext =
|
|
12330
|
-
const nameWithoutExt =
|
|
12978
|
+
const originalName = path3.basename(file);
|
|
12979
|
+
const ext = path3.extname(originalName);
|
|
12980
|
+
const nameWithoutExt = path3.basename(originalName, ext);
|
|
12331
12981
|
finalFilename = `${nameWithoutExt}_${Date.now()}${ext}`;
|
|
12332
12982
|
}
|
|
12333
12983
|
} else if (Buffer.isBuffer(file)) {
|
|
@@ -12350,7 +13000,7 @@ async function uploadFile(file, filename) {
|
|
|
12350
13000
|
throw new Error(`上传到 OSS 失败: ${error}`);
|
|
12351
13001
|
}
|
|
12352
13002
|
}
|
|
12353
|
-
// src/node/cron
|
|
13003
|
+
// src/node/cron.ts
|
|
12354
13004
|
import cron from "node-cron";
|
|
12355
13005
|
var interval = (intervalMinutes, immediately, fn) => {
|
|
12356
13006
|
console.log(`定时任务已启动,将每${intervalMinutes}分钟执行一次`);
|
|
@@ -12372,10 +13022,6 @@ var schedule = (cronExpression, immediately, fn) => {
|
|
|
12372
13022
|
timezone: "Asia/Shanghai"
|
|
12373
13023
|
});
|
|
12374
13024
|
};
|
|
12375
|
-
|
|
12376
|
-
// src/node/index.ts
|
|
12377
|
-
import { default as default6, DataStoreOptions } from "nedb";
|
|
12378
|
-
import * as cheerio from "cheerio";
|
|
12379
13025
|
var export__ = import_lodash.default;
|
|
12380
13026
|
|
|
12381
13027
|
export {
|
|
@@ -12398,6 +13044,7 @@ export {
|
|
|
12398
13044
|
setType as set,
|
|
12399
13045
|
sendMail,
|
|
12400
13046
|
schedule,
|
|
13047
|
+
retryPromise,
|
|
12401
13048
|
replaceContentInFile,
|
|
12402
13049
|
replaceByVariables,
|
|
12403
13050
|
replaceByRules,
|
|
@@ -12431,8 +13078,9 @@ export {
|
|
|
12431
13078
|
levenshteinDistance,
|
|
12432
13079
|
lazyType as lazy,
|
|
12433
13080
|
late,
|
|
13081
|
+
exports_keling as keling,
|
|
12434
13082
|
jsonParse,
|
|
12435
|
-
|
|
13083
|
+
default5 as json5,
|
|
12436
13084
|
isValidNumber,
|
|
12437
13085
|
isValid,
|
|
12438
13086
|
isJson,
|
|
@@ -12464,9 +13112,11 @@ export {
|
|
|
12464
13112
|
functionType as function,
|
|
12465
13113
|
findItem,
|
|
12466
13114
|
filterParams,
|
|
13115
|
+
executePromise,
|
|
12467
13116
|
enumType as enum,
|
|
12468
13117
|
effectsType as effect,
|
|
12469
13118
|
downloadFile,
|
|
13119
|
+
exports_doubao2 as doubao,
|
|
12470
13120
|
discriminatedUnionType as discriminatedUnion,
|
|
12471
13121
|
delay,
|
|
12472
13122
|
en_default as defaultErrorMap,
|
|
@@ -12474,14 +13124,14 @@ export {
|
|
|
12474
13124
|
datetimeRegex,
|
|
12475
13125
|
dateType as date,
|
|
12476
13126
|
custom,
|
|
12477
|
-
|
|
13127
|
+
default6 as consola,
|
|
12478
13128
|
coerce,
|
|
12479
13129
|
chinaDayjs,
|
|
12480
13130
|
cheerio,
|
|
12481
13131
|
calcJsText,
|
|
12482
13132
|
booleanType as boolean,
|
|
12483
13133
|
bigIntType as bigint,
|
|
12484
|
-
|
|
13134
|
+
default4 as axios,
|
|
12485
13135
|
arrayType as array,
|
|
12486
13136
|
anyType as any,
|
|
12487
13137
|
amount,
|
|
@@ -12541,7 +13191,7 @@ export {
|
|
|
12541
13191
|
EMPTY_PATH,
|
|
12542
13192
|
Dayjs,
|
|
12543
13193
|
DataStoreOptions,
|
|
12544
|
-
|
|
13194
|
+
default2 as DataStore,
|
|
12545
13195
|
DIRTY,
|
|
12546
13196
|
BRAND
|
|
12547
13197
|
};
|