reelforge 1.24.1 → 1.24.2

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.
@@ -1,7 +1,8 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { uploadMultipart, post } from "../client.js";
4
- import { print } from "../utils/output.js";
4
+ import { uploadToOss } from "../utils/oss-upload.js";
5
+ import { print, warn } from "../utils/output.js";
5
6
  export function registerAudio(program) {
6
7
  const audio = program
7
8
  .command("audio")
@@ -32,21 +33,38 @@ export function registerAudio(program) {
32
33
  }
33
34
  let r;
34
35
  if (opts.file) {
35
- const buf = await fs.readFile(opts.file);
36
- const filename = path.basename(opts.file);
37
- const ext = path.extname(filename).toLowerCase();
38
- const mime = ext === ".wav" ? "audio/wav" :
39
- ext === ".m4a" ? "audio/mp4" :
40
- ext === ".flac" ? "audio/flac" :
41
- ext === ".ogg" ? "audio/ogg" :
42
- "audio/mpeg";
43
- const fileBlob = new File([new Uint8Array(buf)], filename, { type: mime });
44
- const fields = { file: fileBlob };
45
- if (opts.language)
46
- fields.language = opts.language;
47
- if (opts.model)
48
- fields.model = opts.model;
49
- r = await uploadMultipart("/api/v1/audio/transcribe", fields);
36
+ let key = null;
37
+ try {
38
+ key = await uploadToOss(opts.file);
39
+ }
40
+ catch (e) {
41
+ warn(`OSS 直传不可用,回退 multipart 上传 (${e instanceof Error ? e.message : e})`);
42
+ }
43
+ if (key) {
44
+ const body = { key };
45
+ if (opts.language)
46
+ body.language = opts.language;
47
+ if (opts.model)
48
+ body.model = opts.model;
49
+ r = await post("/api/v1/audio/transcribe", body);
50
+ }
51
+ else {
52
+ const buf = await fs.readFile(opts.file);
53
+ const filename = path.basename(opts.file);
54
+ const ext = path.extname(filename).toLowerCase();
55
+ const mime = ext === ".wav" ? "audio/wav" :
56
+ ext === ".m4a" ? "audio/mp4" :
57
+ ext === ".flac" ? "audio/flac" :
58
+ ext === ".ogg" ? "audio/ogg" :
59
+ "audio/mpeg";
60
+ const fileBlob = new File([new Uint8Array(buf)], filename, { type: mime });
61
+ const fields = { file: fileBlob };
62
+ if (opts.language)
63
+ fields.language = opts.language;
64
+ if (opts.model)
65
+ fields.model = opts.model;
66
+ r = await uploadMultipart("/api/v1/audio/transcribe", fields);
67
+ }
50
68
  }
51
69
  else {
52
70
  const body = { audio_url: opts.url };
@@ -1,7 +1,8 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- import { del, get, uploadMultipart } from "../client.js";
4
- import { print, table, success, bytes } from "../utils/output.js";
3
+ import { del, get, post, uploadMultipart } from "../client.js";
4
+ import { uploadToOss } from "../utils/oss-upload.js";
5
+ import { print, table, success, bytes, warn } from "../utils/output.js";
5
6
  export function registerBgm(program) {
6
7
  const bgm = program
7
8
  .command("bgm")
@@ -26,10 +27,23 @@ export function registerBgm(program) {
26
27
  .helpOption("-h, --help", "show help")
27
28
  .action(async (file) => {
28
29
  const abs = path.resolve(file);
29
- const buf = fs.readFileSync(abs);
30
30
  const name = path.basename(abs);
31
- const fileObj = new File([new Uint8Array(buf)], name, { type: "audio/mpeg" });
32
- const r = await uploadMultipart("/api/v1/bgm", { file: fileObj });
31
+ let r;
32
+ let key = null;
33
+ try {
34
+ key = await uploadToOss(abs);
35
+ }
36
+ catch (e) {
37
+ warn(`OSS 直传不可用,回退 multipart 上传 (${e instanceof Error ? e.message : e})`);
38
+ }
39
+ if (key) {
40
+ r = await post("/api/v1/bgm", { key, filename: name });
41
+ }
42
+ else {
43
+ const buf = fs.readFileSync(abs);
44
+ const fileObj = new File([new Uint8Array(buf)], name, { type: "audio/mpeg" });
45
+ r = await uploadMultipart("/api/v1/bgm", { file: fileObj });
46
+ }
33
47
  success(`Uploaded ${name}`);
34
48
  print(r);
35
49
  });
@@ -1,8 +1,9 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- import { del, get, uploadMultipart } from "../client.js";
3
+ import { del, get, post, uploadMultipart } from "../client.js";
4
+ import { uploadToOss } from "../utils/oss-upload.js";
4
5
  import { downloadTo } from "../utils/download.js";
5
- import { print, table, success, bytes } from "../utils/output.js";
6
+ import { print, table, success, bytes, warn } from "../utils/output.js";
6
7
  export function registerFiles(program) {
7
8
  const files = program
8
9
  .command("files")
@@ -28,10 +29,23 @@ export function registerFiles(program) {
28
29
  .helpOption("-h, --help", "show help")
29
30
  .action(async (file) => {
30
31
  const abs = path.resolve(file);
31
- const buf = fs.readFileSync(abs);
32
32
  const name = path.basename(abs);
33
- const fileObj = new File([new Uint8Array(buf)], name);
34
- const r = await uploadMultipart("/api/v1/files", { file: fileObj });
33
+ let key = null;
34
+ try {
35
+ key = await uploadToOss(abs);
36
+ }
37
+ catch (e) {
38
+ warn(`OSS 直传不可用,回退 multipart 上传 (${e instanceof Error ? e.message : e})`);
39
+ }
40
+ let r;
41
+ if (key) {
42
+ r = await post("/api/v1/files", { key, filename: name });
43
+ }
44
+ else {
45
+ const buf = fs.readFileSync(abs);
46
+ const fileObj = new File([new Uint8Array(buf)], name);
47
+ r = await uploadMultipart("/api/v1/files", { file: fileObj });
48
+ }
35
49
  success(`Uploaded → ${r.relative_path}`);
36
50
  print(r);
37
51
  });
@@ -16,6 +16,7 @@ const EXT_TO_MIME = {
16
16
  ".wav": "audio/wav",
17
17
  ".m4a": "audio/mp4",
18
18
  ".ogg": "audio/ogg",
19
+ ".flac": "audio/flac",
19
20
  ".pdf": "application/pdf",
20
21
  };
21
22
  export function mimeForFile(filePath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reelforge",
3
- "version": "1.24.1",
3
+ "version": "1.24.2",
4
4
  "description": "AI 视频生成 CLI。一句话主题或自己的脚本 → 自动出抖音/TikTok/视频号竖屏 MP4。安装即用:`reelforge` 或短别名 `rf`。",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",