@gentbajko/slopify 0.5.1 → 0.6.1
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/SUBTITLES.md +21 -0
- package/dist/adapter-registry.js +8 -3
- package/dist/adapters/alignment/audio.js +45 -0
- package/dist/adapters/alignment/cache.js +91 -0
- package/dist/adapters/alignment/ctc.js +128 -0
- package/dist/adapters/alignment/index.js +34 -0
- package/dist/adapters/alignment/lock.js +58 -0
- package/dist/adapters/alignment/numbers.js +91 -0
- package/dist/adapters/alignment/protocol.js +23 -0
- package/dist/adapters/alignment/quality.js +17 -0
- package/dist/adapters/alignment/runner.js +76 -0
- package/dist/adapters/alignment/text.js +61 -0
- package/dist/adapters/alignment/vocabulary.js +69 -0
- package/dist/adapters/alignment/worker.js +163 -0
- package/dist/adapters/llm/claude-code.js +6 -3
- package/dist/adapters/llm/codex.js +3 -2
- package/dist/adapters/llm/gemini-workspace.js +70 -0
- package/dist/adapters/llm/gemini.js +141 -0
- package/dist/adapters/llm/run-cli.js +6 -9
- package/dist/assets/fonts/Barlow-Regular.ttf +0 -0
- package/dist/assets/fonts/OFL.txt +93 -0
- package/dist/assets/fonts/SOURCE.txt +7 -0
- package/dist/edge/http/app.js +4 -0
- package/dist/edge/http/fonts.js +147 -0
- package/dist/edge/http/projects.js +23 -1
- package/dist/edge/http/providers.js +13 -0
- package/dist/edge/http/subtitles.js +92 -0
- package/dist/kernel/cli-command.js +45 -0
- package/dist/kernel/ports/subtitles.js +1 -0
- package/dist/kernel/runner/providers.js +3 -2
- package/dist/main.js +2 -1
- package/dist/slices/admission/repo.js +2 -0
- package/dist/slices/admission/rules.js +6 -0
- package/dist/slices/fonts/catalog.js +95 -0
- package/dist/slices/fonts/discovery.js +81 -0
- package/dist/slices/fonts/files.js +37 -0
- package/dist/slices/fonts/index.js +5 -0
- package/dist/slices/fonts/model.js +4 -0
- package/dist/slices/fonts/preview.js +14 -0
- package/dist/slices/fonts/sfnt.js +262 -0
- package/dist/slices/fonts/upload.js +40 -0
- package/dist/slices/settings/cli-paths.js +98 -0
- package/dist/slices/settings/cli-status.js +21 -12
- package/dist/slices/settings/model.js +9 -0
- package/dist/slices/settings/readiness.js +13 -9
- package/dist/slices/storage/downloads.js +2 -0
- package/dist/slices/storage/layout.js +10 -0
- package/dist/slices/storage/model.js +5 -0
- package/dist/slices/storage/repo.js +1 -0
- package/dist/slices/subtitles/captions.js +88 -0
- package/dist/slices/subtitles/model.js +18 -0
- package/dist/slices/subtitles/prepare.js +162 -0
- package/dist/slices/subtitles/transcript.js +34 -0
- package/dist/slices/video/audio-export.js +3 -0
- package/dist/slices/video/ffmpeg.js +14 -7
- package/dist/slices/video/plan.js +4 -4
- package/dist/slices/video/run.js +5 -2
- package/dist/slices/video/write-export.js +85 -20
- package/dist/web/assets/index-CNYs0noB.js +130 -0
- package/dist/web/assets/index-Mk0bvBg-.css +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +4 -2
- package/dist/web/assets/index-C1fsrIP5.css +0 -1
- package/dist/web/assets/index-DwJ_XTl3.js +0 -81
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2017 The Barlow Project Authors (https://github.com/jpt/barlow)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Barlow-Regular.ttf
|
|
2
|
+
Source: https://raw.githubusercontent.com/google/fonts/6cdf01867df0813c2390f90dff7dc66c87f14cf7/ofl/barlow/Barlow-Regular.ttf
|
|
3
|
+
SHA-256: 95aa02c7c43096e0dd44d787ba6216864a67157e402adab59b35572e0c1577ea
|
|
4
|
+
|
|
5
|
+
OFL.txt
|
|
6
|
+
Source: https://raw.githubusercontent.com/google/fonts/6cdf01867df0813c2390f90dff7dc66c87f14cf7/ofl/barlow/OFL.txt
|
|
7
|
+
SHA-256: 186d750eb496a4c17a76385f82be6aea2ac1cf2de074a811d63786cf374ea73f
|
package/dist/edge/http/app.js
CHANGED
|
@@ -5,12 +5,14 @@ import { streamSSE } from "hono/streaming";
|
|
|
5
5
|
import { actionRoutes } from "./actions.js";
|
|
6
6
|
import { entryRoutes } from "./entries.js";
|
|
7
7
|
import { fileRoutes } from "./files.js";
|
|
8
|
+
import { fontsRoutes } from "./fonts.js";
|
|
8
9
|
import { problem, problemFromError, titleOf } from "./problem.js";
|
|
9
10
|
import { projectRoutes } from "./projects.js";
|
|
10
11
|
import { promptRoutes } from "./prompts.js";
|
|
11
12
|
import { providerRoutes } from "./providers.js";
|
|
12
13
|
import { settingsRoutes } from "./settings.js";
|
|
13
14
|
import { stagingRoutes } from "./staging.js";
|
|
15
|
+
import { subtitleRoutes } from "./subtitles.js";
|
|
14
16
|
import { telemetryRoutes } from "./telemetry.js";
|
|
15
17
|
import { usageRoutes } from "./usage.js";
|
|
16
18
|
const notBuilt = "The Slopify UI is not built yet. The API is running: try /api/health.\n" +
|
|
@@ -27,6 +29,8 @@ function apiRoutes(deps, startedAt) {
|
|
|
27
29
|
// The re-run and cancel actions sit on the same prefix as the project itself; they
|
|
28
30
|
// are their own router because they are their own concern.
|
|
29
31
|
.route("/projects", actionRoutes(deps))
|
|
32
|
+
.route("/projects", subtitleRoutes(deps))
|
|
33
|
+
.route("/fonts", fontsRoutes(deps))
|
|
30
34
|
.route("/prompts", promptRoutes(deps))
|
|
31
35
|
.route("/entries", entryRoutes(deps))
|
|
32
36
|
.route("/telemetry", telemetryRoutes(deps))
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
import { pipeline } from "node:stream/promises";
|
|
3
|
+
import { Busboy } from "@fastify/busboy";
|
|
4
|
+
import { zValidator } from "@hono/zod-validator";
|
|
5
|
+
import { Hono } from "hono";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { fontIdPattern, fontMaxBytes, isMissingFont, listFonts, previewFont, uploadFont, } from "../../slices/fonts/index.js";
|
|
8
|
+
import { problem, titleOf } from "./problem.js";
|
|
9
|
+
const idParam = z.object({ id: z.string().regex(fontIdPattern) });
|
|
10
|
+
// Inferred so the Hono client retains all response shapes.
|
|
11
|
+
export function fontsRoutes(deps) {
|
|
12
|
+
return new Hono()
|
|
13
|
+
.get("/", async (c) => c.json({ fonts: await listFonts(deps.paths) }))
|
|
14
|
+
.post("/", async (c) => {
|
|
15
|
+
const contentType = c.req.header("content-type");
|
|
16
|
+
if (contentType === undefined || !contentType.toLowerCase().startsWith("multipart/form-data"))
|
|
17
|
+
return problem(c, {
|
|
18
|
+
status: 415,
|
|
19
|
+
title: titleOf(415),
|
|
20
|
+
detail: "Upload one .ttf or .otf file as multipart/form-data.",
|
|
21
|
+
});
|
|
22
|
+
const body = c.req.raw.body;
|
|
23
|
+
if (body === null)
|
|
24
|
+
return problem(c, {
|
|
25
|
+
status: 400,
|
|
26
|
+
title: titleOf(400),
|
|
27
|
+
detail: "The request carried no font file.",
|
|
28
|
+
});
|
|
29
|
+
const part = await readUpload(contentType, body);
|
|
30
|
+
if (!part.ok) {
|
|
31
|
+
const tooLarge = part.reason === "too-large";
|
|
32
|
+
return problem(c, {
|
|
33
|
+
status: tooLarge ? 413 : 400,
|
|
34
|
+
title: tooLarge ? "Content Too Large" : titleOf(400),
|
|
35
|
+
detail: tooLarge
|
|
36
|
+
? "A font file must be no larger than 32 MiB."
|
|
37
|
+
: "Upload exactly one complete font file in the file part.",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const result = await uploadFont(deps.paths, part.upload);
|
|
41
|
+
if (!result.ok)
|
|
42
|
+
return problem(c, failure(result.reason));
|
|
43
|
+
return c.json({ font: result.font }, 201);
|
|
44
|
+
})
|
|
45
|
+
.get("/:id/file", zValidator("param", idParam, (result, c) => {
|
|
46
|
+
if (!result.success)
|
|
47
|
+
return problem(c, { status: 404, title: titleOf(404), detail: "No font has that id." });
|
|
48
|
+
return undefined;
|
|
49
|
+
}), async (c) => {
|
|
50
|
+
try {
|
|
51
|
+
const preview = await previewFont(deps.paths, c.req.valid("param").id);
|
|
52
|
+
return c.body(Uint8Array.from(preview.content), 200, {
|
|
53
|
+
"content-type": preview.contentType,
|
|
54
|
+
"x-content-type-options": "nosniff",
|
|
55
|
+
"cache-control": "private, max-age=300",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (!isMissingFont(error))
|
|
60
|
+
throw error;
|
|
61
|
+
return problem(c, { status: 404, title: titleOf(404), detail: "No font has that id." });
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Bounded buffering is intentional for small font files. No file is committed until
|
|
66
|
+
// the entire multipart envelope finishes, so a second part or truncation cannot save it.
|
|
67
|
+
async function readUpload(contentType, body) {
|
|
68
|
+
let parser;
|
|
69
|
+
try {
|
|
70
|
+
parser = new Busboy({
|
|
71
|
+
headers: { "content-type": contentType },
|
|
72
|
+
preservePath: true,
|
|
73
|
+
limits: { files: 1, fields: 0, parts: 1, fileSize: fontMaxBytes + 1 },
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return { ok: false, reason: "multipart" };
|
|
78
|
+
}
|
|
79
|
+
const chunks = [];
|
|
80
|
+
let filename;
|
|
81
|
+
let count = 0;
|
|
82
|
+
let invalid = false;
|
|
83
|
+
let tooLarge = false;
|
|
84
|
+
parser.on("file", (field, stream, name) => {
|
|
85
|
+
filename = name;
|
|
86
|
+
if (field !== "file")
|
|
87
|
+
invalid = true;
|
|
88
|
+
stream.on("data", (chunk) => {
|
|
89
|
+
count += chunk.byteLength;
|
|
90
|
+
if (count > fontMaxBytes)
|
|
91
|
+
tooLarge = true;
|
|
92
|
+
else
|
|
93
|
+
chunks.push(chunk);
|
|
94
|
+
});
|
|
95
|
+
stream.on("limit", () => {
|
|
96
|
+
tooLarge = true;
|
|
97
|
+
});
|
|
98
|
+
stream.on("error", (error) => {
|
|
99
|
+
invalid = true;
|
|
100
|
+
parser.destroy(error);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
parser.on("filesLimit", () => {
|
|
104
|
+
invalid = true;
|
|
105
|
+
});
|
|
106
|
+
parser.on("fieldsLimit", () => {
|
|
107
|
+
invalid = true;
|
|
108
|
+
});
|
|
109
|
+
parser.on("partsLimit", () => {
|
|
110
|
+
invalid = true;
|
|
111
|
+
});
|
|
112
|
+
try {
|
|
113
|
+
await pipeline(Readable.fromWeb(body), parser);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return { ok: false, reason: "multipart" };
|
|
117
|
+
}
|
|
118
|
+
if (tooLarge)
|
|
119
|
+
return { ok: false, reason: "too-large" };
|
|
120
|
+
if (invalid || filename === undefined)
|
|
121
|
+
return { ok: false, reason: "multipart" };
|
|
122
|
+
return { ok: true, upload: { filename, content: Buffer.concat(chunks, count) } };
|
|
123
|
+
}
|
|
124
|
+
function failure(reason) {
|
|
125
|
+
switch (reason) {
|
|
126
|
+
case "too-large":
|
|
127
|
+
return {
|
|
128
|
+
status: 413,
|
|
129
|
+
title: "Content Too Large",
|
|
130
|
+
detail: "A font file must be no larger than 32 MiB.",
|
|
131
|
+
};
|
|
132
|
+
case "unsupported-format":
|
|
133
|
+
return { status: 415, title: titleOf(415), detail: "Choose a .ttf or .otf font file." };
|
|
134
|
+
case "unsafe-filename":
|
|
135
|
+
return {
|
|
136
|
+
status: 400,
|
|
137
|
+
title: titleOf(400),
|
|
138
|
+
detail: "The font filename cannot contain a path or control character.",
|
|
139
|
+
};
|
|
140
|
+
case "invalid-font":
|
|
141
|
+
return {
|
|
142
|
+
status: 400,
|
|
143
|
+
title: titleOf(400),
|
|
144
|
+
detail: "This file is not a supported, valid TrueType or OpenType font.",
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -6,6 +6,7 @@ import { listProjects, projectById, runDraftSchema, stageStandingsByProject, sta
|
|
|
6
6
|
import { admit } from "../../slices/admission/rules.js";
|
|
7
7
|
import { startRun } from "../../slices/admission/start.js";
|
|
8
8
|
import { withProjectControl } from "../../slices/control/lock.js";
|
|
9
|
+
import { resolveFont } from "../../slices/fonts/index.js";
|
|
9
10
|
import { pickTemplates, renderPicked } from "../../slices/library/slots.js";
|
|
10
11
|
import { deleteProject } from "../../slices/storage/delete-project.js";
|
|
11
12
|
import { outputsOf, stagedFiles } from "../../slices/storage/repo.js";
|
|
@@ -44,7 +45,28 @@ export function projectRoutes(deps) {
|
|
|
44
45
|
status: derive(stagesOf(deps.db, project.id), project.paused),
|
|
45
46
|
});
|
|
46
47
|
return (new Hono()
|
|
47
|
-
.post("/", zValidator("json", runDraftSchema, onInvalid), (c) => {
|
|
48
|
+
.post("/", zValidator("json", runDraftSchema, onInvalid), async (c) => {
|
|
49
|
+
const requestedSubtitles = c.req.valid("json").subtitles;
|
|
50
|
+
if (requestedSubtitles !== undefined && requestedSubtitles.mode !== "off") {
|
|
51
|
+
try {
|
|
52
|
+
await resolveFont(deps.paths, requestedSubtitles.fontId);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return problem(c, {
|
|
56
|
+
status: 400,
|
|
57
|
+
title: titleOf(400),
|
|
58
|
+
detail: "Choose an available subtitle font before starting.",
|
|
59
|
+
extensions: {
|
|
60
|
+
fields: [
|
|
61
|
+
{
|
|
62
|
+
field: "subtitles.fontId",
|
|
63
|
+
message: "This font is no longer available; choose another or upload it again.",
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
48
70
|
// The bodies are read here, at the click, so an edit made since the
|
|
49
71
|
// prompt was selected is the one that runs.
|
|
50
72
|
const picked = pickTemplates(deps.db, c.req.valid("json"));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { zValidator } from "@hono/zod-validator";
|
|
2
2
|
import { Hono } from "hono";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import { cliPathMaxLength, saveCliPath } from "../../slices/settings/cli-paths.js";
|
|
4
5
|
import { keyStatus, removeProviderKey, saveProviderKey } from "../../slices/settings/keys.js";
|
|
5
6
|
import { providerById, providerIds } from "../../slices/settings/model.js";
|
|
6
7
|
import { providerStatuses } from "../../slices/settings/readiness.js";
|
|
@@ -9,6 +10,7 @@ const providerParam = z.object({ id: z.enum(providerIds) });
|
|
|
9
10
|
// ceiling: no format check is allowed on a key, so the only thing said about the value is
|
|
10
11
|
// that it is a string of a length a key could plausibly have. Raise the bound if a provider
|
|
11
12
|
// ever issues something longer.
|
|
13
|
+
const pathBody = z.object({ path: z.string().max(cliPathMaxLength) });
|
|
12
14
|
const keyBody = z.object({ key: z.string().min(1).max(4096) });
|
|
13
15
|
// The return type is inferred so Hono keeps the route types the SPA's client is
|
|
14
16
|
// generated from; see stagingRoutes.
|
|
@@ -19,6 +21,17 @@ export function providerRoutes(deps) {
|
|
|
19
21
|
// What Settings draws its rails from and Play its dropdowns: every provider, with
|
|
20
22
|
// the one fact that decides whether it is selectable.
|
|
21
23
|
.get("/", async (c) => c.json({ providers: await providerStatuses(readiness) }))
|
|
24
|
+
.put("/:id/path", zValidator("param", providerParam, onInvalid), zValidator("json", pathBody, onInvalid), async (c) => {
|
|
25
|
+
const result = await saveCliPath(readiness, c.req.valid("param").id, c.req.valid("json").path);
|
|
26
|
+
if (!result.ok)
|
|
27
|
+
return problem(c, {
|
|
28
|
+
status: 400,
|
|
29
|
+
title: titleOf(400),
|
|
30
|
+
detail: result.message,
|
|
31
|
+
extensions: { fields: [{ field: "path", message: result.message }] },
|
|
32
|
+
});
|
|
33
|
+
return c.json(result.status);
|
|
34
|
+
})
|
|
22
35
|
.put("/:id/key", zValidator("param", providerParam, onInvalid), zValidator("json", keyBody, onInvalid), (c) => {
|
|
23
36
|
const { id } = c.req.valid("param");
|
|
24
37
|
const result = saveProviderKey(keys, id, c.req.valid("json").key);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { zValidator } from "@hono/zod-validator";
|
|
2
|
+
import { Hono } from "hono";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { transact } from "../../kernel/db/tx.js";
|
|
5
|
+
import { derive } from "../../kernel/runner/graph.js";
|
|
6
|
+
import { projectById, resetStage, stagesOf, updateProjectConfig, } from "../../slices/admission/repo.js";
|
|
7
|
+
import { withProjectControl } from "../../slices/control/lock.js";
|
|
8
|
+
import { resolveFont } from "../../slices/fonts/index.js";
|
|
9
|
+
import { outputsOf } from "../../slices/storage/repo.js";
|
|
10
|
+
import { subtitleConfigSchema } from "../../slices/subtitles/model.js";
|
|
11
|
+
import { onInvalid, problem, titleOf } from "./problem.js";
|
|
12
|
+
const idParam = z.object({
|
|
13
|
+
id: z
|
|
14
|
+
.string()
|
|
15
|
+
.min(1)
|
|
16
|
+
.max(64)
|
|
17
|
+
.regex(/^[0-9A-Za-z_-]+$/),
|
|
18
|
+
});
|
|
19
|
+
export function subtitleRoutes(deps) {
|
|
20
|
+
return new Hono().patch("/:id/subtitles", zValidator("param", idParam, onInvalid), zValidator("json", subtitleConfigSchema, onInvalid), async (c) => {
|
|
21
|
+
const { id } = c.req.valid("param");
|
|
22
|
+
return withProjectControl(deps.db, id, async () => {
|
|
23
|
+
const project = projectById(deps.db, id);
|
|
24
|
+
if (project === undefined)
|
|
25
|
+
return problem(c, {
|
|
26
|
+
status: 404,
|
|
27
|
+
title: titleOf(404),
|
|
28
|
+
detail: "No project has that id.",
|
|
29
|
+
});
|
|
30
|
+
const stages = stagesOf(deps.db, id);
|
|
31
|
+
if (stages.some((stage) => stage.state === "running") || deps.runner.hasInflight?.(id))
|
|
32
|
+
return problem(c, {
|
|
33
|
+
status: 409,
|
|
34
|
+
title: titleOf(409),
|
|
35
|
+
detail: "Pause the run and wait for its active work to stop before changing subtitles.",
|
|
36
|
+
});
|
|
37
|
+
const chosen = c.req.valid("json");
|
|
38
|
+
if (chosen.mode !== "off" && project.config.sources.audio === "off")
|
|
39
|
+
return problem(c, {
|
|
40
|
+
status: 400,
|
|
41
|
+
title: titleOf(400),
|
|
42
|
+
detail: "Subtitles need narration audio.",
|
|
43
|
+
});
|
|
44
|
+
const subtitles = project.config.sources.video === "off" && chosen.mode === "burn-in"
|
|
45
|
+
? { ...chosen, mode: "files" }
|
|
46
|
+
: chosen;
|
|
47
|
+
if (subtitles.mode !== "off" && subtitles.fontId !== project.config.subtitles?.fontId) {
|
|
48
|
+
try {
|
|
49
|
+
await resolveFont(deps.paths, subtitles.fontId);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return problem(c, {
|
|
53
|
+
status: 400,
|
|
54
|
+
title: titleOf(400),
|
|
55
|
+
detail: "That font is no longer available. Choose another font or upload it again.",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Font discovery awaits filesystem work; a pending runner may have claimed a
|
|
60
|
+
// stage during that time. Recheck synchronously immediately before the write.
|
|
61
|
+
if (stagesOf(deps.db, id).some((stage) => stage.state === "running") ||
|
|
62
|
+
deps.runner.hasInflight?.(id)) {
|
|
63
|
+
return problem(c, {
|
|
64
|
+
status: 409,
|
|
65
|
+
title: titleOf(409),
|
|
66
|
+
detail: "Pause the run before changing subtitles.",
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const video = stages.find((stage) => stage.kind === "video");
|
|
70
|
+
transact(deps.db, () => {
|
|
71
|
+
updateProjectConfig(deps.db, id, { ...project.config, subtitles }, deps.clock.now().toISOString());
|
|
72
|
+
// Only the local final export is invalidated. Existing provider outputs and
|
|
73
|
+
// the last finished export remain intact until its replacement succeeds.
|
|
74
|
+
if (video !== undefined &&
|
|
75
|
+
(project.config.sources.audio !== "off" || project.config.sources.video !== "off"))
|
|
76
|
+
resetStage(deps.db, video.id);
|
|
77
|
+
});
|
|
78
|
+
deps.hub.emit(id, { type: "project.updated", projectId: id });
|
|
79
|
+
if (project.paused !== true)
|
|
80
|
+
deps.runner.tick(id);
|
|
81
|
+
const current = stagesOf(deps.db, id);
|
|
82
|
+
return c.json({
|
|
83
|
+
project: {
|
|
84
|
+
...projectById(deps.db, id),
|
|
85
|
+
status: derive(current, project.paused === true),
|
|
86
|
+
},
|
|
87
|
+
stages: current,
|
|
88
|
+
outputs: outputsOf(deps.db, id),
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { extname, isAbsolute, join, resolve, win32 } from "node:path";
|
|
3
|
+
// Keep prompts out of cmd.exe: npm launchers name a JavaScript entry point that
|
|
4
|
+
// Node can execute directly with an argv array, including quotes and newlines.
|
|
5
|
+
export function cliCommand(binary) {
|
|
6
|
+
const file = process.platform === "win32" ? windowsFile(binary) : binary;
|
|
7
|
+
if (/\.[cm]?js$/i.test(file))
|
|
8
|
+
return { file: process.execPath, args: [resolve(file)] };
|
|
9
|
+
if (process.platform !== "win32" || !/\.(cmd|bat)$/i.test(file))
|
|
10
|
+
return { file, args: [] };
|
|
11
|
+
const stat = statSync(file);
|
|
12
|
+
if (!stat.isFile() || stat.size > 64 * 1024)
|
|
13
|
+
throw unsupportedShim();
|
|
14
|
+
const target = windowsShimTarget(file, readFileSync(file, "utf8"));
|
|
15
|
+
if (target === undefined || !statSync(target, { throwIfNoEntry: false })?.isFile())
|
|
16
|
+
throw unsupportedShim();
|
|
17
|
+
return { file: process.execPath, args: [target] };
|
|
18
|
+
}
|
|
19
|
+
export function windowsShimTarget(file, source) {
|
|
20
|
+
if (!/(?:node|bun)(?:\.exe)?/i.test(source))
|
|
21
|
+
return undefined;
|
|
22
|
+
// npm's cmd-shim uses %dp0%, older launchers use %~dp0. The remainder must
|
|
23
|
+
// be a literal relative script path, followed by the original argument list.
|
|
24
|
+
const matched = /"(?:%dp0%|%~dp0)[\\/]?([^"%\r\n]+\.[cm]?js)"\s+%\*/i.exec(source);
|
|
25
|
+
if (matched?.[1] === undefined || win32.isAbsolute(matched[1]))
|
|
26
|
+
return undefined;
|
|
27
|
+
return win32.resolve(win32.dirname(file), matched[1]);
|
|
28
|
+
}
|
|
29
|
+
function windowsFile(binary) {
|
|
30
|
+
const path = Object.entries(process.env).find(([key]) => key.toLowerCase() === "path")?.[1] ?? "";
|
|
31
|
+
const directories = isAbsolute(binary) || /[\\/]/.test(binary) ? [""] : path.split(";");
|
|
32
|
+
const suffixes = extname(binary) === "" ? [".exe", ".com", ".cmd", ".bat", ""] : [""];
|
|
33
|
+
for (const directory of directories) {
|
|
34
|
+
for (const suffix of suffixes) {
|
|
35
|
+
const file = directory === "" ? binary + suffix : join(directory.replace(/^"|"$/g, ""), binary + suffix);
|
|
36
|
+
if (statSync(file, { throwIfNoEntry: false })?.isFile())
|
|
37
|
+
return resolve(file);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Let spawn report its usual ENOENT when no executable exists.
|
|
41
|
+
return binary;
|
|
42
|
+
}
|
|
43
|
+
function unsupportedShim() {
|
|
44
|
+
return new Error("This batch launcher is not a supported Node CLI shim. Select the CLI's .exe or JavaScript entry file instead.");
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -30,11 +30,12 @@ export function stageProviders(deps, context, pieceId) {
|
|
|
30
30
|
if (event.type === "delta") {
|
|
31
31
|
text += event.text;
|
|
32
32
|
}
|
|
33
|
-
else {
|
|
33
|
+
else if (event.type === "done") {
|
|
34
34
|
usage = event.usage;
|
|
35
35
|
finishReason = event.finishReason;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
if (event.type !== "activity")
|
|
38
|
+
onEvent?.(event);
|
|
38
39
|
}
|
|
39
40
|
const answer = { text, usage, finishReason };
|
|
40
41
|
const unusable = call.check?.(answer);
|
package/dist/main.js
CHANGED
|
@@ -2,6 +2,7 @@ import { fileURLToPath } from "node:url";
|
|
|
2
2
|
import { serve } from "@hono/node-server";
|
|
3
3
|
import ffmpegStatic from "ffmpeg-static";
|
|
4
4
|
import { buildRegistry } from "./adapter-registry.js";
|
|
5
|
+
import { alignSubtitles } from "./adapters/alignment/index.js";
|
|
5
6
|
import { prepareFfmpeg } from "./adapters/ffmpeg.js";
|
|
6
7
|
import { nodeRunCli } from "./adapters/llm/run-cli.js";
|
|
7
8
|
import { cartesiaModel } from "./adapters/tts/cartesia.js";
|
|
@@ -150,7 +151,7 @@ function wire({ db, paths, clock, ids, log, hub, telemetry, flusher, registry, f
|
|
|
150
151
|
};
|
|
151
152
|
// The audio stage joins its chunks with the same binary the render uses, so it takes
|
|
152
153
|
// the same seven dependencies.
|
|
153
|
-
const video = { db, paths, ids, clock, log, ffmpeg, count };
|
|
154
|
+
const video = { db, paths, ids, clock, log, ffmpeg, count, alignSubtitles };
|
|
154
155
|
// Research, the article, the images and the thumbnail all write into the same project
|
|
155
156
|
// folder from the same database handle, so they take the same six dependencies.
|
|
156
157
|
const writing = { db, paths, ids, clock, log, count };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { stageKinds, stageStates } from "../../kernel/pipeline.js";
|
|
3
3
|
import { chunkModes } from "../narration/chunk.js";
|
|
4
|
+
import { subtitleConfigSchema } from "../subtitles/model.js";
|
|
4
5
|
import { entryModes, formats, stageSources } from "./model.js";
|
|
5
6
|
const providerChoice = z.object({ provider: z.string(), model: z.string() });
|
|
6
7
|
const entryChoice = z.object({ name: z.string(), mode: z.enum(entryModes) });
|
|
@@ -39,6 +40,7 @@ export const runDraftSchema = z.object({
|
|
|
39
40
|
// a mode not listed here would never reach the audio stage.
|
|
40
41
|
chunking: z.object({ mode: z.enum(chunkModes), words: z.number().optional() }).optional(),
|
|
41
42
|
silenceGapSeconds: z.number(),
|
|
43
|
+
subtitles: subtitleConfigSchema.optional(),
|
|
42
44
|
});
|
|
43
45
|
export const runConfigSchema = runDraftSchema.extend({
|
|
44
46
|
rendered: z.record(z.string(), z.string()),
|
|
@@ -71,6 +71,9 @@ export function admit(input) {
|
|
|
71
71
|
blank(draft.thumbnailPrompt)) {
|
|
72
72
|
fields.push({ field: "thumbnailPrompt", message: "Pick a thumbnail prompt." });
|
|
73
73
|
}
|
|
74
|
+
if (sources.audio === "off" && draft.subtitles !== undefined && draft.subtitles.mode !== "off") {
|
|
75
|
+
fields.push({ field: "subtitles.mode", message: "Subtitles need narration audio." });
|
|
76
|
+
}
|
|
74
77
|
checkProvided(draft, input.staged, fields);
|
|
75
78
|
checkValues(draft, input.requiredSlots, fields);
|
|
76
79
|
if (!Number.isFinite(draft.silenceGapSeconds) ||
|
|
@@ -104,6 +107,9 @@ export function normaliseDraft(draft) {
|
|
|
104
107
|
return {
|
|
105
108
|
...draft,
|
|
106
109
|
title: draft.title.trim(),
|
|
110
|
+
subtitles: sources.video === "off" && draft.subtitles?.mode === "burn-in"
|
|
111
|
+
? { ...draft.subtitles, mode: "files" }
|
|
112
|
+
: draft.subtitles,
|
|
107
113
|
sources,
|
|
108
114
|
values,
|
|
109
115
|
intro: sources.audio === "generate" ? draft.intro : undefined,
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { lstat, readdir } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { discoverSystemFonts } from "./discovery.js";
|
|
6
|
+
import { readFontFile, unavailable } from "./files.js";
|
|
7
|
+
import { fontSummary } from "./model.js";
|
|
8
|
+
import { readFontMetadata } from "./sfnt.js";
|
|
9
|
+
export const fontIdPattern = /^(?:default|(?:system|uploaded)-[a-f0-9]{64})$/;
|
|
10
|
+
const uploadName = /^(uploaded-[a-f0-9]{64})\.(ttf|otf)$/;
|
|
11
|
+
const bundled = fileURLToPath(new URL("../../assets/fonts/Barlow-Regular.ttf", import.meta.url));
|
|
12
|
+
export async function listFonts(paths) {
|
|
13
|
+
const [defaultFont, uploaded, system] = await Promise.all([
|
|
14
|
+
bundledFont(),
|
|
15
|
+
uploadedFonts(paths),
|
|
16
|
+
discoverSystemFonts(),
|
|
17
|
+
]);
|
|
18
|
+
return [defaultFont, ...uploaded, ...system].map(fontSummary);
|
|
19
|
+
}
|
|
20
|
+
export async function resolveFont(paths, id) {
|
|
21
|
+
if (!fontIdPattern.test(id))
|
|
22
|
+
throw missingFont();
|
|
23
|
+
if (id === "default")
|
|
24
|
+
return bundledFont();
|
|
25
|
+
const fonts = id.startsWith("uploaded-")
|
|
26
|
+
? await uploadedFonts(paths, id)
|
|
27
|
+
: await discoverSystemFonts();
|
|
28
|
+
const font = fonts.find((font) => font.id === id);
|
|
29
|
+
if (font === undefined)
|
|
30
|
+
throw missingFont();
|
|
31
|
+
return font;
|
|
32
|
+
}
|
|
33
|
+
export function missingFont() {
|
|
34
|
+
return new Error("The selected font is no longer available. Choose another font.", {
|
|
35
|
+
cause: "font-not-found",
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export function isMissingFont(error) {
|
|
39
|
+
return error instanceof Error && error.cause === "font-not-found";
|
|
40
|
+
}
|
|
41
|
+
async function bundledFont() {
|
|
42
|
+
const bytes = await readFontFile(bundled);
|
|
43
|
+
const face = bytes === undefined ? undefined : readFontMetadata(bytes)?.[0];
|
|
44
|
+
if (face === undefined)
|
|
45
|
+
throw new Error("Slopify's bundled Barlow font is missing or invalid. Reinstall Slopify.");
|
|
46
|
+
return {
|
|
47
|
+
id: "default",
|
|
48
|
+
name: face.name,
|
|
49
|
+
family: face.family,
|
|
50
|
+
source: "bundled",
|
|
51
|
+
path: bundled,
|
|
52
|
+
extension: ".ttf",
|
|
53
|
+
assName: face.assName,
|
|
54
|
+
faceIndex: 0,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function uploadedFonts(paths, wanted) {
|
|
58
|
+
const root = join(paths.dataDir, "fonts");
|
|
59
|
+
let names;
|
|
60
|
+
try {
|
|
61
|
+
if (!(await lstat(root)).isDirectory())
|
|
62
|
+
return [];
|
|
63
|
+
names = wanted === undefined ? await readdir(root) : [`${wanted}.ttf`, `${wanted}.otf`];
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (unavailable(error))
|
|
67
|
+
return [];
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
const result = [];
|
|
71
|
+
for (const name of names.toSorted()) {
|
|
72
|
+
const id = uploadName.exec(name)?.[1];
|
|
73
|
+
if (id === undefined)
|
|
74
|
+
continue;
|
|
75
|
+
const path = join(root, name);
|
|
76
|
+
const bytes = await readFontFile(path);
|
|
77
|
+
if (bytes === undefined ||
|
|
78
|
+
`uploaded-${createHash("sha256").update(bytes).digest("hex")}` !== id)
|
|
79
|
+
continue;
|
|
80
|
+
const face = readFontMetadata(bytes)?.[0];
|
|
81
|
+
if (face === undefined || face.extension === ".ttc")
|
|
82
|
+
continue;
|
|
83
|
+
result.push({
|
|
84
|
+
id,
|
|
85
|
+
name: face.name,
|
|
86
|
+
family: face.family,
|
|
87
|
+
source: "uploaded",
|
|
88
|
+
path,
|
|
89
|
+
extension: face.extension,
|
|
90
|
+
assName: face.assName,
|
|
91
|
+
faceIndex: 0,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|