maoda-commander-tt 0.0.16 → 0.0.17
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/main.js +39 -18
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -3238,6 +3238,7 @@ var POLL_INTERVAL_MS = 3e3;
|
|
|
3238
3238
|
var POLL_STATUS_LOG_INTERVAL_MS = 1e4;
|
|
3239
3239
|
var POLL_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
3240
3240
|
var SUBMIT_TIMEOUT_MS = 3e4;
|
|
3241
|
+
var DOWNLOAD_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
3241
3242
|
var AiVidCommand = class extends AiBaseCommand {
|
|
3242
3243
|
_meta() {
|
|
3243
3244
|
return {
|
|
@@ -3262,9 +3263,10 @@ var AiVidCommand = class extends AiBaseCommand {
|
|
|
3262
3263
|
)
|
|
3263
3264
|
);
|
|
3264
3265
|
cmd.addOption(
|
|
3265
|
-
new Option10(
|
|
3266
|
-
|
|
3267
|
-
|
|
3266
|
+
new Option10(
|
|
3267
|
+
"--duration <seconds>",
|
|
3268
|
+
"\u89C6\u9891\u65F6\u957F\uFF08\u79D2\uFF09\uFF0C\u7F3A\u7701\u4E0D\u6307\u5B9A"
|
|
3269
|
+
).argParser(parseDuration)
|
|
3268
3270
|
);
|
|
3269
3271
|
cmd.addOption(
|
|
3270
3272
|
new Option10(
|
|
@@ -3288,6 +3290,11 @@ var AiVidCommand = class extends AiBaseCommand {
|
|
|
3288
3290
|
this._outputJsonError(1, "\u8BF7\u8F93\u5165\u89C6\u9891\u751F\u6210\u63D0\u793A\u8BCD");
|
|
3289
3291
|
return this._makeOk();
|
|
3290
3292
|
}
|
|
3293
|
+
const token = resolveOpenRouterToken();
|
|
3294
|
+
if (!token) {
|
|
3295
|
+
this._outputJsonError(1, "\u7F3A\u5C11 OPENROUTER_AK\uFF0C\u8BF7\u5148\u914D\u7F6E\u53EF\u7528\u7684 API Key");
|
|
3296
|
+
return this._makeOk();
|
|
3297
|
+
}
|
|
3291
3298
|
const referenceResult = await prepareReferenceImages(ctx.options.reference);
|
|
3292
3299
|
if (!referenceResult.ok) {
|
|
3293
3300
|
this._outputJsonError(referenceResult.code, referenceResult.msg);
|
|
@@ -3310,7 +3317,7 @@ var AiVidCommand = class extends AiBaseCommand {
|
|
|
3310
3317
|
image_url: { url: item.dataUrl }
|
|
3311
3318
|
}));
|
|
3312
3319
|
}
|
|
3313
|
-
const submitResult = await this._submitGeneration(requestBody);
|
|
3320
|
+
const submitResult = await this._submitGeneration(requestBody, token);
|
|
3314
3321
|
if (!submitResult.ok) {
|
|
3315
3322
|
this._outputJsonError(submitResult.code, submitResult.msg);
|
|
3316
3323
|
return this._makeOk();
|
|
@@ -3334,7 +3341,7 @@ var AiVidCommand = class extends AiBaseCommand {
|
|
|
3334
3341
|
});
|
|
3335
3342
|
return this._makeOk();
|
|
3336
3343
|
}
|
|
3337
|
-
const pollResult = await this._pollUntilComplete(pollingUrl);
|
|
3344
|
+
const pollResult = await this._pollUntilComplete(pollingUrl, token);
|
|
3338
3345
|
if (!pollResult.ok) {
|
|
3339
3346
|
this._outputJsonError(pollResult.code, pollResult.msg);
|
|
3340
3347
|
return this._makeOk();
|
|
@@ -3351,7 +3358,8 @@ var AiVidCommand = class extends AiBaseCommand {
|
|
|
3351
3358
|
}
|
|
3352
3359
|
const downloadResult = await downloadVideoToFile(
|
|
3353
3360
|
videoUrl,
|
|
3354
|
-
outputTargetResult.value
|
|
3361
|
+
outputTargetResult.value,
|
|
3362
|
+
token
|
|
3355
3363
|
);
|
|
3356
3364
|
if (!downloadResult.ok) {
|
|
3357
3365
|
this._outputJsonError(downloadResult.code, downloadResult.msg);
|
|
@@ -3366,11 +3374,7 @@ var AiVidCommand = class extends AiBaseCommand {
|
|
|
3366
3374
|
});
|
|
3367
3375
|
return this._makeOk();
|
|
3368
3376
|
}
|
|
3369
|
-
async _submitGeneration(requestBody) {
|
|
3370
|
-
const token = process.env.OPENROUTER_AK?.trim() || OPENROUTER_AK;
|
|
3371
|
-
if (!token) {
|
|
3372
|
-
return makeError(1, "\u7F3A\u5C11 OPENROUTER_AK\uFF0C\u8BF7\u5148\u914D\u7F6E\u53EF\u7528\u7684 API Key");
|
|
3373
|
-
}
|
|
3377
|
+
async _submitGeneration(requestBody, token) {
|
|
3374
3378
|
const controller = new AbortController();
|
|
3375
3379
|
const timer = setTimeout(() => controller.abort(), SUBMIT_TIMEOUT_MS);
|
|
3376
3380
|
let response;
|
|
@@ -3414,8 +3418,7 @@ var AiVidCommand = class extends AiBaseCommand {
|
|
|
3414
3418
|
}
|
|
3415
3419
|
return makeOkWith(payload);
|
|
3416
3420
|
}
|
|
3417
|
-
async _pollUntilComplete(pollingUrl) {
|
|
3418
|
-
const token = process.env.OPENROUTER_AK?.trim() || OPENROUTER_AK;
|
|
3421
|
+
async _pollUntilComplete(pollingUrl, token) {
|
|
3419
3422
|
const startedAt = Date.now();
|
|
3420
3423
|
let lastStatusLogAt = 0;
|
|
3421
3424
|
while (true) {
|
|
@@ -3470,6 +3473,9 @@ var AiVidCommand = class extends AiBaseCommand {
|
|
|
3470
3473
|
}
|
|
3471
3474
|
}
|
|
3472
3475
|
};
|
|
3476
|
+
function resolveOpenRouterToken() {
|
|
3477
|
+
return process.env.OPENROUTER_AK?.trim() || OPENROUTER_AK;
|
|
3478
|
+
}
|
|
3473
3479
|
function parseReferencePaths3(value, previous) {
|
|
3474
3480
|
return previous.concat(
|
|
3475
3481
|
value.split(",").map((item) => item.trim()).filter((item) => item.length > 0)
|
|
@@ -3578,7 +3584,7 @@ async function resolveOutputTarget2(outputPath) {
|
|
|
3578
3584
|
});
|
|
3579
3585
|
}
|
|
3580
3586
|
}
|
|
3581
|
-
async function downloadVideoToFile(remoteUrl, target) {
|
|
3587
|
+
async function downloadVideoToFile(remoteUrl, target, token) {
|
|
3582
3588
|
try {
|
|
3583
3589
|
await fs7.mkdir(target.directoryPath, { recursive: true });
|
|
3584
3590
|
} catch (error) {
|
|
@@ -3588,18 +3594,33 @@ async function downloadVideoToFile(remoteUrl, target) {
|
|
|
3588
3594
|
`\u521B\u5EFA\u8F93\u51FA\u76EE\u5F55\u5931\u8D25: ${target.directoryPath}: ${message}`
|
|
3589
3595
|
);
|
|
3590
3596
|
}
|
|
3597
|
+
const controller = new AbortController();
|
|
3598
|
+
const timer = setTimeout(() => controller.abort(), DOWNLOAD_TIMEOUT_MS);
|
|
3591
3599
|
let response;
|
|
3592
3600
|
try {
|
|
3593
|
-
response = await fetch(remoteUrl
|
|
3601
|
+
response = await fetch(remoteUrl, {
|
|
3602
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
3603
|
+
signal: controller.signal
|
|
3604
|
+
});
|
|
3594
3605
|
} catch (error) {
|
|
3595
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
3606
|
+
const message = error instanceof Error && error.name === "AbortError" ? "\u4E0B\u8F7D\u8D85\u65F6" : error instanceof Error ? error.message : String(error);
|
|
3596
3607
|
return makeError(1, `\u4E0B\u8F7D\u89C6\u9891\u5931\u8D25: ${message}`);
|
|
3608
|
+
} finally {
|
|
3609
|
+
clearTimeout(timer);
|
|
3597
3610
|
}
|
|
3598
3611
|
if (!response.ok) {
|
|
3599
|
-
|
|
3612
|
+
const detail = await response.text().catch(() => "");
|
|
3613
|
+
const suffix = detail.trim() ? `: ${detail.trim().slice(0, 500)}` : "";
|
|
3614
|
+
return makeError(
|
|
3615
|
+
response.status,
|
|
3616
|
+
`\u4E0B\u8F7D\u89C6\u9891\u5931\u8D25: HTTP ${response.status}${suffix}`
|
|
3617
|
+
);
|
|
3600
3618
|
}
|
|
3601
3619
|
const bytes = Buffer.from(await response.arrayBuffer());
|
|
3602
|
-
const targetPath = target.autoNamed ? replaceFileExtension2(
|
|
3620
|
+
const targetPath = target.autoNamed ? replaceFileExtension2(
|
|
3621
|
+
target.filePath,
|
|
3622
|
+
inferVideoExtension(remoteUrl, response)
|
|
3623
|
+
) : target.filePath;
|
|
3603
3624
|
try {
|
|
3604
3625
|
await fs7.writeFile(targetPath, bytes);
|
|
3605
3626
|
} catch (error) {
|