rvlib-shipkit 2.19.0 → 2.20.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/annex/annex.ts +227 -0
- package/src/annex/offload.ts +279 -0
- package/src/checks/SK040-release-words.check.ts +43 -0
- package/src/checks/SK041-annex-links.check.ts +28 -0
- package/src/checks/SK042-post-kinds.check.ts +73 -0
- package/src/cli/cmd_Annex.ts +179 -0
- package/src/cli/cmd_Commands.ts +4 -1
- package/src/cli/cmd_Home.ts +3 -2
- package/src/cli/cmd_Messages.ts +155 -0
- package/src/cli/cmd_Releases.ts +48 -0
- package/src/cli/cmd_Review.ts +161 -6
- package/src/cli/cmd_Shot.ts +4 -4
- package/src/cli/cmd_Social.ts +143 -6
- package/src/cli/family-pages.ts +2 -0
- package/src/cli/kit/index.ts +1 -1
- package/src/cli/kit/verb.ts +11 -3
- package/src/cli/registry.ts +6 -1
- package/src/collections/collection-types.ts +8 -1
- package/src/collections/providers.ts +4 -1
- package/src/commands/model.ts +36 -0
- package/src/commands/registry.ts +49 -0
- package/src/commands/routes.ts +59 -0
- package/src/commands/runner.ts +35 -0
- package/src/commands/runs.ts +112 -0
- package/src/core/app-icon.ts +4 -3
- package/src/core/icon-type.ts +8 -0
- package/src/core/jobs.ts +4 -3
- package/src/core/layout.ts +5 -2
- package/src/core/squircle.ts +95 -0
- package/src/home/daemon-jobs.ts +26 -2
- package/src/home/global-units.ts +3 -0
- package/src/home/gui-app/ShipkitGui.swift +302 -5
- package/src/home/gui-app.ts +63 -33
- package/src/home/hmr-keep.ts +134 -0
- package/src/home/home-start.ts +2 -2
- package/src/home/lib-watch.ts +21 -11
- package/src/home/pm.ts +1 -1
- package/src/home/process-apps.ts +181 -0
- package/src/home/resources.ts +3 -3
- package/src/home/run-web.ts +7 -4
- package/src/home/serve-web.ts +64 -14
- package/src/identities/collection.ts +49 -0
- package/src/identities/identities.ts +110 -8
- package/src/identities/machine.ts +4 -3
- package/src/identities/rating.ts +33 -0
- package/src/identities/shown.ts +170 -0
- package/src/identities/steps.ts +5 -0
- package/src/media-store/purge.ts +15 -1
- package/src/media-store/remote.ts +22 -6
- package/src/messages/brief.ts +117 -0
- package/src/messages/collection.ts +40 -0
- package/src/messages/model.ts +171 -0
- package/src/messages/routes.ts +15 -0
- package/src/messages/score.ts +180 -0
- package/src/messages/tabs.ts +13 -0
- package/src/release/notes.ts +130 -0
- package/src/release/run-bump.ts +41 -18
- package/src/release/run-release.ts +22 -4
- package/src/release/run-releases.ts +17 -15
- package/src/release/unit-resolve.ts +9 -0
- package/src/releases/add.ts +66 -0
- package/src/releases/collection.ts +36 -0
- package/src/releases/from-card.ts +66 -0
- package/src/releases/model.ts +267 -0
- package/src/releases/pictures.ts +89 -0
- package/src/releases/routes.ts +36 -0
- package/src/releases/store.ts +71 -0
- package/src/repo-config.ts +5 -0
- package/src/review/cells.ts +0 -11
- package/src/review/format.ts +10 -6
- package/src/review/model.ts +92 -3
- package/src/review/notes.ts +2 -48
- package/src/review/routes.ts +28 -10
- package/src/review/stage-card.ts +197 -0
- package/src/review/stage-routes.ts +123 -0
- package/src/review/store.ts +36 -0
- package/src/review/trailer-card.ts +99 -0
- package/src/review/trailer-desk.ts +57 -4
- package/src/review/trailer-model.ts +41 -7
- package/src/review/trailer-notes.ts +45 -0
- package/src/review/trailer-routes.ts +22 -13
- package/src/serve/hub-app/app-bridge.ts +71 -0
- package/src/serve/hub-app/commands/commands-page.tsx +122 -0
- package/src/serve/hub-app/commands/commands-st.ts +177 -0
- package/src/serve/hub-app/commands.css +24 -0
- package/src/serve/hub-app/hash-route.ts +40 -1
- package/src/serve/hub-app/home-st.ts +11 -2
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/hub-app.tsx +6 -0
- package/src/serve/hub-app/icons.tsx +5 -0
- package/src/serve/hub-app/identities-view.tsx +4 -1
- package/src/serve/hub-app/identities.css +1 -0
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/keys.ts +2 -2
- package/src/serve/hub-app/machine-st.ts +41 -10
- package/src/serve/hub-app/messages/messages-page.tsx +354 -0
- package/src/serve/hub-app/messages/messages-st.ts +74 -0
- package/src/serve/hub-app/messages.css +35 -0
- package/src/serve/hub-app/releases/releases-page.tsx +94 -0
- package/src/serve/hub-app/releases/releases-st.ts +69 -0
- package/src/serve/hub-app/releases.css +25 -0
- package/src/serve/hub-app/repo-sections.ts +15 -1
- package/src/serve/hub-app/repo-st.ts +56 -5
- package/src/serve/hub-app/review/clip-st.ts +31 -3
- package/src/serve/hub-app/review/note-place.ts +31 -0
- package/src/serve/hub-app/review/review-cells.tsx +27 -3
- package/src/serve/hub-app/review/review-st.ts +77 -2
- package/src/serve/hub-app/review/review-thread.tsx +9 -31
- package/src/serve/hub-app/review/review-views.tsx +164 -58
- package/src/serve/hub-app/review/thread-st.ts +108 -41
- package/src/serve/hub-app/review/trailer-card.tsx +187 -0
- package/src/serve/hub-app/review/trailer-page.tsx +62 -31
- package/src/serve/hub-app/review/trailer-st.ts +138 -26
- package/src/serve/hub-app/review/trailer-timeline.tsx +39 -26
- package/src/serve/hub-app/review.css +49 -6
- package/src/serve/hub-app/social/comms-page.tsx +55 -23
- package/src/serve/hub-app/social/identity-pictures.ts +46 -8
- package/src/serve/hub-app/social/kit.tsx +9 -6
- package/src/serve/hub-app/social/post-card.tsx +10 -2
- package/src/serve/hub-app/social/social-model.ts +37 -3
- package/src/serve/hub-app/social/social-page.tsx +179 -65
- package/src/serve/hub-app/social/social-st.ts +79 -26
- package/src/serve/hub-app/social/stage-popup.tsx +268 -0
- package/src/serve/hub-app/social/stage-st.ts +310 -0
- package/src/serve/hub-app/social/step-layout.ts +42 -0
- package/src/serve/hub-app/social.css +60 -1
- package/src/serve/hub-app/tree-build.ts +38 -1
- package/src/serve/hub-app/tree-svc.ts +10 -3
- package/src/serve/project-gutter-route.ts +4 -2
- package/src/serve/same-origin.ts +24 -1
- package/src/serve/serve-hub.ts +15 -1
- package/src/shipkit-files.ts +9 -7
- package/src/shot/shooter.ts +3 -3
- package/src/shot/shot-ask.ts +14 -3
- package/src/shot/shot.shipkit.ts +1 -1
- package/src/social/discord-layout.ts +48 -5
- package/src/social/fit.ts +84 -0
- package/src/social/identity-words.ts +74 -0
- package/src/social/kind-pages.ts +41 -0
- package/src/social/kinds.ts +92 -0
- package/src/social/load.ts +105 -9
- package/src/social/media-limit.ts +63 -2
- package/src/social/presence.ts +1 -1
- package/src/social/publish/bluesky.ts +58 -19
- package/src/social/publish/index.ts +31 -5
- package/src/social/reach.ts +49 -0
- package/src/social/release-stage.ts +173 -0
- package/src/social/routes.ts +42 -7
- package/src/social/stage.ts +227 -0
- package/src/social/strip.ts +85 -0
- package/src/social/text.ts +6 -2
- package/src/social/unit.ts +57 -1
- package/src/social/writes.ts +11 -0
- package/src/trailer/build.ts +15 -2
- package/src/trailer/grammar.ts +14 -4
- package/src/trailer/public-words.ts +41 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// the pictures his hands still have to upload and the texts to paste again, as needs (wiki
|
|
2
|
+
// tools/shipkit/social-identities.md, What each account shows): one row an online account whose rows no api sets and
|
|
3
|
+
// that do not show what the folder holds now. Listed in the house repo alone, where the identities live, so no repo
|
|
4
|
+
// says it twice
|
|
5
|
+
import { existsSync } from 'node:fs'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { type Collection, type Instance } from '../collections/collection-types.ts'
|
|
8
|
+
import { LAYOUT } from '../core/layout.ts'
|
|
9
|
+
import { DEFAULT_HOME_PORT } from '../home/home-paths.ts'
|
|
10
|
+
import { identityAddress } from '../serve/hub-app/identity-address.ts'
|
|
11
|
+
import { readIdentities, type Identities } from './identities.ts'
|
|
12
|
+
|
|
13
|
+
export const PICTURES_COL = 'pictures'
|
|
14
|
+
|
|
15
|
+
/** one row an online account with a stale row for his hands */
|
|
16
|
+
export function pictureNeeds(ids: Identities, home = `http://127.0.0.1:${DEFAULT_HOME_PORT}`): Instance[] {
|
|
17
|
+
const out: Instance[] = []
|
|
18
|
+
for (const i of ids.identities)
|
|
19
|
+
for (const a of i.accounts) {
|
|
20
|
+
const stale = a.uploads.filter((u) => u.stale && u.by == null)
|
|
21
|
+
if (a.live === '' || stale.length === 0) continue
|
|
22
|
+
const where = `${home}${identityAddress({ id: i.id, part: a.id, place: null })}`
|
|
23
|
+
const lines = stale.map((u) =>
|
|
24
|
+
u.kind === 'text'
|
|
25
|
+
? `- **${u.field}**: its text changed since it was pasted on ${u.shown?.on ?? '?'}: paste it again`
|
|
26
|
+
: `- **${u.field}**: ${u.files[0]}${u.shown == null ? ', what it shows is unknown' : `, it shows ${u.shown.file} as of ${u.shown.on} (sha ${u.shown.sha})`}`,
|
|
27
|
+
)
|
|
28
|
+
out.push({
|
|
29
|
+
id: `pictures:${i.id}/${a.id}`,
|
|
30
|
+
text: `update ${i.name}'s ${stale.map((u) => u.field).join(', ')} on ${a.name}`,
|
|
31
|
+
label: `${i.name} on ${a.name}: ${stale.map((u) => u.field).join(', ')}`,
|
|
32
|
+
slot: 'pictures',
|
|
33
|
+
type: 'ask',
|
|
34
|
+
path: `${PICTURES_COL}/${i.id}/${a.id}`,
|
|
35
|
+
virtual: true,
|
|
36
|
+
severity: 'red',
|
|
37
|
+
href: where,
|
|
38
|
+
md: [`${a.name} (${a.live}) does not show these rows of ${i.name} as the folder holds them now:`, '', ...lines, '', `Upload or paste each one, then click « Done, uploaded » or « Done, pasted » beside it: ${where}`].join('\n'),
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
return out
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** only in the repo that holds the identities folder, the house repo */
|
|
45
|
+
export function picturesCollection(root: string): Collection | null {
|
|
46
|
+
const dir = join(root, LAYOUT.identities)
|
|
47
|
+
if (!existsSync(dir)) return null
|
|
48
|
+
return { id: PICTURES_COL, title: 'pictures', kind: 'ask', media: 'text', list: async () => pictureNeeds(readIdentities(dir)) }
|
|
49
|
+
}
|
|
@@ -6,6 +6,9 @@ import { homedir } from 'node:os'
|
|
|
6
6
|
import { isAbsolute, join } from 'node:path'
|
|
7
7
|
import { LAYOUT } from '../core/layout.ts'
|
|
8
8
|
import { parseFrontmatter, rows, section, table, type ProfileRow } from '../social/md.ts'
|
|
9
|
+
import { ceilingOf, type PostRating } from './rating.ts'
|
|
10
|
+
import { uploadsOf, type Upload } from './shown.ts'
|
|
11
|
+
import { stepRefs } from './steps.ts'
|
|
9
12
|
|
|
10
13
|
const SLUG = /^[a-z0-9-]+$/
|
|
11
14
|
|
|
@@ -23,12 +26,36 @@ export type Place = {
|
|
|
23
26
|
when: string
|
|
24
27
|
/** the label a post there must carry */
|
|
25
28
|
flair: string
|
|
29
|
+
/** the most a post there may show (`posts:`); unset, `safe` */
|
|
30
|
+
ceiling: PostRating
|
|
26
31
|
/** absolute */
|
|
27
32
|
file: string
|
|
28
33
|
rules: string
|
|
29
34
|
notes: string
|
|
30
35
|
}
|
|
31
36
|
|
|
37
|
+
/** a venue's media limits, `limits: image 5 MB, video 512 MB 140 s`: bytes and seconds, each unset when unknown */
|
|
38
|
+
export type MediaLimits = { imageBytes?: number; videoBytes?: number; videoSeconds?: number }
|
|
39
|
+
|
|
40
|
+
/** `limits:` read; a part it cannot read is an error at its file */
|
|
41
|
+
export function limitsOf(v: string | undefined, file: string, errors: string[]): MediaLimits {
|
|
42
|
+
const out: MediaLimits = {}
|
|
43
|
+
for (const part of (v ?? '').split(',').map((x) => x.trim()).filter(Boolean)) {
|
|
44
|
+
const m = /^(image|video) (\d+(?:\.\d+)?) MB(?: (\d+) s)?$/.exec(part)
|
|
45
|
+
if (m == null || (m[1] === 'image' && m[3] != null)) {
|
|
46
|
+
errors.push(`${file}: limits "${part}" is not "image <n> MB" or "video <n> MB [<n> s]"`)
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
49
|
+
const bytes = Math.round(Number(m[2]) * 1e6)
|
|
50
|
+
if (m[1] === 'image') out.imageBytes = bytes
|
|
51
|
+
else {
|
|
52
|
+
out.videoBytes = bytes
|
|
53
|
+
if (m[3] != null) out.videoSeconds = Number(m[3])
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return out
|
|
57
|
+
}
|
|
58
|
+
|
|
32
59
|
/** a `## Setup` step: one bullet of the checklist */
|
|
33
60
|
export type Step = { text: string; done: boolean }
|
|
34
61
|
|
|
@@ -45,6 +72,8 @@ export type Account = {
|
|
|
45
72
|
write: string
|
|
46
73
|
inbox: string
|
|
47
74
|
stats: string
|
|
75
|
+
/** the page where its profile is edited (the name, the bio, the avatar) */
|
|
76
|
+
settings: string
|
|
48
77
|
max: number | null
|
|
49
78
|
/** the field a message's text goes in: description, comment; empty, the post's own text */
|
|
50
79
|
text: string
|
|
@@ -60,6 +89,12 @@ export type Account = {
|
|
|
60
89
|
secret: string
|
|
61
90
|
/** Discord: the server's id, its messages' links and the bot's posts */
|
|
62
91
|
guild: string
|
|
92
|
+
/** the most a post on its own profile (the place `me`) may show (`posts:`); unset, `safe` */
|
|
93
|
+
ceiling: PostRating
|
|
94
|
+
/** the venue's own switch a rated post needs, said on its card (X: « mark the media sensitive »); empty, none */
|
|
95
|
+
sensitive: string
|
|
96
|
+
/** the media a post there may carry (`limits:`); empty, none known */
|
|
97
|
+
limits: MediaLimits
|
|
63
98
|
/** absolute */
|
|
64
99
|
file: string
|
|
65
100
|
dir: string
|
|
@@ -69,10 +104,26 @@ export type Account = {
|
|
|
69
104
|
steps: Step[]
|
|
70
105
|
notes: string
|
|
71
106
|
places: Place[]
|
|
107
|
+
/** its picture rows and what it shows of each (shown.md) */
|
|
108
|
+
uploads: Upload[]
|
|
72
109
|
}
|
|
73
110
|
|
|
74
111
|
/** one picture: the file shown, its size, and the same picture in its other formats (an svg beside its png) */
|
|
75
|
-
export type Picture = {
|
|
112
|
+
export type Picture = {
|
|
113
|
+
file: string
|
|
114
|
+
w: number | null
|
|
115
|
+
h: number | null
|
|
116
|
+
also: string[]
|
|
117
|
+
/** each of its files (shown and also) by its version, which moves when its bytes do: a url carries it, so a page
|
|
118
|
+
* never keeps an old picture under a url that stayed the same */
|
|
119
|
+
v: Record<string, string>
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** a file's version: its size and mtime, '' when it is gone; cheap, so every answer computes it fresh */
|
|
123
|
+
export function pictureVersion(abs: string): string {
|
|
124
|
+
const st = statSync(abs, { throwIfNoEntry: false })
|
|
125
|
+
return st == null ? '' : `${st.size.toString(36)}-${Math.round(st.mtimeMs).toString(36)}`
|
|
126
|
+
}
|
|
76
127
|
|
|
77
128
|
/** a company as the forms ask it: `legal.md`, and the private rows of the gitignored `legal.local.md` */
|
|
78
129
|
export type Legal = {
|
|
@@ -87,6 +138,8 @@ export type Identity = {
|
|
|
87
138
|
order: number
|
|
88
139
|
/** it speaks for a repo that names none */
|
|
89
140
|
default: boolean
|
|
141
|
+
/** an adult (18+) voice (`adult: true`): every draft names its rating, and the stage popup picks none for him */
|
|
142
|
+
adult: boolean
|
|
90
143
|
site: string
|
|
91
144
|
siteRepo: string
|
|
92
145
|
/** the folder its picture paths are relative to, absolute: its `files`, else its own folder */
|
|
@@ -135,6 +188,26 @@ function merged(shared: ProfileRow[], own: ProfileRow[]): ProfileRow[] {
|
|
|
135
188
|
return [...shared.map((r) => mine.get(r.field) ?? r), ...own.filter((r) => !shared.some((s) => s.field === r.field))]
|
|
136
189
|
}
|
|
137
190
|
|
|
191
|
+
/** a text row's value as he pastes it: `[[field]]` the other row's value, `<br>` a new line (a table cell holds none),
|
|
192
|
+
* so a venue's text says the bio once, never « the bio » in words */
|
|
193
|
+
export function filledRows(list: ProfileRow[], file: string, errors: string[]): ProfileRow[] {
|
|
194
|
+
const by = new Map(list.map((r) => [r.field, r]))
|
|
195
|
+
return list.map((r) => {
|
|
196
|
+
if (r.files.length > 0 || !/\[\[|<br>/.test(r.value)) return r
|
|
197
|
+
const value = r.value
|
|
198
|
+
.replace(/\[\[([^\]]+)\]\]/g, (all, f: string) => {
|
|
199
|
+
const at = by.get(f)
|
|
200
|
+
if (at == null || at === r || /\[\[/.test(at.value)) {
|
|
201
|
+
errors.push(`${file}: row ${r.field} names [[${f}]], ${at == null ? 'no row' : 'a row that names another'}`)
|
|
202
|
+
return all
|
|
203
|
+
}
|
|
204
|
+
return at.value
|
|
205
|
+
})
|
|
206
|
+
.replace(/\s*<br>\s*/g, '\n')
|
|
207
|
+
return { ...r, value }
|
|
208
|
+
})
|
|
209
|
+
}
|
|
210
|
+
|
|
138
211
|
function places(dir: string, errors: string[]): Place[] {
|
|
139
212
|
const at = join(dir, 'places')
|
|
140
213
|
if (!existsSync(at)) return []
|
|
@@ -158,6 +231,7 @@ function places(dir: string, errors: string[]): Place[] {
|
|
|
158
231
|
write: meta.write ?? '',
|
|
159
232
|
when: meta.when ?? '',
|
|
160
233
|
flair: meta.flair ?? '',
|
|
234
|
+
ceiling: ceilingOf(meta.posts, abs, errors),
|
|
161
235
|
file: abs,
|
|
162
236
|
rules: section(body, 'Rules') ?? '',
|
|
163
237
|
notes: section(body, 'Notes') ?? '',
|
|
@@ -227,7 +301,8 @@ function pictures(files: string | null, dirs: string, file: string, errors: stri
|
|
|
227
301
|
const here: Picture[] = []
|
|
228
302
|
for (const [name, exts] of byName) {
|
|
229
303
|
const [shown, ...rest] = [...exts].sort((x, y) => SHOWN.indexOf(x) - SHOWN.indexOf(y))
|
|
230
|
-
|
|
304
|
+
const v = Object.fromEntries([shown!, ...rest].map((e) => [`${dir}/${name}.${e}`, pictureVersion(join(abs, `${name}.${e}`))]))
|
|
305
|
+
here.push({ file: `${dir}/${name}.${shown}`, ...imageSize(join(abs, `${name}.${shown}`)), also: rest.map((e) => `${dir}/${name}.${e}`), v })
|
|
231
306
|
}
|
|
232
307
|
out.push(...here.sort((x, y) => (y.w ?? 0) * (y.h ?? 0) - (x.w ?? 0) * (x.h ?? 0)))
|
|
233
308
|
}
|
|
@@ -249,6 +324,13 @@ function account(identity: string, id: string, dir: string, shared: ProfileRow[]
|
|
|
249
324
|
const file = join(dir, 'account.md')
|
|
250
325
|
const { meta, body } = parseFrontmatter(read(file))
|
|
251
326
|
linkErrors(file, meta, ['profile', 'live', 'write', 'inbox', 'stats'], errors)
|
|
327
|
+
const own = rows(body, 'Profile', files)
|
|
328
|
+
errors.push(...copiedRows(own, shared, file))
|
|
329
|
+
const merge = filledRows(merged(shared, own), file, errors)
|
|
330
|
+
const automation = meta.automation ?? 'none'
|
|
331
|
+
const secret = meta.secret ?? ''
|
|
332
|
+
const guild = meta.guild ?? ''
|
|
333
|
+
const setup = steps(body)
|
|
252
334
|
return {
|
|
253
335
|
id,
|
|
254
336
|
identity,
|
|
@@ -260,30 +342,49 @@ function account(identity: string, id: string, dir: string, shared: ProfileRow[]
|
|
|
260
342
|
write: meta.write ?? '',
|
|
261
343
|
inbox: meta.inbox ?? '',
|
|
262
344
|
stats: meta.stats ?? '',
|
|
345
|
+
settings: meta.settings ?? '',
|
|
263
346
|
max: meta.max ? Number(meta.max) : null,
|
|
264
347
|
text: meta.text ?? '',
|
|
265
348
|
group: meta.group ?? '',
|
|
266
349
|
place: meta.place ?? '',
|
|
267
350
|
footer: meta.footer ?? '',
|
|
268
|
-
automation
|
|
269
|
-
secret
|
|
270
|
-
guild
|
|
351
|
+
automation,
|
|
352
|
+
secret,
|
|
353
|
+
guild,
|
|
354
|
+
ceiling: ceilingOf(meta.posts, file, errors),
|
|
355
|
+
sensitive: meta.sensitive ?? '',
|
|
356
|
+
limits: limitsOf(meta.limits, file, errors),
|
|
271
357
|
file,
|
|
272
358
|
dir,
|
|
273
|
-
rows:
|
|
359
|
+
rows: merge,
|
|
360
|
+
uploads: uploadsOf({ id, guild, secret, automation }, merge, dir, files, new Set(own.map((r) => r.field)), setup.length === 0 ? null : stepRefs(setup)),
|
|
274
361
|
automationText: section(body, 'Automation') ?? '',
|
|
275
|
-
steps:
|
|
362
|
+
steps: setup,
|
|
276
363
|
notes: section(body, 'Notes') ?? '',
|
|
277
364
|
places: places(dir, errors),
|
|
278
365
|
}
|
|
279
366
|
}
|
|
280
367
|
|
|
368
|
+
/** the identity's texts an account's own text row copies verbatim (over 12 characters): one error line each, so a text
|
|
369
|
+
* lives in one place and every venue follows it (`[[field]]`, or no row at all to inherit it) */
|
|
370
|
+
export function copiedRows(own: readonly ProfileRow[], shared: readonly ProfileRow[], file: string): string[] {
|
|
371
|
+
const out: string[] = []
|
|
372
|
+
for (const r of own) {
|
|
373
|
+
if (r.files.length > 0) continue
|
|
374
|
+
for (const s of shared)
|
|
375
|
+
if (s.files.length === 0 && s.value.length > 12 && !s.value.includes('[[') && r.value.includes(s.value))
|
|
376
|
+
out.push(`${file}: row ${r.field} holds the identity's ${s.field} verbatim: write [[${s.field}]] there, or drop the row to inherit it`)
|
|
377
|
+
}
|
|
378
|
+
return out
|
|
379
|
+
}
|
|
380
|
+
|
|
281
381
|
function identity(id: string, dir: string, errors: string[]): Identity {
|
|
282
382
|
const file = join(dir, 'identity.md')
|
|
283
383
|
const { meta, body } = parseFrontmatter(read(file))
|
|
284
384
|
const files = meta.files ? home(meta.files) : dir
|
|
285
385
|
if (!isAbsolute(files) || !existsSync(files)) errors.push(`${file}: files "${meta.files}" is no folder on this disk`)
|
|
286
|
-
|
|
386
|
+
// filled once here, so the profile shows and copies a shared text (a tier's lines) as an account does
|
|
387
|
+
const shared = filledRows(rows(body, 'Profile', files), file, errors)
|
|
287
388
|
const at = join(dir, 'accounts')
|
|
288
389
|
const accounts: Account[] = []
|
|
289
390
|
if (existsSync(at))
|
|
@@ -301,6 +402,7 @@ function identity(id: string, dir: string, errors: string[]): Identity {
|
|
|
301
402
|
name: meta.name ?? id,
|
|
302
403
|
order: Number(meta.order ?? 99),
|
|
303
404
|
default: meta.default === 'true',
|
|
405
|
+
adult: meta.adult === 'true',
|
|
304
406
|
site: meta.site ?? '',
|
|
305
407
|
siteRepo: meta.siteRepo ?? '',
|
|
306
408
|
files,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// `identity.md` of the folder moves, so the list's 5 s poll costs a few stats
|
|
4
4
|
import { existsSync, readdirSync, statSync } from 'node:fs'
|
|
5
5
|
import { join } from 'node:path'
|
|
6
|
-
import { readIdentities, speakerOf, type Identities, type Identity } from './identities.ts'
|
|
6
|
+
import { pictureVersion, readIdentities, speakerOf, type Identities, type Identity } from './identities.ts'
|
|
7
7
|
|
|
8
8
|
/** one identity as a header of the project list draws it */
|
|
9
9
|
export type RailIdentity = {
|
|
@@ -40,10 +40,11 @@ function folderStamp(dir: string | null): string {
|
|
|
40
40
|
return readdirSync(dir).sort().map((id) => `${id}:${stampOf(join(dir, id, 'identity.md'))}`).join('|')
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
/** the url the gutter serves an identity's mark at (project-gutter-route.ts), its
|
|
43
|
+
/** the url the gutter serves an identity's mark at (project-gutter-route.ts), its version in it: read on every call,
|
|
44
|
+
* so a redrawn avatar moves the url even while the identity's cache holds */
|
|
44
45
|
export const markUrl = (i: Identity): string | null => {
|
|
45
46
|
const f = markFile(i)
|
|
46
|
-
return f == null ? null : `/api/projects/identity-mark/${encodeURIComponent(i.id)}?v=${
|
|
47
|
+
return f == null ? null : `/api/projects/identity-mark/${encodeURIComponent(i.id)}?v=${pictureVersion(f)}`
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
export const railOf = (i: Identity): RailIdentity => ({ id: i.id, name: i.name, default: i.default, colour: colourOf(i), mark: markUrl(i) })
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// an account's rating (wiki tools/shipkit/social-identities.md): its `rating` row names the pictures it shows, `sfw` or
|
|
2
|
+
// `nsfw`, and a row for the other one (`avatar nsfw` on an sfw account) is not its. Pure: the hub's bundle reads it too
|
|
3
|
+
|
|
4
|
+
export const RATINGS: readonly string[] = ['sfw', 'nsfw']
|
|
5
|
+
|
|
6
|
+
/** the `rating` row's first word: `sfw`, `nsfw`, or '' when it names none */
|
|
7
|
+
export const ratingIn = (rows: readonly { field: string; value: string }[]): string => (rows.find((r) => r.field === 'rating')?.value.trim().split(/\s/)[0] ?? '').toLowerCase()
|
|
8
|
+
|
|
9
|
+
/** a row for the other rating, `avatar nsfw` on an sfw account: not this venue's */
|
|
10
|
+
export function otherRating(field: string, rating: string): boolean {
|
|
11
|
+
const last = field.trim().split(/\s+/).pop() ?? ''
|
|
12
|
+
return rating !== '' && RATINGS.includes(last) && last !== rating
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** what a post shows, and what a place takes (wiki tools/shipkit/social-identities.md, The accounts): `safe` no nudity,
|
|
16
|
+
* `mild` nudity never explicit, `explicit` the rest. A place takes a post rated at most its own */
|
|
17
|
+
export const POST_RATINGS = ['safe', 'mild', 'explicit'] as const
|
|
18
|
+
export type PostRating = (typeof POST_RATINGS)[number]
|
|
19
|
+
|
|
20
|
+
export const isPostRating = (v: string): v is PostRating => (POST_RATINGS as readonly string[]).includes(v)
|
|
21
|
+
|
|
22
|
+
/** a place whose ceiling is `ceiling` takes a post rated `r` */
|
|
23
|
+
export const takes = (ceiling: PostRating, r: PostRating): boolean => POST_RATINGS.indexOf(r) <= POST_RATINGS.indexOf(ceiling)
|
|
24
|
+
|
|
25
|
+
/** a `posts:` value read: absent is `safe`, so a place nobody rated takes nothing rated (fail closed); a bad word is an
|
|
26
|
+
* error at its file and reads `safe` too */
|
|
27
|
+
export function ceilingOf(v: string | undefined, file: string, errors: string[]): PostRating {
|
|
28
|
+
const w = (v ?? '').trim()
|
|
29
|
+
if (w === '') return 'safe'
|
|
30
|
+
if (isPostRating(w)) return w
|
|
31
|
+
errors.push(`${file}: posts "${w}" is not ${POST_RATINGS.join(', ')}`)
|
|
32
|
+
return 'safe'
|
|
33
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// what each account shows (wiki tools/shipkit/social-identities.md, What each account shows): `shown.md` beside its
|
|
2
|
+
// account.md records the sha of the picture each row was last given, or of the text he last pasted; a picture row
|
|
3
|
+
// whose files moved since, or that names none recorded, is stale; a text row only once recorded and moved. The one
|
|
4
|
+
// constraint: only a push or his « Done, uploaded » or « Done, pasted » writes a row, never a guess
|
|
5
|
+
import { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { parseFrontmatter, table, type ProfileRow } from '../social/md.ts'
|
|
8
|
+
import { otherRating, ratingIn } from './rating.ts'
|
|
9
|
+
|
|
10
|
+
export const SHOWN_FILE = 'shown.md'
|
|
11
|
+
|
|
12
|
+
/** one recorded row: the short sha the account was given, that file (relative to the identity's `files`), the day */
|
|
13
|
+
export type ShownRow = { row: string; sha: string; file: string; on: string }
|
|
14
|
+
|
|
15
|
+
/** who sets a row: Discord's bot, Bluesky's api, or null, his hands */
|
|
16
|
+
export type Uploader = 'discord' | 'bluesky' | null
|
|
17
|
+
|
|
18
|
+
/** a picture row he uploads, or a text row he pastes */
|
|
19
|
+
export type ShownKind = 'picture' | 'text'
|
|
20
|
+
|
|
21
|
+
/** the file column of a text row: it names no file */
|
|
22
|
+
export const TEXT_FILE = 'text'
|
|
23
|
+
|
|
24
|
+
/** one picture or text row of an account and what the account shows of it */
|
|
25
|
+
export type Upload = {
|
|
26
|
+
field: string
|
|
27
|
+
kind: ShownKind
|
|
28
|
+
/** the row's files, relative to the identity's `files`; the first is what a push sends; none for a text */
|
|
29
|
+
files: string[]
|
|
30
|
+
/** the same files, absolute */
|
|
31
|
+
abs: string[]
|
|
32
|
+
/** each file's short sha now, in the same order; '' for one the disk cannot read; a text: its value's sha alone */
|
|
33
|
+
shas: string[]
|
|
34
|
+
/** the recorded row; null, nobody knows what the account shows */
|
|
35
|
+
shown: ShownRow | null
|
|
36
|
+
/** a picture: its recorded sha is none of its files' as they are now; a text: recorded, and its value moved since */
|
|
37
|
+
stale: boolean
|
|
38
|
+
by: Uploader
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** a server's picture rows the bot sets, by the field Discord's guild takes them in */
|
|
42
|
+
export const DISCORD_ROWS: Readonly<Record<string, string>> = { icon: 'icon', banner: 'banner', 'invite splash': 'splash' }
|
|
43
|
+
/** the profile rows Bluesky's api sets, by the field of app.bsky.actor.profile */
|
|
44
|
+
export const BLUESKY_ROWS: Readonly<Record<string, string>> = { avatar: 'avatar', banner: 'banner' }
|
|
45
|
+
|
|
46
|
+
const held = new Map<string, { stamp: string; sha: string }>()
|
|
47
|
+
|
|
48
|
+
/** a file's short sha (sha256, 12 hex), read again only when its size or mtime moves; '' when it cannot be read */
|
|
49
|
+
export function shaOf(abs: string): string {
|
|
50
|
+
const st = statSync(abs, { throwIfNoEntry: false })
|
|
51
|
+
if (st == null || !st.isFile()) return ''
|
|
52
|
+
const stamp = `${st.size}:${st.mtimeMs}`
|
|
53
|
+
const at = held.get(abs)
|
|
54
|
+
if (at?.stamp === stamp) return at.sha
|
|
55
|
+
const sha = new Bun.CryptoHasher('sha256').update(readFileSync(abs)).digest('hex').slice(0, 12)
|
|
56
|
+
held.set(abs, { stamp, sha })
|
|
57
|
+
return sha
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** a text's short sha (sha256, 12 hex): the value he pastes, its lines as they are */
|
|
61
|
+
export const textSha = (value: string): string => new Bun.CryptoHasher('sha256').update(value).digest('hex').slice(0, 12)
|
|
62
|
+
|
|
63
|
+
/** the rows of an account's `shown.md`; none when it has no file */
|
|
64
|
+
export function readShown(dir: string): ShownRow[] {
|
|
65
|
+
const abs = join(dir, SHOWN_FILE)
|
|
66
|
+
if (!existsSync(abs)) return []
|
|
67
|
+
return table(parseFrontmatter(readFileSync(abs, 'utf8')).body, 'Shown').map(([row = '', sha = '', file = '', on = '']) => ({ row, sha, file, on }))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const page = (name: string, list: readonly ShownRow[]): string =>
|
|
71
|
+
[
|
|
72
|
+
`# What ${name} shows`,
|
|
73
|
+
'',
|
|
74
|
+
"The picture each profile row of this account was last given, or the text last pasted (file `text`), by its short sha (sha256, 12 hex). Written by a push (`sk identities push`, `sk social discord apply`) and by « Done, uploaded » or « Done, pasted » in the hub's identity view. A picture row not here is unknown, so it is to upload; a text row not here is unknown and quiet (wiki tools/shipkit/social-identities.md, What each account shows).",
|
|
75
|
+
'',
|
|
76
|
+
'## Shown',
|
|
77
|
+
'',
|
|
78
|
+
'| row | sha | file | on |',
|
|
79
|
+
'|---|---|---|---|',
|
|
80
|
+
...list.map((r) => `| ${r.row} | ${r.sha} | ${r.file} | ${r.on} |`),
|
|
81
|
+
'',
|
|
82
|
+
].join('\n')
|
|
83
|
+
|
|
84
|
+
/** one row recorded in the account's `shown.md`, the others kept in their order; the file's path, absolute */
|
|
85
|
+
export function writeShown(dir: string, name: string, row: ShownRow): string {
|
|
86
|
+
const list = readShown(dir)
|
|
87
|
+
const at = list.findIndex((r) => r.row === row.row)
|
|
88
|
+
if (at === -1) list.push(row)
|
|
89
|
+
else list[at] = row
|
|
90
|
+
const abs = join(dir, SHOWN_FILE)
|
|
91
|
+
writeFileSync(abs, page(name, list))
|
|
92
|
+
return abs
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type Of = { id: string; guild: string; secret: string; automation: string }
|
|
96
|
+
|
|
97
|
+
/** who sets a row of this account */
|
|
98
|
+
export function uploaderOf(a: Of, field: string): Uploader {
|
|
99
|
+
if (a.id === 'discord' && a.guild !== '' && a.secret !== '' && field in DISCORD_ROWS) return 'discord'
|
|
100
|
+
if (a.id === 'bluesky' && a.automation === 'live' && a.secret !== '' && field in BLUESKY_ROWS) return 'bluesky'
|
|
101
|
+
return null
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** the picture rows an account shows, each with what it shows: its rating's, and a row of the other rating only when
|
|
105
|
+
* the account names it itself (`avatar sfw` on an nsfw venue that also takes an SFW variant), never one it inherits
|
|
106
|
+
* (`avatar nsfw` of the identity on an sfw venue); `files` the folder its paths are relative to. Then the text rows he
|
|
107
|
+
* pastes: the ones `pasted` names (its setup's refs), or with no setup (null) every text row but `rating`; each by the
|
|
108
|
+
* sha of its value as filled, stale only once recorded and moved since */
|
|
109
|
+
export function uploadsOf(a: Of, rows: readonly ProfileRow[], dir: string, files: string | null, own: ReadonlySet<string> = new Set(), pasted: ReadonlySet<string> | null = null): Upload[] {
|
|
110
|
+
const rating = ratingIn(rows)
|
|
111
|
+
const shown = readShown(dir)
|
|
112
|
+
const at = (field: string): ShownRow | null => shown.find((x) => x.row === field) ?? null
|
|
113
|
+
const pictures: Upload[] =
|
|
114
|
+
files == null
|
|
115
|
+
? []
|
|
116
|
+
: rows
|
|
117
|
+
.filter((r) => r.files.length > 0 && (!otherRating(r.field, rating) || own.has(r.field)))
|
|
118
|
+
.map((r) => {
|
|
119
|
+
const abs = r.files.map((f) => join(files, f))
|
|
120
|
+
const shas = abs.map(shaOf)
|
|
121
|
+
const s = at(r.field)
|
|
122
|
+
return { field: r.field, kind: 'picture', files: r.files, abs, shas, shown: s, stale: s == null || s.sha === '' || !shas.includes(s.sha), by: uploaderOf(a, r.field) }
|
|
123
|
+
})
|
|
124
|
+
const texts: Upload[] = rows
|
|
125
|
+
.filter((r) => (files == null || r.files.length === 0) && (pasted == null ? r.field !== 'rating' : pasted.has(r.field)))
|
|
126
|
+
.map((r) => {
|
|
127
|
+
const sha = textSha(r.value)
|
|
128
|
+
const s = at(r.field)
|
|
129
|
+
return { field: r.field, kind: 'text', files: [], abs: [], shas: [sha], shown: s, stale: s != null && s.sha !== sha, by: null }
|
|
130
|
+
})
|
|
131
|
+
return [...pictures, ...texts]
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** the day a row is recorded on, local time */
|
|
135
|
+
export const today = (): string => {
|
|
136
|
+
const d = new Date()
|
|
137
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** a row recorded as given its file now: `file` one of the row's own files (never a path from elsewhere), else its
|
|
141
|
+
* first; a text row as pasted with its value now. `sha`, the one the page showed: refused when the row moved since, so
|
|
142
|
+
* he never records what he did not copy. Throws on a row the account does not show */
|
|
143
|
+
export function recordShown(a: { name: string; dir: string; uploads: readonly Upload[] }, field: string, file?: string, sha?: string): { abs: string; row: ShownRow } {
|
|
144
|
+
const u = a.uploads.find((x) => x.field === field)
|
|
145
|
+
if (u == null) throw new Error(`${a.name} shows no picture or text row "${field}" (${a.uploads.map((x) => x.field).join(', ') || 'none'})`)
|
|
146
|
+
if (u.kind === 'text') {
|
|
147
|
+
if (file != null) throw new Error(`${a.name} ${field} is a text row: it names no file`)
|
|
148
|
+
if (sha != null && sha !== u.shas[0]) throw new Error(`${a.name} ${field} changed since the page showed it: copy it again, then press « Done, pasted »`)
|
|
149
|
+
const row = { row: field, sha: u.shas[0]!, file: TEXT_FILE, on: today() }
|
|
150
|
+
return { abs: writeShown(a.dir, a.name, row), row }
|
|
151
|
+
}
|
|
152
|
+
if (sha != null && !u.shas.includes(sha)) throw new Error(`${a.name} ${field} changed since the page showed it: download it again`)
|
|
153
|
+
const i = file == null ? 0 : u.files.indexOf(file)
|
|
154
|
+
if (i === -1) throw new Error(`${a.name} ${field}: "${file}" is none of its files (${u.files.join(', ')})`)
|
|
155
|
+
if (u.shas[i] === '') throw new Error(`${a.name} ${field}: ${u.files[i]} cannot be read`)
|
|
156
|
+
const row = { row: field, sha: u.shas[i]!, file: u.files[i]!, on: today() }
|
|
157
|
+
return { abs: writeShown(a.dir, a.name, row), row }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** what a picture push did, or would do dry: its lines, the rows it left and why, the `shown.md` files it wrote */
|
|
161
|
+
export type PushReport = { changes: string[]; left: string[]; recorded: string[] }
|
|
162
|
+
|
|
163
|
+
/** the rows an api of this kind sets and that are stale: a push sends each its first file */
|
|
164
|
+
export const toPush = (uploads: readonly Upload[], by: Exclude<Uploader, null>): Upload[] => uploads.filter((u) => u.by === by && u.stale && u.shas[0] !== '')
|
|
165
|
+
|
|
166
|
+
/** a pushed row recorded as given its first file */
|
|
167
|
+
export const recordPushed = (a: { name: string; dir: string }, u: Upload): string => writeShown(a.dir, a.name, { row: u.field, sha: u.shas[0]!, file: u.files[0]!, on: today() })
|
|
168
|
+
|
|
169
|
+
/** the stale rows of an account, as one line's words: « avatar, banner » */
|
|
170
|
+
export const staleWords = (uploads: readonly Upload[]): string => uploads.filter((u) => u.stale).map((u) => u.field).join(', ')
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// an account's setup steps (wiki tools/shipkit/social-identities.md, The accounts): `[[field]]` names a row of its
|
|
2
|
+
// form. Pure: the hub's bundle reads it too
|
|
3
|
+
|
|
4
|
+
/** the rows the steps name, `[[field]]`: the form he fills */
|
|
5
|
+
export const stepRefs = (list: readonly { text: string }[]): Set<string> => new Set(list.flatMap((s) => [...s.text.matchAll(/\[\[([^\]]+)\]\]/g)].map((m) => m[1]!)))
|
package/src/media-store/purge.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// form, `join(store, item, name)`, from the same index rows
|
|
5
5
|
import { existsSync, rmSync, statSync, statfsSync } from 'node:fs'
|
|
6
6
|
import { join, resolve } from 'node:path'
|
|
7
|
+
import { annexKeep, annexSweep, presentAnnexes } from '../annex/annex.ts'
|
|
7
8
|
import { mediaDb, tryWrite } from './db.ts'
|
|
8
9
|
import type { MediaKind } from './kind.ts'
|
|
9
10
|
import type { Space } from './space.ts'
|
|
@@ -66,13 +67,16 @@ export interface PurgeResult {
|
|
|
66
67
|
files: number
|
|
67
68
|
/** a file the HEAD or its kind did not confirm: left on the disk */
|
|
68
69
|
refused: { key: string; why: string }[]
|
|
70
|
+
/** of the files freed, those whose content an annex holds, and the bytes this pass copied there (one content at
|
|
71
|
+
* four paths is copied once) */
|
|
72
|
+
annexed: { files: number; bytes: number }
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
/** free the disk of the candidates, oldest first, until `enough` says stop, `jobs` files at a time: each file waits
|
|
72
76
|
* on its HEAD and its kind's check, so one at a time spends the purge on round trips. A file some process holds open
|
|
73
77
|
* stays */
|
|
74
78
|
export async function purge(kind: MediaKind, dir: string, space: Space, list: readonly Candidate[], o: { enough?: () => boolean; say?: (l: string) => void; jobs?: number } = {}): Promise<PurgeResult> {
|
|
75
|
-
const out: PurgeResult = { freed: 0, files: 0, refused: [] }
|
|
79
|
+
const out: PurgeResult = { freed: 0, files: 0, refused: [], annexed: { files: 0, bytes: 0 } }
|
|
76
80
|
const store = resolve(dir)
|
|
77
81
|
const open = openOf(list.map((c) => join(store, c.item, c.name)))
|
|
78
82
|
let said = Date.now()
|
|
@@ -96,6 +100,15 @@ export async function purge(kind: MediaKind, dir: string, space: Space, list: re
|
|
|
96
100
|
out.refused.push({ key: c.key, why: (e as Error).message })
|
|
97
101
|
return
|
|
98
102
|
}
|
|
103
|
+
try {
|
|
104
|
+
const kept = await annexKeep(path, c.key, c.size)
|
|
105
|
+
if (kept) {
|
|
106
|
+
out.annexed.files++
|
|
107
|
+
if (kept.copied) out.annexed.bytes += c.size
|
|
108
|
+
}
|
|
109
|
+
} catch (e) {
|
|
110
|
+
console.error(`WARN media store: ${(e as Error).message}; the Space holds it, the disk lets it go`)
|
|
111
|
+
}
|
|
99
112
|
rmSync(path, { force: true })
|
|
100
113
|
tryWrite(`${c.item}/${c.name} purged`, (db) => void db.query('update files set local = 0, purged = ? where store = ? and item = ? and name = ?').run(Date.now(), store, c.item, c.name))
|
|
101
114
|
out.freed += c.size
|
|
@@ -114,6 +127,7 @@ export async function purge(kind: MediaKind, dir: string, space: Space, list: re
|
|
|
114
127
|
}
|
|
115
128
|
}
|
|
116
129
|
await Promise.all(Array.from({ length: Math.max(1, o.jobs ?? PURGE_JOBS) }, work))
|
|
130
|
+
if (out.annexed.files > 0) for (const a of await presentAnnexes()) annexSweep(a)
|
|
117
131
|
return out
|
|
118
132
|
}
|
|
119
133
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// a media file from the disk or the Space (wiki tools/shipkit/media-store.md, Read): a URL signed for a file the disk
|
|
2
|
-
// let go, and the file fetched back into its place, checked by its sha, for a tool that needs its bytes
|
|
2
|
+
// let go, and the file fetched back into its place, checked by its sha, for a tool that needs its bytes: from the
|
|
3
|
+
// annex first (wiki tools/shipkit/annex.md), else from the Space
|
|
3
4
|
import { existsSync, renameSync, rmSync, statSync } from 'node:fs'
|
|
4
5
|
import { resolve } from 'node:path'
|
|
6
|
+
import { annexCopy, annexDrop } from '../annex/annex.ts'
|
|
5
7
|
import { shaOf } from './content.ts'
|
|
6
8
|
import { mediaDb, tryWrite } from './db.ts'
|
|
7
9
|
import type { MediaFact } from './fact.ts'
|
|
@@ -65,28 +67,42 @@ export async function signedIfUp(key: string): Promise<string | null> {
|
|
|
65
67
|
|
|
66
68
|
const fetching = new Map<string, Promise<string | null>>()
|
|
67
69
|
|
|
68
|
-
/** the file at `path`, fetched back
|
|
70
|
+
/** the file at `path`, fetched back first when the disk let it go, from an annex else the Space: checked by its sha before it lands,
|
|
69
71
|
* its index row marked local again (`row`: the store, item and name it is indexed under). null when neither holds it */
|
|
70
72
|
export function fetchBack(path: string, key: string, f: MediaFact, row?: { store: string; item: string; name: string }): Promise<string | null> {
|
|
71
73
|
if (existsSync(path)) return Promise.resolve(path)
|
|
72
74
|
const held = fetching.get(path)
|
|
73
75
|
if (held) return held
|
|
74
76
|
const job = (async (): Promise<string | null> => {
|
|
77
|
+
const tmp = `${path}.${process.pid}.back`
|
|
78
|
+
const done = (): string => {
|
|
79
|
+
renameSync(tmp, path)
|
|
80
|
+
if (row) tryWrite(`${row.item}/${row.name} back`, (db) => void db.query('update files set local = 1, purged = null where store = ? and item = ? and name = ?').run(resolve(row.store), row.item, row.name))
|
|
81
|
+
return path
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const at = await annexCopy(key, f.size, tmp)
|
|
85
|
+
if (at) {
|
|
86
|
+
const sha = await shaOf(tmp)
|
|
87
|
+
if (sha === f.sha) return done()
|
|
88
|
+
annexDrop(at, `it hashes to ${sha.slice(0, 12)}, the record of ${key} says ${f.sha.slice(0, 12)}`)
|
|
89
|
+
}
|
|
90
|
+
} catch (e) {
|
|
91
|
+
console.error(`WARN media store: ${path} not read from the annex: ${(e as Error).message}`)
|
|
92
|
+
}
|
|
93
|
+
rmSync(tmp, { force: true })
|
|
75
94
|
const space = (await machineSpace()).space
|
|
76
95
|
if (!space || !(await confirmedUp(key, f.size))) return null
|
|
77
|
-
const tmp = `${path}.${process.pid}.back`
|
|
78
96
|
try {
|
|
79
97
|
await space.get(key, tmp)
|
|
80
98
|
const sha = await shaOf(tmp)
|
|
81
99
|
if (sha !== f.sha || statSync(tmp).size !== f.size) throw new Error(`${key}: the bytes fetched back hash to ${sha.slice(0, 12)}, the record says ${f.sha.slice(0, 12)}`)
|
|
82
|
-
|
|
100
|
+
return done()
|
|
83
101
|
} catch (e) {
|
|
84
102
|
rmSync(tmp, { force: true })
|
|
85
103
|
console.error(`FAIL: media store: ${path} not fetched back: ${(e as Error).message}`)
|
|
86
104
|
return null
|
|
87
105
|
}
|
|
88
|
-
if (row) tryWrite(`${row.item}/${row.name} back`, (db) => void db.query('update files set local = 1, purged = null where store = ? and item = ? and name = ?').run(resolve(row.store), row.item, row.name))
|
|
89
|
-
return path
|
|
90
106
|
})().finally(() => fetching.delete(path))
|
|
91
107
|
fetching.set(path, job)
|
|
92
108
|
return job
|