rvlib-shipkit 2.20.0 → 2.21.0
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/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/src/checks/SK004-gitignore-policy.check.ts +6 -3
- package/src/cli/cmd_GlobalProcesses.ts +2 -107
- package/src/cli/cmd_Home.ts +1 -1
- package/src/cli/cmd_Overview.ts +2 -1
- package/src/cli/cmd_Releases.ts +39 -3
- package/src/cli/cmd_Review.ts +22 -13
- package/src/cli/cmd_Social.ts +13 -7
- package/src/cli/cmd_Sound.ts +17 -4
- package/src/cli/cmd_Trailer.ts +67 -1
- package/src/cli/registry.ts +2 -1
- package/src/collections/collection-types.ts +1 -1
- package/src/collections/review.ts +23 -4
- package/src/core/layout.ts +6 -0
- package/src/home/gui-app/ShipkitGui.swift +35 -0
- package/src/home/gui-app.ts +1 -0
- package/src/home/pm-switch.ts +112 -0
- package/src/identities/identities.ts +11 -6
- package/src/messages/brief.ts +3 -3
- package/src/messages/score.ts +2 -0
- package/src/releases/add.ts +33 -5
- package/src/releases/before.ts +31 -0
- package/src/releases/from-card.ts +104 -19
- package/src/releases/model.ts +73 -13
- package/src/releases/pictures.ts +29 -8
- package/src/review/http.ts +1 -1
- package/src/review/model.ts +12 -2
- package/src/review/stage-card.ts +1 -1
- package/src/review/store.ts +12 -2
- package/src/review/trailer-desk.ts +19 -0
- package/src/review/trailer-model.ts +65 -0
- package/src/review/trailer-routes.ts +98 -1
- package/src/review/trailer-voices.ts +144 -0
- package/src/review/watchers.ts +58 -1
- package/src/serve/hub-app/benign-errors.ts +22 -0
- package/src/serve/hub-app/hash-route.ts +27 -15
- package/src/serve/hub-app/home-st.ts +8 -0
- package/src/serve/hub-app/hub-app.tsx +2 -0
- package/src/serve/hub-app/project-list.css +7 -2
- package/src/serve/hub-app/project-list.tsx +9 -0
- package/src/serve/hub-app/projects-svc.ts +16 -6
- package/src/serve/hub-app/releases/releases-page.tsx +121 -28
- package/src/serve/hub-app/releases/releases-st.ts +46 -4
- package/src/serve/hub-app/releases.css +30 -3
- package/src/serve/hub-app/repo-sections.ts +1 -1
- package/src/serve/hub-app/repo-st.ts +15 -10
- package/src/serve/hub-app/review/clip-st.ts +3 -1
- package/src/serve/hub-app/review/kit.tsx +3 -3
- package/src/serve/hub-app/review/trailer-page.tsx +31 -6
- package/src/serve/hub-app/review/trailer-st.ts +168 -8
- package/src/serve/hub-app/review/trailer-timeline.tsx +36 -4
- package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
- package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
- package/src/serve/hub-app/review.css +88 -0
- package/src/serve/hub-app/social/comms-page.tsx +10 -5
- package/src/serve/hub-app/social/next-release.tsx +118 -0
- package/src/serve/hub-app/social/social-model.ts +2 -0
- package/src/serve/hub-app/social/social-st.ts +38 -1
- package/src/serve/hub-app/social.css +8 -0
- package/src/serve/hub-app/tree-build.ts +2 -0
- package/src/serve/project-gutter-route.ts +8 -0
- package/src/serve/project-gutter.ts +4 -2
- package/src/shot/box.ts +33 -12
- package/src/shot/client.ts +1 -1
- package/src/shot/shooter.ts +19 -9
- package/src/social/desk-index.ts +49 -8
- package/src/social/discord-layout.ts +6 -2
- package/src/social/drafts.ts +1 -1
- package/src/social/kinds.ts +3 -2
- package/src/social/load.ts +26 -7
- package/src/social/publish/index.ts +24 -9
- package/src/social/release-stage.ts +133 -29
- package/src/social/routes.ts +2 -1
- package/src/social/stage.ts +39 -20
- package/src/trailer/bed.ts +111 -0
- package/src/trailer/build.ts +57 -38
- package/src/trailer/ffmpeg.ts +6 -0
- package/src/trailer/grammar.ts +23 -2
- package/src/trailer/graph.ts +12 -1
- package/src/trailer/shot-plan.ts +75 -0
- package/src/trailer/shot-state.ts +191 -0
- package/src/trailer/sound/audio.ts +28 -0
- package/src/trailer/sound/brand.ts +53 -3
- package/src/trailer/sound/gen.ts +61 -2
- package/src/trailer/sound/index.ts +25 -11
- package/src/trailer/sound/presets.ts +86 -5
- package/src/trailer/sound/run.ts +1 -1
- package/src/trailer/sound/takes.ts +94 -0
- package/src/trailer/titles.ts +36 -0
- package/src/trailer/url.ts +1 -1
package/src/releases/model.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// a release as one markdown file (wiki tools/shipkit/units.md, The release files): `# <version>: <title>`, its date,
|
|
2
|
-
// `## <category>`, `### <change>`, its description, its
|
|
2
|
+
// `## <category>`, `### <change>`, its description, its shots, its bullets, the card it came from in a hidden
|
|
3
3
|
// comment. `next.md` is the version being filled. No fs: store.ts reads the files, the hub page imports this too.
|
|
4
|
-
// A picture is `space:<key>` (private, signed for the hub) until the release makes it a public URL
|
|
4
|
+
// A picture is `space:<key>` (private, signed for the hub) until the release makes it a public URL. Every picture
|
|
5
|
+
// carries its rating, and a venue shows only what its ceiling takes: `shotFor`, the one function every venue calls
|
|
6
|
+
import { POST_RATINGS, takes, type PostRating } from '../identities/rating.ts'
|
|
5
7
|
|
|
6
8
|
export const NEXT = 'next'
|
|
7
9
|
|
|
@@ -11,13 +13,22 @@ export interface Picture {
|
|
|
11
13
|
/** `space:<key>` while private, the public URL once released */
|
|
12
14
|
url: string
|
|
13
15
|
alt: string
|
|
16
|
+
/** what it shows; null when unrated, which reads explicit (`ratingOf`) */
|
|
17
|
+
rating: PostRating | null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** one picture of a change and the still of what it looked like before, `` right under it */
|
|
21
|
+
export interface Shot {
|
|
22
|
+
picture: Picture
|
|
23
|
+
before: Picture | null
|
|
14
24
|
}
|
|
15
25
|
|
|
16
26
|
export interface Change {
|
|
17
27
|
title: string
|
|
18
28
|
/** its description, markdown, empty when the title says it all */
|
|
19
29
|
text: string
|
|
20
|
-
|
|
30
|
+
/** one a rating at most, in the file's order: a safe one for every venue, an nsfw one for those that take it */
|
|
31
|
+
shots: Shot[]
|
|
21
32
|
bullets: string[]
|
|
22
33
|
/** the review card it came from, and the commit that card shows */
|
|
23
34
|
card: string | null
|
|
@@ -44,6 +55,33 @@ export const SPACE = 'space:'
|
|
|
44
55
|
export const isPrivate = (p: Picture): boolean => p.url.startsWith(SPACE)
|
|
45
56
|
export const spaceKey = (p: Picture): string | null => (isPrivate(p) ? p.url.slice(SPACE.length) : null)
|
|
46
57
|
|
|
58
|
+
/** a change's pictures, each shot's after then its before: what bump makes public and the guard reads */
|
|
59
|
+
export const picturesOf = (ch: Pick<Change, 'shots'>): Picture[] => ch.shots.flatMap((s) => (s.before ? [s.picture, s.before] : [s.picture]))
|
|
60
|
+
|
|
61
|
+
/** a picture's rating as a venue reads it: unrated is explicit, fail closed */
|
|
62
|
+
export const ratingOf = (p: Pick<Picture, 'rating'>): PostRating => p.rating ?? 'explicit'
|
|
63
|
+
|
|
64
|
+
/** what a venue whose ceiling is `ceiling` shows of a change: the shot of the highest rating it takes, its before only
|
|
65
|
+
* when the venue takes that too; null, its words alone. THE function every venue calls, never a filter of its own */
|
|
66
|
+
export function shotFor(ch: Pick<Change, 'shots'>, ceiling: PostRating): Shot | null {
|
|
67
|
+
const rank = (s: Shot): number => POST_RATINGS.indexOf(ratingOf(s.picture))
|
|
68
|
+
const fit = ch.shots.filter((s) => takes(ceiling, ratingOf(s.picture))).sort((a, b) => rank(b) - rank(a))[0]
|
|
69
|
+
if (!fit) return null
|
|
70
|
+
return { picture: fit.picture, before: fit.before && takes(ceiling, ratingOf(fit.before)) ? fit.before : null }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** the change holds a picture this venue may not show and none it may: the venue says where it is instead */
|
|
74
|
+
export const withheldFrom = (ch: Pick<Change, 'shots'>, ceiling: PostRating): boolean => ch.shots.length > 0 && shotFor(ch, ceiling) == null
|
|
75
|
+
|
|
76
|
+
/** a picture line's title: its rating, a before's `before <rating>`; an unrated one says none */
|
|
77
|
+
const titleOf = (p: Picture, before: boolean): string => {
|
|
78
|
+
const t = [before ? 'before' : '', p.rating ?? ''].filter((w) => w !== '').join(' ')
|
|
79
|
+
return t === '' ? '' : ` "${t}"`
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** a change's media is a clip (a card's clip), not a still */
|
|
83
|
+
export const isClip = (url: string): boolean => /\.(mp4|webm|mov)(\?|$)/i.test(url)
|
|
84
|
+
|
|
47
85
|
/** where the hub serves a private picture, its key after it */
|
|
48
86
|
export const PICTURE_ROUTE = '/api/releases/picture/'
|
|
49
87
|
/** the hub path a picture shows by: a private one through the hub, a public one as it is */
|
|
@@ -52,7 +90,9 @@ export const pictureRoute = (url: string): string => (url.startsWith(SPACE) ? `$
|
|
|
52
90
|
const VERSION = /^\d+\.\d+\.\d+$/
|
|
53
91
|
const HEAD = /^# (next|\d+\.\d+\.\d+)(?: \((major|minor|patch)\))?(?:: (.*))?$/
|
|
54
92
|
const DATE = /^\d{4}-\d{2}-\d{2}$/
|
|
55
|
-
const PICTURE = /^!\[([^\]]*)\]\((\S+)
|
|
93
|
+
const PICTURE = /^!\[([^\]]*)\]\((\S+)(?: "([^"]*)")?\)$/
|
|
94
|
+
/** a picture line's title: `<rating>`, `before`, `before <rating>`, or none */
|
|
95
|
+
const TITLE = /^(before)?\s*(safe|mild|explicit)?$/
|
|
56
96
|
const MARK = /^<!--\s*(?:card:\s*(\S+))?\s*(?:commit:\s*([0-9a-f]{7,40}))?\s*-->$/
|
|
57
97
|
const BULLET = /^[-*] (.*)$/
|
|
58
98
|
|
|
@@ -68,6 +108,7 @@ export function parseRelease(md: string, name = 'release'): Release {
|
|
|
68
108
|
let cat: Category | null = null
|
|
69
109
|
let ch: Change | null = null
|
|
70
110
|
let comment = false
|
|
111
|
+
let pictureAt = -1
|
|
71
112
|
let text: string[] = []
|
|
72
113
|
const close = (): void => {
|
|
73
114
|
if (ch) ch.text = text.join('\n').trim()
|
|
@@ -102,7 +143,7 @@ export function parseRelease(md: string, name = 'release'): Release {
|
|
|
102
143
|
if (line.startsWith('### ')) {
|
|
103
144
|
if (!cat) throw at(i, `a change sits under a "## <category>": ${line}`)
|
|
104
145
|
close()
|
|
105
|
-
ch = { title: line.slice(4).trim(), text: '',
|
|
146
|
+
ch = { title: line.slice(4).trim(), text: '', shots: [], bullets: [], card: null, commit: null }
|
|
106
147
|
cat.changes.push(ch)
|
|
107
148
|
continue
|
|
108
149
|
}
|
|
@@ -128,8 +169,19 @@ export function parseRelease(md: string, name = 'release'): Release {
|
|
|
128
169
|
if (line.startsWith('<!--')) throw at(i, `a hidden line of a change is "<!-- card: <id> commit: <sha> -->": ${line}`)
|
|
129
170
|
const p = PICTURE.exec(line)
|
|
130
171
|
if (p) {
|
|
131
|
-
|
|
132
|
-
ch.picture
|
|
172
|
+
const t = TITLE.exec((p[3] ?? '').trim())
|
|
173
|
+
if (!t) throw at(i, `"${ch.title}": a picture's title is its rating (safe, mild, explicit), a before's "before <rating>": "${p[3]}"`)
|
|
174
|
+
const pic: Picture = { alt: p[1]!.trim(), url: p[2]!, rating: (t[2] as PostRating | undefined) ?? null }
|
|
175
|
+
const last = ch.shots.at(-1)
|
|
176
|
+
if (t[1]) {
|
|
177
|
+
if (pictureAt !== i - 1 || !last || last.before) throw at(i, `"${ch.title}": one before a picture, on the line right under it`)
|
|
178
|
+
if (isClip(pic.url)) throw at(i, `"${ch.title}": a before is a still (png, jpg, webp), not a clip`)
|
|
179
|
+
last.before = pic
|
|
180
|
+
continue
|
|
181
|
+
}
|
|
182
|
+
if (ch.shots.some((s) => ratingOf(s.picture) === ratingOf(pic))) throw at(i, `"${ch.title}" has one picture a rating, and two read ${ratingOf(pic)} (an unrated one reads explicit)`)
|
|
183
|
+
ch.shots.push({ picture: pic, before: null })
|
|
184
|
+
pictureAt = i
|
|
133
185
|
continue
|
|
134
186
|
}
|
|
135
187
|
const b = BULLET.exec(line)
|
|
@@ -157,7 +209,10 @@ export function renderRelease(r: Release): string {
|
|
|
157
209
|
out.push('', `### ${ch.title}`)
|
|
158
210
|
if (ch.card || ch.commit) out.push(`<!--${ch.card ? ` card: ${ch.card}` : ''}${ch.commit ? ` commit: ${ch.commit}` : ''} -->`)
|
|
159
211
|
if (ch.text) out.push(ch.text)
|
|
160
|
-
|
|
212
|
+
for (const s of ch.shots) {
|
|
213
|
+
out.push(`})`)
|
|
214
|
+
if (s.before) out.push(`})`)
|
|
215
|
+
}
|
|
161
216
|
for (const b of ch.bullets) out.push(`- ${b}`)
|
|
162
217
|
}
|
|
163
218
|
}
|
|
@@ -191,13 +246,16 @@ export function upsertChange(r: Release, category: string, change: Change): Rele
|
|
|
191
246
|
|
|
192
247
|
export const changesOf = (r: Release): Change[] => r.categories.flatMap((c) => c.changes)
|
|
193
248
|
|
|
249
|
+
/** a change's key on a page: its card, else its title */
|
|
250
|
+
export const changeKey = (ch: Pick<Change, 'card' | 'title'>): string => `${ch.card ?? ''}${ch.title}`
|
|
251
|
+
|
|
194
252
|
/** a card id's words: its slug, made from the card's title, which a public repo's file carries in its hidden comment */
|
|
195
253
|
const cardWords = (id: string | null): string => (id ?? '').replace(/^\d{8}-\d{6}-?/, '').replace(/-/g, ' ')
|
|
196
254
|
|
|
197
255
|
/** every word of a release that a stranger reads, each a text the repo's guard runs on. The card ids' slugs only when
|
|
198
256
|
* the file itself is public (a declared public repo): the notes, the post and the page never show the hidden comment */
|
|
199
257
|
export const publicTexts = (r: Release, o: { fileIsPublic?: boolean } = {}): string[] =>
|
|
200
|
-
[r.title, ...r.categories.flatMap((c) => [c.name, ...c.changes.flatMap((ch) => [ch.title, ch.text, ch.
|
|
258
|
+
[r.title, ...r.categories.flatMap((c) => [c.name, ...c.changes.flatMap((ch) => [ch.title, ch.text, ...picturesOf(ch).map((p) => p.alt), ...ch.bullets, o.fileIsPublic ? cardWords(ch.card) : ''])])].filter((t) => t.trim() !== '')
|
|
201
259
|
|
|
202
260
|
/** next named as a version, dated */
|
|
203
261
|
export function promoted(r: Release, version: string, date: string): Release {
|
|
@@ -215,15 +273,17 @@ const newer = (a: string, b: string): number => {
|
|
|
215
273
|
/** versions newest first, next on top */
|
|
216
274
|
export const byVersion = (a: string, b: string): number => (a === NEXT ? -1 : b === NEXT ? 1 : newer(a, b))
|
|
217
275
|
|
|
218
|
-
/** one release as notes: each category a `### `, each change a bullet of its title and description,
|
|
219
|
-
* own bullets under it. A GitHub release, the staged
|
|
220
|
-
|
|
276
|
+
/** one release as notes: each category a `### `, each change a bullet of its title and description, the picture the
|
|
277
|
+
* ceiling takes (a clip as a link: markdown shows no video), its own bullets under it. A GitHub release, the staged
|
|
278
|
+
* post and CHANGELOG.md read this, all public: safe */
|
|
279
|
+
export function notesOf(r: Release, ceiling: PostRating = 'safe'): string {
|
|
221
280
|
const out: string[] = []
|
|
222
281
|
for (const c of r.categories) {
|
|
223
282
|
out.push(`### ${c.name}`, '')
|
|
224
283
|
for (const ch of c.changes) {
|
|
225
284
|
out.push(`- **${ch.title}**${ch.text ? `: ${ch.text.replace(/\s*\n\s*/g, ' ')}` : ''}`)
|
|
226
|
-
|
|
285
|
+
const pic = shotFor(ch, ceiling)?.picture
|
|
286
|
+
if (pic && !isPrivate(pic)) out.push(isClip(pic.url) ? ` [▶ ${pic.alt}](${pic.url})` : ` `)
|
|
227
287
|
for (const b of ch.bullets) out.push(` - ${b}`)
|
|
228
288
|
}
|
|
229
289
|
out.push('')
|
package/src/releases/pictures.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { shaOf, shaOfKey } from '../media-store/content.ts'
|
|
|
9
9
|
import { linkMedia, putMedia } from '../media-store/put.ts'
|
|
10
10
|
import { stripCopy } from '../social/strip.ts'
|
|
11
11
|
import { guardWith, type SocialUnit } from '../social/unit.ts'
|
|
12
|
-
import { isPrivate, SPACE, spaceKey, type Release } from './model.ts'
|
|
12
|
+
import { isPrivate, ratingOf, SPACE, spaceKey, type Picture, type Release } from './model.ts'
|
|
13
13
|
|
|
14
14
|
/** the media store's label of every release picture, private and public */
|
|
15
15
|
export const RELEASE_KIND = 'release'
|
|
@@ -48,6 +48,21 @@ export async function pictureFile(root: string, key: string): Promise<string> {
|
|
|
48
48
|
return at
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/** the local file of any release picture: a private one's (`pictureFile`), a public one's scratch copy by its sha,
|
|
52
|
+
* else fetched once into it */
|
|
53
|
+
export async function localPicture(root: string, url: string): Promise<string> {
|
|
54
|
+
if (url.startsWith(SPACE)) return pictureFile(root, url.slice(SPACE.length))
|
|
55
|
+
const m = /([0-9a-f]{64})(\.[a-z0-9]+)(?:\?|$)/i.exec(url)
|
|
56
|
+
if (!m) throw new Error(`${url}: no release picture (its name is its sha)`)
|
|
57
|
+
const at = copyOf(root, m[1]!.toLowerCase(), m[2]!.toLowerCase())
|
|
58
|
+
if (existsSync(at)) return at
|
|
59
|
+
const r = await fetch(url)
|
|
60
|
+
if (!r.ok) throw new Error(`${url}: answered ${r.status}`)
|
|
61
|
+
mkdirSync(picturesDir(root), { recursive: true })
|
|
62
|
+
writeFileSync(at, Buffer.from(await r.arrayBuffer()))
|
|
63
|
+
return at
|
|
64
|
+
}
|
|
65
|
+
|
|
51
66
|
/** a signed link for the hub to show a private picture, or its public URL as it is */
|
|
52
67
|
export async function shownUrl(url: string): Promise<string> {
|
|
53
68
|
const key = url.startsWith(SPACE) ? url.slice(SPACE.length) : null
|
|
@@ -57,13 +72,16 @@ export async function shownUrl(url: string): Promise<string> {
|
|
|
57
72
|
/** every private picture of a release made public, each after the repo's guard read its bytes: the release with its
|
|
58
73
|
* public URLs. A refusal throws naming the change, and nothing is made public before every picture passed */
|
|
59
74
|
export async function publishPictures(root: string, r: Release, unit: SocialUnit | null): Promise<{ release: Release; published: number }> {
|
|
60
|
-
|
|
75
|
+
// only a safe picture gets a public URL: an nsfw one goes to its venues as a file, so it stays private
|
|
76
|
+
const todo = r.categories
|
|
77
|
+
.flatMap((c) => c.changes)
|
|
78
|
+
.flatMap((ch) => ch.shots.flatMap((s) => [s.picture, s.before].filter((p): p is Picture => p != null && isPrivate(p) && ratingOf(p) === 'safe').map((p) => ({ ch, p, before: p === s.before }))))
|
|
61
79
|
const files = new Map<string, string>()
|
|
62
|
-
for (const ch of todo) {
|
|
63
|
-
const key = spaceKey(
|
|
80
|
+
for (const { ch, p, before } of todo) {
|
|
81
|
+
const key = spaceKey(p)!
|
|
64
82
|
const file = await pictureFile(root, key)
|
|
65
|
-
const problems = guardWith(unit, { title: ch.title, alt:
|
|
66
|
-
if (problems.length > 0) throw new Error(`"${ch.title}": the repo's guard refuses its picture: ${problems.join('; ')}`)
|
|
83
|
+
const problems = guardWith(unit, { title: ch.title, alt: p.alt, files: [file] })
|
|
84
|
+
if (problems.length > 0) throw new Error(`"${ch.title}": the repo's guard refuses its ${before ? 'before' : 'picture'}: ${problems.join('; ')}`)
|
|
67
85
|
files.set(key, file)
|
|
68
86
|
}
|
|
69
87
|
const urls = new Map<string, string>()
|
|
@@ -80,8 +98,11 @@ export async function publishPictures(root: string, r: Release, unit: SocialUnit
|
|
|
80
98
|
categories: r.categories.map((c) => ({
|
|
81
99
|
...c,
|
|
82
100
|
changes: c.changes.map((ch) => {
|
|
83
|
-
const
|
|
84
|
-
|
|
101
|
+
const pub = (p: Picture | null): Picture | null => {
|
|
102
|
+
const key = p ? spaceKey(p) : null
|
|
103
|
+
return key && urls.has(key) ? { ...p!, url: urls.get(key)! } : p
|
|
104
|
+
}
|
|
105
|
+
return { ...ch, shots: ch.shots.map((s) => ({ picture: pub(s.picture)!, before: pub(s.before) })) }
|
|
85
106
|
}),
|
|
86
107
|
})),
|
|
87
108
|
}
|
package/src/review/http.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// answer under its ETag, a file with byte ranges
|
|
3
3
|
import { extname } from 'node:path'
|
|
4
4
|
|
|
5
|
-
export const TYPES: Record<string, string> = { '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp', '.svg': 'image/svg+xml', '.webm': 'video/webm', '.mp4': 'video/mp4', '.ico': 'image/x-icon' }
|
|
5
|
+
export const TYPES: Record<string, string> = { '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp', '.svg': 'image/svg+xml', '.webm': 'video/webm', '.mp4': 'video/mp4', '.ico': 'image/x-icon', '.wav': 'audio/wav', '.m4a': 'audio/mp4' }
|
|
6
6
|
export const NO_STORE = { 'Cache-Control': 'no-store' }
|
|
7
7
|
/** an item's files never change once written, nor a kept render under its version: a phone keeps what it fetched */
|
|
8
8
|
export const KEEP = { 'Cache-Control': 'private, max-age=86400' }
|
package/src/review/model.ts
CHANGED
|
@@ -179,6 +179,8 @@ export const SHA_RE = /^[0-9a-f]{64}$/
|
|
|
179
179
|
export interface CardChangelog {
|
|
180
180
|
category: string
|
|
181
181
|
line: string
|
|
182
|
+
/** what its media shows (`--rating`): the rating its picture lands with; absent, unrated (it reads explicit) */
|
|
183
|
+
rating?: 'safe' | 'mild' | 'explicit'
|
|
182
184
|
}
|
|
183
185
|
|
|
184
186
|
/** `--changelog "<category>: <line>"` read; a line with no category throws saying the shape */
|
|
@@ -712,6 +714,14 @@ export const coversCard = (f: WatchFilter, x: ReviewItem): boolean =>
|
|
|
712
714
|
/** the live watchers that will read his answer on any of these cards */
|
|
713
715
|
export const listenersOf = (cards: readonly ReviewItem[], watchers: readonly Watcher[]): Watcher[] => watchers.filter((w) => cards.some((x) => coversCard(w, x)))
|
|
714
716
|
|
|
717
|
+
/** who listens, in plain words: one lane's watch by its lane, any other by « an agent », several by their count */
|
|
718
|
+
export function listenWords(ws: readonly Watcher[]): string {
|
|
719
|
+
const [w] = ws
|
|
720
|
+
if (w === undefined) return 'nobody listens'
|
|
721
|
+
if (ws.length > 1) return `${ws.length} agents listening`
|
|
722
|
+
return w.lane ? `the ${w.lane} lane is listening` : 'an agent is listening'
|
|
723
|
+
}
|
|
724
|
+
|
|
715
725
|
/** what `review add` says when no live watch of the card's own session or lane will read his answer, else null: an
|
|
716
726
|
* unfiltered watch (a dispatcher, another session) hears it for someone else */
|
|
717
727
|
export function unheardLine(item: Item, watchers: readonly Watcher[]): string | null {
|
|
@@ -866,8 +876,8 @@ export function itemProblems(v: unknown): string[] {
|
|
|
866
876
|
if (v.answers !== undefined && !(Array.isArray(v.answers) && v.answers.length > 0 && v.answers.every((a) => typeof a === 'string' && ID_RE.test(a))))
|
|
867
877
|
out.push('answers: a list of item ids')
|
|
868
878
|
for (const k of ['what', 'post', 'commit', 'supersedes', 'why', 'keeps']) if (v[k] !== undefined && typeof v[k] !== 'string') out.push(`${k}: a text`)
|
|
869
|
-
if (v.changelog !== undefined && !(obj(v.changelog) && typeof v.changelog.category === 'string' && v.changelog.category.trim() !== '' && typeof v.changelog.line === 'string' && v.changelog.line.trim() !== ''))
|
|
870
|
-
out.push('changelog: { category, line }, or absent')
|
|
879
|
+
if (v.changelog !== undefined && !(obj(v.changelog) && typeof v.changelog.category === 'string' && v.changelog.category.trim() !== '' && typeof v.changelog.line === 'string' && v.changelog.line.trim() !== '' && (v.changelog.rating === undefined || ['safe', 'mild', 'explicit'].includes(v.changelog.rating as string))))
|
|
880
|
+
out.push('changelog: { category, line, rating? }, or absent')
|
|
871
881
|
if (v.light !== undefined && v.light !== 'review') out.push('light: review, or absent')
|
|
872
882
|
if (v.wip !== undefined && !(obj(v.wip) && typeof v.wip.live === 'string' && v.wip.live !== '' && Number.isInteger(v.wip.frame))) out.push('wip: { live, frame }, or absent')
|
|
873
883
|
if (v.trailer !== undefined) out.push(...trailerCardProblems(v.trailer))
|
package/src/review/stage-card.ts
CHANGED
|
@@ -123,7 +123,7 @@ export type StageAsk = {
|
|
|
123
123
|
pick?: string
|
|
124
124
|
text: string
|
|
125
125
|
rating: PostRating
|
|
126
|
-
/** what the post is for (wiki guides/post-kinds/index.md); unset, a card's `
|
|
126
|
+
/** what the post is for (wiki guides/post-kinds/index.md); unset, a card's `iteration` */
|
|
127
127
|
kind?: string
|
|
128
128
|
/** a `custom` kind's one line on why no kind fits */
|
|
129
129
|
kindWhy?: string
|
package/src/review/store.ts
CHANGED
|
@@ -380,7 +380,7 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
|
|
|
380
380
|
title: input.title.trim(),
|
|
381
381
|
what: input.what.trim(),
|
|
382
382
|
...(input.post?.trim() ? { post: input.post.trim() } : {}),
|
|
383
|
-
...(input.changelog ? { changelog: { category: input.changelog.category.trim(), line: input.changelog.line.trim() } } : {}),
|
|
383
|
+
...(input.changelog ? { changelog: { category: input.changelog.category.trim(), line: input.changelog.line.trim(), ...(input.changelog.rating ? { rating: input.changelog.rating } : {}) } } : {}),
|
|
384
384
|
...(topic ? { topic } : {}),
|
|
385
385
|
...(input.commit ? { commit: input.commit } : {}),
|
|
386
386
|
views: loaded.map((v, n) => viewOf(v, n, input.marks?.[n], given[n]?.note)),
|
|
@@ -966,7 +966,7 @@ export function deleteReport(dir: string, id: string): void {
|
|
|
966
966
|
* after it (`…-live-3`): its name first, the whole store only when no name holds it */
|
|
967
967
|
export function itemOfRef(dir: string, ref: string): ReviewItem | null {
|
|
968
968
|
const m = /^([a-z][a-z0-9-]*)#(\d+)$/.exec(ref.trim())
|
|
969
|
-
if (!m) return ID_RE.test(ref) ? readItem(dir, ref) :
|
|
969
|
+
if (!m) return ID_RE.test(ref) ? readItem(dir, ref) : itemOfPrefix(dir, ref)
|
|
970
970
|
const holds = (x: ReviewItem | null): x is ReviewItem => x !== null && x.item.origin.by === 'player' && x.item.origin.server === m[1] && x.item.origin.serverId === Number(m[2])
|
|
971
971
|
const tail = `-${m[1]}-${m[2]}`
|
|
972
972
|
for (const n of existsSync(dir) ? readdirSync(dir).filter((n) => n.endsWith(tail)).sort() : []) {
|
|
@@ -980,6 +980,16 @@ export function itemOfRef(dir: string, ref: string): ReviewItem | null {
|
|
|
980
980
|
return readAll(dir).items.find(holds) ?? null
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
+
/** an item by its moment alone (`20261108-194005`): the one id of that second; two of them is an error naming both, so
|
|
984
|
+
* a short id never picks one by chance. A longer ref is an exact id: a gone item's id never lands on one it starts */
|
|
985
|
+
function itemOfPrefix(dir: string, ref: string): ReviewItem | null {
|
|
986
|
+
const p = ref.trim()
|
|
987
|
+
if (!/^\d{8}-\d{6}$/.test(p) || !existsSync(dir)) return null
|
|
988
|
+
const hits = readdirSync(dir).filter((n) => n.startsWith(`${p}-`))
|
|
989
|
+
if (hits.length > 1) throw new Error(`${p} starts ${hits.length} items: ${hits.sort().join(', ')}; give more of the id`)
|
|
990
|
+
return hits.length === 1 ? readItem(dir, hits[0]!) : null
|
|
991
|
+
}
|
|
992
|
+
|
|
983
993
|
/** a player's report as the owner names it: `live#85`; any other item by its id */
|
|
984
994
|
export const refOf = (x: ReviewItem): string => (x.item.origin.by === 'player' ? `${x.item.origin.server}#${x.item.origin.serverId}` : x.item.id)
|
|
985
995
|
|
|
@@ -11,6 +11,8 @@ import { fetchBack, signedUrl } from '../media-store/remote.ts'
|
|
|
11
11
|
import { parseTrailer, starts, total, type Trailer } from '../trailer/grammar.ts'
|
|
12
12
|
import { THUMB_W } from '../trailer/graph.ts'
|
|
13
13
|
import { ffmpeg } from '../trailer/ffmpeg.ts'
|
|
14
|
+
import { answerOf, readFacts, readPlan } from '../trailer/shot-plan.ts'
|
|
15
|
+
import { cutStates, planCutOf, type CutPlan, type CutStates } from '../trailer/shot-state.ts'
|
|
14
16
|
import { probe, stillAt } from './media.ts'
|
|
15
17
|
import type { FrameSubject } from './model.ts'
|
|
16
18
|
import { readAllCached, storeDir } from './store.ts'
|
|
@@ -371,9 +373,26 @@ export function cutInfo(root: string, dir: string, id: string, c: CutFiles): Cut
|
|
|
371
373
|
strip: timeline && view ? stripInfo(viewStrip(root, id, c.cut, view.mtime), view, timeline) : null,
|
|
372
374
|
fileMtime,
|
|
373
375
|
version: c.version === true,
|
|
376
|
+
shots: timeline ? shotStates(root, id, c, timeline, errors) : null,
|
|
374
377
|
}
|
|
375
378
|
}
|
|
376
379
|
|
|
380
|
+
/** the cut's shots in plain words: its plan (a kept version reads its cut's), its takes as the last check or build read
|
|
381
|
+
* them (a version's takes are kept with it: none read), the answers on the cards a plan names. A plan that does not
|
|
382
|
+
* parse is said in the cut's errors */
|
|
383
|
+
function shotStates(root: string, id: string, c: CutFiles, tl: Timeline, errors: string[]): CutStates {
|
|
384
|
+
const planCut = planCutOf(c.cut, c.version === true)
|
|
385
|
+
let plan: CutPlan = { shots: {} }
|
|
386
|
+
try {
|
|
387
|
+
plan = readPlan(root, id, planCut)
|
|
388
|
+
} catch (e) {
|
|
389
|
+
errors.push((e as Error).message)
|
|
390
|
+
}
|
|
391
|
+
const cards = Object.values(plan.shots).some((e) => e.card) ? readAllCached(storeDir(root)).items : []
|
|
392
|
+
const answer = (card: string) => answerOf(cards.find((x) => x.item.id === card) ?? null)
|
|
393
|
+
return cutStates(tl.shots.map((s) => s.name), plan, planCut, c.version ? null : readFacts(root, id, c.cut), answer)
|
|
394
|
+
}
|
|
395
|
+
|
|
377
396
|
export function trailerInfo(root: string, id: string): TrailerInfo | null {
|
|
378
397
|
const dir = trailerDir(root, id)
|
|
379
398
|
if (!dir) return null
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// the trailer view's shapes (wiki tools/trailer/index.md, Frame notes): what the hub answers about a repo's cuts, and a frame
|
|
2
2
|
// note as the view shows it, read from its item of the one store. Pure: the routes and the page share them
|
|
3
3
|
import { isFrame, isReply, partyOf, stateOf, type ReviewItem } from './model.ts'
|
|
4
|
+
import type { CutStates } from '../trailer/shot-state.ts'
|
|
4
5
|
|
|
5
6
|
export type NoteState = 'open' | 'done' | 'wontfix'
|
|
6
7
|
|
|
@@ -169,6 +170,9 @@ export interface CutInfo {
|
|
|
169
170
|
fileMtime: number
|
|
170
171
|
/** a kept version (`versions/<v>.trailer` and `versions/<v>/`): it never changes */
|
|
171
172
|
version: boolean
|
|
173
|
+
/** each shot of its timeline in plain words: ready, queued, filming, waiting on a card, not filmed (trailer/shot-state.ts);
|
|
174
|
+
* null with no timeline */
|
|
175
|
+
shots: CutStates | null
|
|
172
176
|
}
|
|
173
177
|
|
|
174
178
|
export interface TrailerInfo {
|
|
@@ -181,6 +185,67 @@ export interface TrailerDesk {
|
|
|
181
185
|
trailers: TrailerInfo[]
|
|
182
186
|
}
|
|
183
187
|
|
|
188
|
+
/** the seconds of picture a voice line's passage shows before the line starts, and after the longer of its versions
|
|
189
|
+
* (trailer/bed.ts voicePassage) */
|
|
190
|
+
export const PASSAGE_PAD = 1
|
|
191
|
+
|
|
192
|
+
/** one place a voice line is spoken: its cut, its line, its shot's span and its own start on the cut's timeline */
|
|
193
|
+
export interface VoiceUse {
|
|
194
|
+
cut: string
|
|
195
|
+
line: number
|
|
196
|
+
/** the .trailer file, repo relative */
|
|
197
|
+
file: string
|
|
198
|
+
shot: string
|
|
199
|
+
shotStart: number
|
|
200
|
+
shotEnd: number
|
|
201
|
+
/** seconds on the cut the line starts */
|
|
202
|
+
at: number
|
|
203
|
+
/** seconds it has before the next line starts, or the cut ends */
|
|
204
|
+
room: number
|
|
205
|
+
/** its `volume` in the cut */
|
|
206
|
+
volume: number
|
|
207
|
+
/** the brand voice it names, null for the brand's own */
|
|
208
|
+
by: string | null
|
|
209
|
+
/** it reads a recorded voice: his take, or a standin until he makes one */
|
|
210
|
+
mine: boolean
|
|
211
|
+
/** who the cut plays now, in words */
|
|
212
|
+
reader: string
|
|
213
|
+
/** the sound the cut plays now, its cache key; null until a build makes it */
|
|
214
|
+
made: string | null
|
|
215
|
+
/** a line of a recorded voice: who stands in, and its line's cache key whether it plays or not (null until made) */
|
|
216
|
+
standin: { name: string; made: string | null } | null
|
|
217
|
+
/** the cut's render on screen, null before its first */
|
|
218
|
+
video: { mtime: number } | null
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** one text of a trailer's lines: one take serves every use of the same words */
|
|
222
|
+
export interface VoiceLine {
|
|
223
|
+
/** the take's key: the words alone, tags and case dropped */
|
|
224
|
+
key: string
|
|
225
|
+
/** as written, tags included: a tag is how to say it */
|
|
226
|
+
text: string
|
|
227
|
+
words: string
|
|
228
|
+
/** the recorded voice his take is kept under; null when the brand has none */
|
|
229
|
+
voice: string | null
|
|
230
|
+
/** some use reads a recorded voice: it waits for him until he has a take */
|
|
231
|
+
mine: boolean
|
|
232
|
+
/** his take: the file he recorded; where its own 0 sits on the line's time (`dragged`: his, else at its first
|
|
233
|
+
* sound); the ranges of it he masked, in its own seconds; and the line made of it as the cut plays it, starting at
|
|
234
|
+
* the line's 0 (its cache key; null until made) */
|
|
235
|
+
take: { file: string; mtime: number; offset: number; dragged: boolean; mask: [number, number][]; made: string | null } | null
|
|
236
|
+
uses: VoiceUse[]
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export interface VoicesDesk {
|
|
240
|
+
trailer: string
|
|
241
|
+
/** the brand's first recorded voice and his name, null when the brand has none */
|
|
242
|
+
recorder: { voice: string; who: string; takes: boolean } | null
|
|
243
|
+
lines: VoiceLine[]
|
|
244
|
+
/** lines of a recorded voice with no take yet */
|
|
245
|
+
waiting: number
|
|
246
|
+
errors: string[]
|
|
247
|
+
}
|
|
248
|
+
|
|
184
249
|
/** the shot on screen at `t`: the last one started */
|
|
185
250
|
export function shotAt(tl: Pick<Timeline, 'shots'>, t: number): ShotSpan | null {
|
|
186
251
|
let out: ShotSpan | null = null
|
|
@@ -7,8 +7,11 @@ import { join, relative } from 'node:path'
|
|
|
7
7
|
import { bad, NO_STORE, ranged } from './http.ts'
|
|
8
8
|
import { ID_RE, isFrame } from './model.ts'
|
|
9
9
|
import { act, appendMessage, deleteRaised, raiseItem, readAllCached, readItem } from './store.ts'
|
|
10
|
-
import { cutOf, frameNote, frameStill, montagePage, pinnedRender, trailerDir, trailerIds, trailerInfo, videoOf, viewMedia } from './trailer-desk.ts'
|
|
10
|
+
import { cutOf, frameNote, frameStill, montagePage, pinnedRender, readView, trailerDir, trailerIds, trailerInfo, videoOf, viewMedia } from './trailer-desk.ts'
|
|
11
11
|
import { CUT_RE, noteMarkOf, noteOf, TRAILER_ID_RE, type NoteMark, type NoteState, type TrailerDesk } from './trailer-model.ts'
|
|
12
|
+
import { madeFile, voicesDesk, voicesWaiting } from './trailer-voices.ts'
|
|
13
|
+
import { dropTake, setTakeEdit, writeTake, type TakeExt } from '../trailer/sound/takes.ts'
|
|
14
|
+
import type { Take } from '../trailer/sound/presets.ts'
|
|
12
15
|
|
|
13
16
|
/** a note's mark as its message stores it: a review card's Rect */
|
|
14
17
|
const rectsOf = (m: NoteMark) => [{ ...m, comment: '' }]
|
|
@@ -38,10 +41,104 @@ function noteAfter(dir: string, nid: string): Response {
|
|
|
38
41
|
return note ? Response.json(note, { headers: NO_STORE }) : bad(`no note ${nid}`, 404)
|
|
39
42
|
}
|
|
40
43
|
|
|
44
|
+
const TAKE_TYPES: Record<string, TakeExt> = { 'audio/webm': 'webm', 'audio/ogg': 'ogg', 'audio/mp4': 'm4a', 'audio/x-m4a': 'm4a', 'audio/wav': 'wav', 'audio/x-wav': 'wav', 'audio/mpeg': 'mp3', 'audio/flac': 'flac' }
|
|
45
|
+
const AUDIO_TYPE: Record<string, string> = { webm: 'audio/webm', ogg: 'audio/ogg', m4a: 'audio/mp4', mp4: 'audio/mp4', wav: 'audio/wav', mp3: 'audio/mpeg', flac: 'audio/flac' }
|
|
46
|
+
|
|
47
|
+
/** his take made as the cut will play it, the build's own run: its waveform and its sound on the page are the cut's */
|
|
48
|
+
async function makeTake(root: string, voice: string, text: string, take: Take): Promise<void> {
|
|
49
|
+
const [{ takeRun }, { soundRun }, { brandSound }, { voiceTweak }] = await Promise.all([import('../trailer/sound/presets.ts'), import('../trailer/sound/run.ts'), import('../trailer/sound/index.ts'), import('../trailer/sound/brand.ts')])
|
|
50
|
+
await soundRun(takeRun(text, take, voiceTweak(await brandSound(root), voice)), { root, dir: root }, () => undefined)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** the Voices routes: the lines of a trailer, the sound a cut plays now, his take of a text (kept, played, edited,
|
|
54
|
+
* dropped) */
|
|
55
|
+
async function voiceRoutes(req: Request, path: string, root: string): Promise<Response | null> {
|
|
56
|
+
if (path === '/api/trailer/voices' && req.method === 'GET') return Response.json(await voicesWaiting(root), { headers: NO_STORE })
|
|
57
|
+
const made = /^\/api\/trailer\/voices\/made\/([0-9a-f]{16})\.wav$/.exec(path)
|
|
58
|
+
if (made && req.method === 'GET') {
|
|
59
|
+
const f = madeFile(root, made[1] ?? '')
|
|
60
|
+
return f ? ranged(req, f) : bad('that line is not made: sk trailer makes it', 404)
|
|
61
|
+
}
|
|
62
|
+
const passage = /^\/api\/trailer\/voices\/passage\/([^/]+)\/([0-9a-f]{12})\/([^/]+)\/(\d+)\/(ref|take|none)\.mp4$/.exec(path)
|
|
63
|
+
if (passage && req.method === 'GET') {
|
|
64
|
+
// one line's passage, picture and bed and one version of the line, as one file (trailer/bed.ts voicePassage)
|
|
65
|
+
const [, id = '', key = '', cut = '', lineNo = '', hear = 'none'] = passage
|
|
66
|
+
const tdir = trailerDir(root, id)
|
|
67
|
+
const c = tdir ? cutOf(tdir, cut) : null
|
|
68
|
+
const line = (await voicesDesk(root, id))?.lines.find((l) => l.key === key)
|
|
69
|
+
const use = line?.uses.find((u) => u.cut === cut && u.line === Number(lineNo))
|
|
70
|
+
if (!tdir || !c?.trailer || !line || !use?.video) return bad(`no rendered use of line ${key} in ${id}/${cut}:${lineNo}`, 404)
|
|
71
|
+
const media = await viewMedia(root, id, cut, use.video.mtime, 'video')
|
|
72
|
+
if (!media || !('path' in media)) return bad(`the render of ${cut} is not on this disk`, 404)
|
|
73
|
+
const ref = madeFile(root, (use.standin ? use.standin.made : use.made) ?? '')
|
|
74
|
+
const take = madeFile(root, line.take?.made ?? '')
|
|
75
|
+
const voice = hear === 'ref' ? ref : hear === 'take' ? take : null
|
|
76
|
+
if (hear !== 'none' && !voice) return bad(`no ${hear === 'ref' ? 'reference' : 'take'} of this line is made yet`, 404)
|
|
77
|
+
const [{ voiceBed, voicePassage }, { durationOf }] = await Promise.all([import('../trailer/bed.ts'), import('../trailer/ffmpeg.ts')])
|
|
78
|
+
const seconds = Math.max(0, ...(await Promise.all([ref, take].flatMap((f) => (f ? [durationOf(f)] : [])))))
|
|
79
|
+
const p = await voicePassage(root, { video: media.path, videoMtime: use.video.mtime, bed: await voiceBed(root, c.trailer), at: use.at, seconds, total: await durationOf(media.path), voice, volume: use.volume })
|
|
80
|
+
return ranged(req, p.file)
|
|
81
|
+
}
|
|
82
|
+
const voicedMp4 = /^\/api\/trailer\/voiced\/([0-9a-f]{16})\.mp4$/.exec(path)
|
|
83
|
+
if (voicedMp4 && req.method === 'GET') {
|
|
84
|
+
const { voicedFile } = await import('../trailer/bed.ts')
|
|
85
|
+
const f = voicedFile(root, voicedMp4[1] ?? '')
|
|
86
|
+
return f ? ranged(req, f) : bad('that voice of the cut is not made: the player asks for it first', 404)
|
|
87
|
+
}
|
|
88
|
+
const voiced = /^\/api\/trailer\/voiced\/([^/]+)\/([^/]+)\/(\d+)\/(takes|standin)$/.exec(path)
|
|
89
|
+
if (voiced && req.method === 'GET') {
|
|
90
|
+
// the whole cut in his voice or its standin's, its picture the render on screen (trailer/bed.ts voicedCut)
|
|
91
|
+
const [, id = '', cut = '', version = '', side = ''] = voiced
|
|
92
|
+
const tdir = TRAILER_ID_RE.test(id) && CUT_RE.test(cut) ? trailerDir(root, id) : null
|
|
93
|
+
const c = tdir ? cutOf(tdir, cut) : null
|
|
94
|
+
if (!c?.trailer || c.version) return bad(`${id}/${cut} is no working cut: only a working cut plays in either voice`, 404)
|
|
95
|
+
const media = await viewMedia(root, id, cut, Number(version), 'video')
|
|
96
|
+
if (!media || !('path' in media)) return bad(`the render of ${cut} at ${version} is not on this disk`, 404)
|
|
97
|
+
const { voicedCut } = await import('../trailer/bed.ts')
|
|
98
|
+
const v = await voicedCut(root, c.trailer, media.path, side === 'takes', readView(root, id, cut, Number(version))?.timeline ?? null)
|
|
99
|
+
return Response.json({ key: v.key }, { headers: NO_STORE })
|
|
100
|
+
}
|
|
101
|
+
const desk = /^\/api\/trailer\/voices\/([^/]+)$/.exec(path)
|
|
102
|
+
if (desk && req.method === 'GET') {
|
|
103
|
+
const d = await voicesDesk(root, desk[1] ?? '')
|
|
104
|
+
return d ? Response.json(d, { headers: NO_STORE }) : bad(`no trailer ${desk[1]}`, 404)
|
|
105
|
+
}
|
|
106
|
+
const take = /^\/api\/trailer\/voices\/([^/]+)\/take\/([0-9a-f]{12})(\/edit)?$/.exec(path)
|
|
107
|
+
if (!take) return null
|
|
108
|
+
const [, id = '', key = '', edit] = take
|
|
109
|
+
const d = await voicesDesk(root, id)
|
|
110
|
+
const line = d?.lines.find((l) => l.key === key)
|
|
111
|
+
if (!d || !line) return bad(`no line ${key} in trailer ${id}`, 404)
|
|
112
|
+
if (req.method === 'GET') {
|
|
113
|
+
if (!line.take) return bad('no take of that line yet', 404)
|
|
114
|
+
const ext = line.take.file.split('.').pop() ?? ''
|
|
115
|
+
return new Response(Bun.file(join(root, line.take.file)), { headers: { 'Content-Type': AUDIO_TYPE[ext] ?? 'application/octet-stream', ...NO_STORE } })
|
|
116
|
+
}
|
|
117
|
+
if (!line.voice) return bad("the brand has no voice of yours: add one to trailer.voices in .shipkit/identity/brand.ts, { record: '<your name>' }")
|
|
118
|
+
if (req.method === 'PUT') {
|
|
119
|
+
const type = (req.headers.get('content-type') ?? '').split(';')[0]?.trim() ?? ''
|
|
120
|
+
const ext = TAKE_TYPES[type]
|
|
121
|
+
if (!ext) return bad(`a take is audio (${Object.keys(TAKE_TYPES).join(', ')}), got ${type || 'no type'}`)
|
|
122
|
+
const file = writeTake(root, line.voice, line.text, new Uint8Array(await req.arrayBuffer()), ext)
|
|
123
|
+
await makeTake(root, line.voice, line.text, { path: relative(root, file), offset: null, mask: [] })
|
|
124
|
+
return Response.json({ ok: true, file: relative(root, file) }, { headers: NO_STORE })
|
|
125
|
+
}
|
|
126
|
+
if (req.method === 'POST' && edit) {
|
|
127
|
+
// his drag and his mask, kept beside the take, the line made again at once
|
|
128
|
+
const e = setTakeEdit(root, line.voice, line.text, await req.json())
|
|
129
|
+
await makeTake(root, line.voice, line.text, { path: line.take?.file ?? '', ...e })
|
|
130
|
+
return Response.json({ ok: true, ...e }, { headers: NO_STORE })
|
|
131
|
+
}
|
|
132
|
+
if (req.method === 'DELETE') return Response.json({ ok: dropTake(root, line.voice, line.text) }, { headers: NO_STORE })
|
|
133
|
+
return null
|
|
134
|
+
}
|
|
135
|
+
|
|
41
136
|
export async function trailerRoutes(req: Request, path: string, root: string, dir: string): Promise<Response | null> {
|
|
42
137
|
const API = '/api/trailer'
|
|
43
138
|
if (path !== API && !path.startsWith(`${API}/`)) return null
|
|
44
139
|
try {
|
|
140
|
+
const voices = await voiceRoutes(req, path, root)
|
|
141
|
+
if (voices) return voices
|
|
45
142
|
if (path === API && req.method === 'GET') {
|
|
46
143
|
const desk: TrailerDesk = { trailers: trailerIds(root).flatMap((id) => trailerInfo(root, id) ?? []) }
|
|
47
144
|
return Response.json(desk, { headers: NO_STORE })
|