rvlib-shipkit 2.10.0 → 2.12.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 +22 -0
- package/package.json +1 -1
- package/src/cli/cmd_Media.ts +253 -0
- package/src/cli/cmd_Review.ts +4 -0
- package/src/cli/cmd_Trailer.ts +4 -0
- package/src/cli/family-pages.ts +1 -0
- package/src/cli/registry.ts +2 -0
- package/src/collections/pings.ts +6 -4
- package/src/core/app-icon.ts +17 -4
- package/src/core/scratch-objects.ts +56 -0
- package/src/core/trace-audit.ts +13 -1
- package/src/home/home-paths.ts +4 -0
- package/src/home/home-routes.ts +36 -2
- package/src/home/hubs.ts +5 -0
- package/src/home/inbox-shape.ts +188 -0
- package/src/home/inbox.ts +104 -0
- package/src/home/run-daemon.ts +12 -2
- package/src/home/serve-web.ts +161 -16
- package/src/ledger/git-scan.ts +73 -25
- package/src/ledger/repo-view.ts +2 -22
- package/src/media-kinds.ts +14 -0
- package/src/media-store/content.ts +61 -0
- package/src/media-store/daemon.ts +91 -0
- package/src/media-store/db.ts +74 -0
- package/src/media-store/fact.ts +9 -0
- package/src/media-store/hand.ts +58 -0
- package/src/media-store/kind.ts +44 -0
- package/src/media-store/purge.ts +139 -0
- package/src/media-store/put.ts +120 -0
- package/src/media-store/remote.ts +93 -0
- package/src/media-store/space.ts +167 -0
- package/src/media-store/sync.ts +101 -0
- package/src/media-store/upload.ts +98 -0
- package/src/repo-config.ts +4 -0
- package/src/review/anim.ts +6 -5
- package/src/review/cells.ts +5 -1
- package/src/review/media-kind.ts +84 -0
- package/src/review/media-read.ts +48 -0
- package/src/review/model.ts +22 -1
- package/src/review/previews.ts +41 -12
- package/src/review/routes.ts +32 -8
- package/src/review/store.ts +102 -40
- package/src/review/trailer-desk.ts +79 -46
- package/src/review/trailer-media.ts +181 -0
- package/src/review/trailer-routes.ts +5 -2
- package/src/review/trailer-shots.ts +89 -0
- package/src/serve/hub-app/cols-svc.ts +12 -1
- package/src/serve/hub-app/home-st.ts +39 -9
- package/src/serve/hub-app/home.html +2 -1
- package/src/serve/hub-app/hub-app.tsx +7 -23
- package/src/serve/hub-app/icons.tsx +2 -0
- package/src/serve/hub-app/inbox-st.ts +144 -0
- package/src/serve/hub-app/inbox-view.tsx +205 -0
- package/src/serve/hub-app/inbox.css +73 -0
- package/src/serve/hub-app/item-view.tsx +19 -0
- package/src/serve/hub-app/keys.ts +4 -3
- package/src/serve/hub-app/palette-st.ts +2 -1
- package/src/serve/hub-app/project-list.tsx +1 -0
- package/src/serve/hub-app/projects-svc.ts +1 -1
- package/src/serve/hub-app/repo-st.ts +1 -1
- package/src/serve/hub-app/review/review-st.ts +15 -3
- package/src/serve/hub-app/review/review-thread.tsx +5 -4
- package/src/serve/hub-app/review.css +1 -1
- package/src/serve/hub-app/test-view.tsx +9 -2
- package/src/serve/hub-app/tests-svc.ts +16 -1
- package/src/serve/hub-runtime.ts +9 -4
- package/src/serve/resources-wire.ts +48 -0
- package/src/serve/serve-hub.ts +11 -7
- package/src/serve/warm-cell.ts +6 -1
- package/src/trailer/footage.ts +6 -2
- package/src/trailer/passage.ts +8 -3
- package/src/trailer/prune.ts +6 -10
- package/src/trailer/shelf.ts +16 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// /api/resources.json on the wire: the one flat list a page polls every ten
|
|
2
|
+
// seconds, serialized once per compute and answered 304 while the page holds
|
|
3
|
+
// it. A test file carries its last run only: its page reads the whole run
|
|
4
|
+
// list from /api/test-runs.json when it opens (the history is half the bytes
|
|
5
|
+
// of a big repo).
|
|
6
|
+
//
|
|
7
|
+
// the one constraint a reader breaks first: the ETag covers the live parts
|
|
8
|
+
// (the plan rows, the hub problems) too, so a moved plan is never a 304.
|
|
9
|
+
import type { Resource } from '../collections/collection-types.ts'
|
|
10
|
+
|
|
11
|
+
/** the list as the page receives it: a test file's runs cut to the last one */
|
|
12
|
+
export const leanResources = (rs: readonly Resource[]): Resource[] =>
|
|
13
|
+
rs.map((r) => (r.test == null || r.test.runs.length <= 1 ? r : { ...r, test: { ...r.test, runs: r.test.runs.slice(0, 1) } }))
|
|
14
|
+
|
|
15
|
+
type Rows = { collections: unknown; resources: Resource[] }
|
|
16
|
+
type Wire = { head: string; tag: string }
|
|
17
|
+
|
|
18
|
+
/** the serialized list, once per computed answer */
|
|
19
|
+
const wires = new WeakMap<Rows, Wire>()
|
|
20
|
+
const wireOf = (rows: Rows): Wire => {
|
|
21
|
+
let w = wires.get(rows)
|
|
22
|
+
if (w == null) {
|
|
23
|
+
const head = JSON.stringify({ collections: rows.collections, resources: leanResources(rows.resources) }).slice(0, -1)
|
|
24
|
+
w = { head, tag: Bun.hash(head).toString(36) }
|
|
25
|
+
wires.set(rows, w)
|
|
26
|
+
}
|
|
27
|
+
return w
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** the answer, 304 when the page sent the same tag; gzipped (and kept for the next page) when it takes it */
|
|
31
|
+
export function resourcesAnswer(req: Request, rows: Rows, live: Record<string, unknown>, zipped: { tag: string; body: Uint8Array<ArrayBuffer> } | null): { res: Response; zipped: typeof zipped } {
|
|
32
|
+
const w = wireOf(rows)
|
|
33
|
+
const tail = JSON.stringify(live).slice(1)
|
|
34
|
+
const tag = `"${w.tag}-${Bun.hash(tail).toString(36)}"`
|
|
35
|
+
const headers = { 'Content-Type': 'application/json', ETag: tag, 'Cache-Control': 'no-cache', Vary: 'Accept-Encoding' }
|
|
36
|
+
if (req.headers.get('If-None-Match') === tag) return { res: new Response(null, { status: 304, headers: { ETag: tag, 'Cache-Control': 'no-cache' } }), zipped }
|
|
37
|
+
const text = tail === '}' ? `${w.head}}` : `${w.head},${tail}`
|
|
38
|
+
if (!/\bgzip\b/.test(req.headers.get('Accept-Encoding') ?? '')) return { res: new Response(text, { headers }), zipped }
|
|
39
|
+
const z = zipped?.tag === tag ? zipped : { tag, body: Bun.gzipSync(new TextEncoder().encode(text)) }
|
|
40
|
+
return { res: new Response(z.body, { headers: { ...headers, 'Content-Encoding': 'gzip' } }), zipped: z }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** one test file's whole run list, newest first, for its page */
|
|
44
|
+
export function testRunsAnswer(rows: Rows, file: string | null): Response {
|
|
45
|
+
const r = rows.resources.find((x) => x.test != null && x.test.file === file)
|
|
46
|
+
if (r?.test == null) return new Response(`no test file ${file ?? '(none named)'} in this repo`, { status: 404 })
|
|
47
|
+
return Response.json({ file, runs: r.test.runs }, { headers: { 'Cache-Control': 'no-store' } })
|
|
48
|
+
}
|
package/src/serve/serve-hub.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { graphRoutes } from 'rvlib-shipkit/src/wiki/serve-graph.ts'
|
|
|
12
12
|
import type { StudioRoutes } from '../assets/server/studio-server.ts'
|
|
13
13
|
import { comfyBoxUp, type ComfyBox, type ComfyPanelUp } from '../comfy/comfy-panel.ts'
|
|
14
14
|
import { appendAskRemark, appendAssetNote, appendPostFeedback, askDone, askProof, markPosted, pickPostVariant } from '../collections/actions.ts'
|
|
15
|
-
import { brokenRow, projectResources, type Collection, type Instance, type NeedItem } from '../collections/collection-types.ts'
|
|
15
|
+
import { brokenRow, projectResources, type Collection, type Instance, type NeedItem, type Resource } from '../collections/collection-types.ts'
|
|
16
16
|
import type { CheckEvent } from '../core/run-check.ts'
|
|
17
17
|
import { configDirty, readGateBlock, writeGateBlock, type GateEdit } from '../core/when-block.ts'
|
|
18
18
|
import type { InvokedBy } from '../ledger/run-log.ts'
|
|
@@ -33,6 +33,7 @@ import { sameOrigin } from './same-origin.ts'
|
|
|
33
33
|
import { LAYOUT } from '../core/layout.ts'
|
|
34
34
|
import { heldNow, heldText } from '../core/last-good.ts'
|
|
35
35
|
import { WarmCell } from './warm-cell.ts'
|
|
36
|
+
import { resourcesAnswer, testRunsAnswer } from './resources-wire.ts'
|
|
36
37
|
import { readmeRoutes } from './readme-route.ts'
|
|
37
38
|
import { reviewRoutes } from '../review/routes.ts'
|
|
38
39
|
import { embedRoute } from './embed.ts'
|
|
@@ -131,6 +132,8 @@ export type HubHandler = {
|
|
|
131
132
|
invalidate: () => void
|
|
132
133
|
/** compute the warm answers now, the rows first: the hub's load */
|
|
133
134
|
warm: () => Promise<void>
|
|
135
|
+
/** every row that needs someone, from the warm rows as memory holds them: the home's inbox polls it */
|
|
136
|
+
needs: () => Promise<Resource[]>
|
|
134
137
|
stop: () => void
|
|
135
138
|
}
|
|
136
139
|
|
|
@@ -188,6 +191,8 @@ export function hubHandler(d: HubDeps, o: { base?: string; projects?: Gutter } =
|
|
|
188
191
|
const timeline = d.timeline == null ? null : new WarmCell(d.timeline, { stamp: d.stamp })
|
|
189
192
|
const graphs = new Map(d.graphs.map((g) => [g.id, new WarmCell(async () => g.load(), { maxAgeMs: WARM_MAX_AGE_MS })]))
|
|
190
193
|
const fresh = (req: Request): boolean => new URL(req.url).searchParams.get('fresh') === '1'
|
|
194
|
+
/** the last gzipped list, answered again to the next page while it holds */
|
|
195
|
+
let zipped: Parameters<typeof resourcesAnswer>[3] = null
|
|
191
196
|
return {
|
|
192
197
|
tools,
|
|
193
198
|
invalidate: () => {
|
|
@@ -200,6 +205,7 @@ export function hubHandler(d: HubDeps, o: { base?: string; projects?: Gutter } =
|
|
|
200
205
|
await timeline?.warm()
|
|
201
206
|
for (const g of graphs.values()) await g.warm()
|
|
202
207
|
},
|
|
208
|
+
needs: async () => (await rows.get({ held: true })).resources.filter((r) => r.severity != null),
|
|
203
209
|
stop: () => { d.comfy?.stop() },
|
|
204
210
|
async handle(req, path, srv): Promise<Response> {
|
|
205
211
|
if (!sameOrigin(req)) return new Response('refused: a request that changes something must come from the hub page', { status: 403 })
|
|
@@ -243,13 +249,11 @@ export function hubHandler(d: HubDeps, o: { base?: string; projects?: Gutter } =
|
|
|
243
249
|
// under its sections, and a second endpoint would be a
|
|
244
250
|
// second answer to drift from this one
|
|
245
251
|
const r = await rows.get({ fresh: fresh(req) })
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
planned: d.planned?.() ?? null,
|
|
250
|
-
hub: [...(d.hubProblems?.list() ?? []), ...heldProblem()],
|
|
251
|
-
})
|
|
252
|
+
const a = resourcesAnswer(req, r, { planned: d.planned?.() ?? null, hub: [...(d.hubProblems?.list() ?? []), ...heldProblem()] }, zipped)
|
|
253
|
+
zipped = a.zipped
|
|
254
|
+
return a.res
|
|
252
255
|
}
|
|
256
|
+
if (path === '/api/test-runs.json') return testRunsAnswer(await rows.get({}), new URL(req.url).searchParams.get('file'))
|
|
253
257
|
// the previous address, answered while pages opened before the
|
|
254
258
|
// tree are still on screen
|
|
255
259
|
if (path === '/api/collections.json') {
|
package/src/serve/warm-cell.ts
CHANGED
|
@@ -91,7 +91,7 @@ export class WarmCell<T> {
|
|
|
91
91
|
|
|
92
92
|
/** the answer in memory, a stale one kicking a recompute behind it. With
|
|
93
93
|
* nothing in memory yet, or `fresh`, it waits on a compute */
|
|
94
|
-
async get(o: { fresh?: boolean } = {}): Promise<T> {
|
|
94
|
+
async get(o: { fresh?: boolean; held?: boolean } = {}): Promise<T> {
|
|
95
95
|
const watched = this.watched
|
|
96
96
|
this.readAt = this.now()
|
|
97
97
|
if (o.fresh === true) return this.fresh()
|
|
@@ -99,6 +99,11 @@ export class WarmCell<T> {
|
|
|
99
99
|
// nothing in memory, a failed compute included: wait on a new one
|
|
100
100
|
if (v == null) return this.run()
|
|
101
101
|
const moved = this.stale || this.gen !== this.runGen
|
|
102
|
+
// `held`: a reader that polls (the home's inbox) takes what is in memory now, a compute behind it
|
|
103
|
+
if (o.held === true) {
|
|
104
|
+
if (moved && this.running == null) this.kick()
|
|
105
|
+
return v.v
|
|
106
|
+
}
|
|
102
107
|
// the first reader in a while: what is in memory may be hours old,
|
|
103
108
|
// and no save recomputed it meanwhile
|
|
104
109
|
if (moved && !watched) return this.running != null && this.runGen === this.gen ? this.running : this.fresh()
|
package/src/trailer/footage.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync,
|
|
|
5
5
|
import { tmpdir } from 'node:os'
|
|
6
6
|
import { isAbsolute, join } from 'node:path'
|
|
7
7
|
import type { TrailerFilmLine, TrailerUnit } from './adapter.ts'
|
|
8
|
+
import { scratchObjects } from '../core/scratch-objects.ts'
|
|
8
9
|
import { duration } from './ffmpeg.ts'
|
|
9
10
|
import type { Shot, Trailer } from './grammar.ts'
|
|
10
11
|
import { cliArgv, isTake, recipeText, recipeWords, runCommand, type Stamp, specOf, type Take, type TakeFilm, type TakeSpec, takeIsStill, takeName, takeSeconds } from './plan.ts'
|
|
@@ -71,7 +72,8 @@ const git = (root: string, args: string[], env?: Record<string, string>): string
|
|
|
71
72
|
* the world the takes show: every file of the repo as it stands, by its content (`trailer/` and `.shipkit/` left out),
|
|
72
73
|
* or only the `paths` the trailer unit's `stamp` names; a repo with no git: `no-git`. Content addressed: the working
|
|
73
74
|
* tree is staged into a throwaway copy of the index and the staged entries hashed, so the same content dirty or
|
|
74
|
-
* committed is one world, and an edit of the cut alone moves nothing
|
|
75
|
+
* committed is one world, and an edit of the cut alone moves nothing. The blobs the add hashes go to a throwaway
|
|
76
|
+
* object dir too (core/scratch-objects.ts), never into the repo's store
|
|
75
77
|
*/
|
|
76
78
|
export function worldStamp(root: string, paths?: readonly string[]): string {
|
|
77
79
|
const real = git(root, ['rev-parse', '--git-path', 'index'])
|
|
@@ -79,17 +81,19 @@ export function worldStamp(root: string, paths?: readonly string[]): string {
|
|
|
79
81
|
const spec = paths ? ['--', ...paths] : ['--', '.', ':(exclude)trailer', ':(exclude).shipkit']
|
|
80
82
|
if (paths) for (const p of paths) if (!existsSync(join(root, p))) throw new Error(`the trailer unit's stamp names a path the repo does not hold: ${p}`)
|
|
81
83
|
const index = join(tmpdir(), `sk-world-${process.pid}-${Math.random().toString(36).slice(2)}`)
|
|
84
|
+
const objects = scratchObjects(root, tmpdir())
|
|
82
85
|
try {
|
|
83
86
|
// a copy of the real index keeps git's stat cache: only the files that changed are read again
|
|
84
87
|
const from = isAbsolute(real.trim()) ? real.trim() : join(root, real.trim())
|
|
85
88
|
if (existsSync(from)) copyFileSync(from, index)
|
|
86
|
-
const env = { GIT_INDEX_FILE: index }
|
|
89
|
+
const env = { ...objects.env, GIT_INDEX_FILE: index }
|
|
87
90
|
if (git(root, ['add', '-A', ...spec], env) === null) throw new Error('git add into the world\'s throwaway index failed')
|
|
88
91
|
const staged = git(root, ['ls-files', '-s', ...spec], env)
|
|
89
92
|
if (staged === null) throw new Error('git ls-files of the world\'s throwaway index failed')
|
|
90
93
|
return new Bun.CryptoHasher('sha1').update(staged).digest('hex').slice(0, 12)
|
|
91
94
|
} finally {
|
|
92
95
|
rmSync(index, { force: true })
|
|
96
|
+
objects.drop()
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
|
package/src/trailer/passage.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { basename, join, relative } from 'node:path'
|
|
|
5
5
|
import { type Loaded, load, Refused, type Say, takesOfLoaded } from './build.ts'
|
|
6
6
|
import { ffmpeg } from './ffmpeg.ts'
|
|
7
7
|
import { starts, type Trailer } from './grammar.ts'
|
|
8
|
+
import { shotFacts } from './shelf.ts'
|
|
8
9
|
|
|
9
10
|
const outOf = (l: Pick<Loaded, 'dir'>): string => join(l.dir, 'out')
|
|
10
11
|
|
|
@@ -66,8 +67,10 @@ async function versionCut(l: Loaded, v: string, cwd: string): Promise<{ t: Trail
|
|
|
66
67
|
if (!existsSync(text)) throw new Refused(`no ${relative(cwd, text)}`)
|
|
67
68
|
const kept = await load(text, l.root, { dir: l.dir, check: false })
|
|
68
69
|
if (kept.errors.length > 0) throw new Refused(`${v} does not read with today's tool (an older version builds only in a worktree at its tag): ${kept.errors[0]!.message}`)
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
let video = versionVideo(l.dir, v) ?? join(l.dir, 'versions', v, `${basename(l.dir)}-${v}.mp4`)
|
|
71
|
+
// a version the disk let go comes back from the media store
|
|
72
|
+
if (!existsSync(video)) video = (await (await import('../review/trailer-media.ts')).versionVideoBack(l.root, basename(l.dir), v)) ?? video
|
|
73
|
+
if (!existsSync(video)) throw new Refused(`no ${relative(cwd, video)}, on the disk or in the media store`)
|
|
71
74
|
return { t: kept.t, video }
|
|
72
75
|
}
|
|
73
76
|
|
|
@@ -103,13 +106,15 @@ export function keep(l: Loaded, v: string, say: Say, cwd: string): void {
|
|
|
103
106
|
const strip = join(outOf(l), `${l.t.name}.strip.png`)
|
|
104
107
|
if (existsSync(strip)) clone(strip, join(dir, `${l.t.name}.strip.png`))
|
|
105
108
|
const shots = join(outOf(l), `${l.t.name}-shots`)
|
|
109
|
+
// the shelf's facts go with it: a shot the media store let go stays known to the version, fetched back on demand
|
|
106
110
|
const files = existsSync(shots) ? readdirSync(shots) : []
|
|
107
111
|
for (const f of files) clone(join(shots, f), join(dir, 'shots', f))
|
|
112
|
+
const count = new Set([...files.filter((f) => !f.startsWith('.')), ...Object.keys(shotFacts(shots))]).size
|
|
108
113
|
// the clones are the machine's: git keeps the text and the index, never a version's folder
|
|
109
114
|
const ignored = Bun.spawnSync(['git', 'check-ignore', '-q', dir], { cwd: l.root }).exitCode === 0
|
|
110
115
|
const ignore = join(l.dir, 'versions', '.gitignore')
|
|
111
116
|
if (!ignored && !existsSync(ignore)) writeFileSync(ignore, '*/\n')
|
|
112
|
-
say(`ok: kept ${v}: ${relative(cwd, text)}, ${relative(cwd, dir)}/ (the video, the strip, ${
|
|
117
|
+
say(`ok: kept ${v}: ${relative(cwd, text)}, ${relative(cwd, dir)}/ (the video, the strip, ${count} shots)`)
|
|
113
118
|
say(`then: its row in ${relative(cwd, join(l.dir, 'versions', 'index.md'))}, commit ${relative(cwd, text)} and that index, git tag trailer-${basename(l.dir)}-${v}, push the commit and the tag`)
|
|
114
119
|
}
|
|
115
120
|
|
package/src/trailer/prune.ts
CHANGED
|
@@ -163,7 +163,7 @@ function filesUnder(dir: string): string[] {
|
|
|
163
163
|
const cacheOf = async (root: string): Promise<string> => join((await import('./footage.ts')).trailerCache(root, 'footage'), '..')
|
|
164
164
|
|
|
165
165
|
/** each folder's files that go, as of `now`; `now` Infinity names the files only their age keeps too */
|
|
166
|
-
function planOf(cache: string, live: Live,
|
|
166
|
+
function planOf(cache: string, live: Live, now: number): [string, Doomed[]][] {
|
|
167
167
|
const whole = live.broken.length === 0
|
|
168
168
|
// titles/ holds the vertical's drawings too: only a title's and a card's files are the prune's
|
|
169
169
|
const ownTitle = (n: string): boolean => /^(title|card)-[0-9a-f]{16}\./.test(n)
|
|
@@ -176,7 +176,6 @@ function planOf(cache: string, live: Live, views: readonly string[], now: number
|
|
|
176
176
|
]
|
|
177
177
|
const dead = existsSync(cache) ? readdirSync(cache, { withFileTypes: true }).filter((e) => e.isDirectory() && !FOLDERS.includes(e.name)) : []
|
|
178
178
|
for (const d of dead) plan.push([`${d.name}/ (dead)`, filesUnder(join(cache, d.name)).map(doomed)])
|
|
179
|
-
plan.push(['trailer-view/', views.filter((f) => existsSync(f) && now - statSync(f).mtimeMs > RENDER_GRACE_MS).map(doomed)])
|
|
180
179
|
return plan
|
|
181
180
|
}
|
|
182
181
|
|
|
@@ -188,15 +187,14 @@ interface Stamp {
|
|
|
188
187
|
|
|
189
188
|
const stampFile = (cache: string): string => join(cache, 'prune.json')
|
|
190
189
|
|
|
191
|
-
/** what the prune reads that a build can change: every cut's text, every file name in the cache's folders
|
|
192
|
-
*
|
|
190
|
+
/** what the prune reads that a build can change: every cut's text, every file name in the cache's folders. The same
|
|
191
|
+
* key and no spared file of age: the prune would find what it found */
|
|
193
192
|
async function pruneKey(root: string, cache: string): Promise<string> {
|
|
194
|
-
const
|
|
193
|
+
const { cutFiles } = await import('./build.ts')
|
|
195
194
|
const h = new Bun.CryptoHasher('sha1')
|
|
196
195
|
for (const f of cutFiles(root)) h.update(`${f}\0`).update(readFileSync(f)).update('\0')
|
|
197
196
|
const folders = existsSync(cache) ? readdirSync(cache, { withFileTypes: true }).filter((e) => e.isDirectory()) : []
|
|
198
197
|
for (const d of folders.map((e) => e.name).sort()) h.update(`${d}/\0${filesUnder(join(cache, d)).sort().join('\0')}\0`)
|
|
199
|
-
h.update(viewsToDrop(root).sort().join('\0'))
|
|
200
198
|
return h.digest('hex')
|
|
201
199
|
}
|
|
202
200
|
|
|
@@ -214,17 +212,15 @@ export async function pruneIfMoved(root: string, now = Date.now()): Promise<Prun
|
|
|
214
212
|
/** plans every folder's prune, then deletes unless `dry`; a whole prune writes its stamp */
|
|
215
213
|
export async function prune(root: string, o: { dry: boolean; now?: number }): Promise<Pruned> {
|
|
216
214
|
const now = o.now ?? Date.now()
|
|
217
|
-
const { viewsToDrop } = await import('../review/trailer-desk.ts')
|
|
218
215
|
const cache = await cacheOf(root)
|
|
219
216
|
const live = await liveSet(root)
|
|
220
|
-
const
|
|
221
|
-
const plan = planOf(cache, live, views, now)
|
|
217
|
+
const plan = planOf(cache, live, now)
|
|
222
218
|
if (!o.dry && existsSync(cache)) {
|
|
223
219
|
for (const [, ds] of plan) for (const d of ds) rmSync(d.file, { force: true })
|
|
224
220
|
for (const d of readdirSync(cache, { withFileTypes: true }).filter((e) => e.isDirectory() && !FOLDERS.includes(e.name))) rmSync(join(cache, d.name), { recursive: true, force: true })
|
|
225
221
|
rmSync(stampFile(cache), { force: true })
|
|
226
222
|
if (live.broken.length === 0) {
|
|
227
|
-
const spared = planOf(cache, live,
|
|
223
|
+
const spared = planOf(cache, live, Number.POSITIVE_INFINITY).flatMap(([, ds]) => ds.filter((d) => existsSync(d.file)))
|
|
228
224
|
const until = Math.min(Number.MAX_SAFE_INTEGER, ...spared.map((d) => statSync(d.file).mtimeMs + RENDER_GRACE_MS))
|
|
229
225
|
writeFileSync(stampFile(cache), JSON.stringify({ key: await pruneKey(root, cache), until } satisfies Stamp))
|
|
230
226
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// the facts of a shots folder (a build's shelf, a version's shots): each file's content by name, kept in the folder
|
|
2
|
+
// so a shot the media store let go stays known (src/review/trailer-shots.ts reads and writes them)
|
|
3
|
+
import { readFileSync } from 'node:fs'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import type { MediaFact } from '../media-store/fact.ts'
|
|
6
|
+
|
|
7
|
+
export const SHOT_FACTS = '.media.json'
|
|
8
|
+
|
|
9
|
+
/** the facts a shots folder keeps, by file name; none when it has no record */
|
|
10
|
+
export function shotFacts(folder: string): Record<string, MediaFact> {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(readFileSync(join(folder, SHOT_FACTS), 'utf8')) as Record<string, MediaFact>
|
|
13
|
+
} catch {
|
|
14
|
+
return {}
|
|
15
|
+
}
|
|
16
|
+
}
|