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,74 @@
|
|
|
1
|
+
// an identity's public words and pictures through the guard of each repo that speaks as it (wiki
|
|
2
|
+
// tools/shipkit/social-identities.md, The guard on the rows): its profile rows and each account's own (a text, or the
|
|
3
|
+
// pictures a row names), its Discord server's name, roles, categories, channels and topics. The desk reads them with its
|
|
4
|
+
// repo's guard; a push to a venue reads them with the guard of every repo speaking as the identity, before any call
|
|
5
|
+
import { existsSync } from 'node:fs'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import type { Identity } from '../identities/identities.ts'
|
|
8
|
+
import { layoutOf } from './discord-layout.ts'
|
|
9
|
+
import { guardWith, type GuardInput, type SocialUnit } from './unit.ts'
|
|
10
|
+
|
|
11
|
+
/** one public word or picture of an identity, `where` its file and row as a problem line names them */
|
|
12
|
+
export type IdentityWord = { where: string; input: Partial<GuardInput> }
|
|
13
|
+
|
|
14
|
+
/** every row once (an account's row it inherits is the identity's), then the server's layout */
|
|
15
|
+
export function identityWords(i: Identity): IdentityWord[] {
|
|
16
|
+
const out: IdentityWord[] = []
|
|
17
|
+
const seen = new Set<string>()
|
|
18
|
+
const base = i.files ?? i.dir
|
|
19
|
+
const row = (file: string, r: { field: string; value: string; files: string[] }): void => {
|
|
20
|
+
const key = JSON.stringify([r.field, r.value])
|
|
21
|
+
if (seen.has(key)) return
|
|
22
|
+
seen.add(key)
|
|
23
|
+
const files = r.files.map((f) => join(base, f)).filter((f) => existsSync(f))
|
|
24
|
+
out.push({ where: `${file}: row ${r.field}`, input: r.files.length > 0 ? { files } : { texts: [r.value] } })
|
|
25
|
+
}
|
|
26
|
+
for (const r of i.rows) row(i.file, r)
|
|
27
|
+
for (const a of i.accounts) for (const r of a.rows) row(a.file, r)
|
|
28
|
+
const discord = i.accounts.find((a) => a.id === 'discord')
|
|
29
|
+
if (discord != null && existsSync(join(discord.dir, 'layout.md'))) {
|
|
30
|
+
// a layout that does not parse is the layout's own error line, said where it is read
|
|
31
|
+
const l = (() => {
|
|
32
|
+
try {
|
|
33
|
+
return layoutOf(discord)
|
|
34
|
+
} catch {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
})()
|
|
38
|
+
if (l != null) {
|
|
39
|
+
out.push({ where: `${l.file}: the server's name`, input: { texts: [l.name] } })
|
|
40
|
+
// a role's name shows beside each member it is given
|
|
41
|
+
for (const r of l.roles) out.push({ where: `${l.file}: role ${r.name}`, input: { texts: [r.name] } })
|
|
42
|
+
for (const c of l.categories) {
|
|
43
|
+
out.push({ where: `${l.file}: category ${c.name}`, input: { texts: [c.name] } })
|
|
44
|
+
for (const ch of c.channels) out.push({ where: `${l.file}: channel ${ch.name}`, input: { texts: [ch.name, ch.topic].filter((t) => t.trim() !== '') } })
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return out
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** what the guards refuse of an identity's words, one line each, `<file>: row <field>: <problem>` */
|
|
52
|
+
export function identityProblems(units: readonly (SocialUnit | null)[], i: Identity): string[] {
|
|
53
|
+
const words = identityWords(i)
|
|
54
|
+
return [...new Set(units.flatMap((u) => words.flatMap((w) => guardWith(u, w.input).map((p) => `${w.where}: ${p}`))))]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** the social units of the house repos that speak as `id`: the guards a push of its words to a venue passes */
|
|
58
|
+
export async function speakersUnits(id: string, cwd = process.cwd()): Promise<SocialUnit[]> {
|
|
59
|
+
const { houseRepoRoots } = await import('./house.ts')
|
|
60
|
+
const { loadSocialUnit } = await import('./unit.ts')
|
|
61
|
+
const out: SocialUnit[] = []
|
|
62
|
+
for (const r of await houseRepoRoots(cwd)) {
|
|
63
|
+
if (r.speaksAs !== id) continue
|
|
64
|
+
const u = await loadSocialUnit(r.path)
|
|
65
|
+
if (u != null) out.push(u)
|
|
66
|
+
}
|
|
67
|
+
return out
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** the push of an identity's words to a venue, refused while a guard of a repo speaking as it names a problem */
|
|
71
|
+
export async function refuseUnguarded(i: Identity, cwd = process.cwd()): Promise<void> {
|
|
72
|
+
const problems = identityProblems(await speakersUnits(i.id, cwd), i)
|
|
73
|
+
if (problems.length > 0) throw new Error(`the guard of a repo speaking as ${i.id} refuses ${problems.length === 1 ? 'one of its words' : `${problems.length} of its words`}, so nothing is pushed:\n ${problems.join('\n ')}`)
|
|
74
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// every kind a repo's drafts take, with its rules page on the disk (wiki tools/shipkit/social.md, The kind): the shared
|
|
2
|
+
// ones' pages in the house wiki beside the house's identities folder, the project's in the repo. The desk links each
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { LAYOUT } from '../core/layout.ts'
|
|
6
|
+
import { KIND_FOR, kindPage, POST_KINDS, type OwnKind } from './kinds.ts'
|
|
7
|
+
|
|
8
|
+
/** a kind as the desk lists it: `page` its rules page, absolute, and `title` what that page's heading says it is for;
|
|
9
|
+
* both null where no page is on this machine */
|
|
10
|
+
export type DeskKind = { id: string; for: string; own: boolean; page: string | null; title: string | null }
|
|
11
|
+
|
|
12
|
+
/** the house wiki, from the identities folder the desk read: `<house>/wiki`; null outside a house */
|
|
13
|
+
function houseWiki(identitiesDir: string | null): string | null {
|
|
14
|
+
if (identitiesDir == null || !identitiesDir.endsWith(LAYOUT.identities)) return null
|
|
15
|
+
const wiki = join(identitiesDir.slice(0, -LAYOUT.identities.length), 'wiki')
|
|
16
|
+
return existsSync(wiki) ? wiki : null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** a page's heading, the words after its path: `# guides/x — a change a user can use` → `a change a user can use` */
|
|
20
|
+
function titleOf(abs: string): string | null {
|
|
21
|
+
const h = /^# (.+)$/m.exec(readFileSync(abs, 'utf8'))?.[1]?.trim()
|
|
22
|
+
if (h == null) return null
|
|
23
|
+
return /^\S+ — (.+)$/.exec(h)?.[1] ?? h
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** the line a unit kind whose rules page is no file gives */
|
|
27
|
+
export const ownPageMissing = (k: Pick<OwnKind, 'id' | 'page'>): string => `social unit: kind ${k.id} names its page ${k.page}, which is no file of the repo`
|
|
28
|
+
|
|
29
|
+
const at = (abs: string | null): { page: string | null; title: string | null } => (abs != null && existsSync(abs) ? { page: abs, title: titleOf(abs) } : { page: null, title: null })
|
|
30
|
+
|
|
31
|
+
/** the shared kinds then the unit's, each with its page; a unit kind whose page is no file is an error line */
|
|
32
|
+
export function deskKinds(root: string, identitiesDir: string | null, own: readonly OwnKind[], errors: string[]): DeskKind[] {
|
|
33
|
+
const wiki = houseWiki(identitiesDir)
|
|
34
|
+
const shared = POST_KINDS.map((k) => ({ id: k, for: KIND_FOR[k], own: false, ...at(wiki == null ? null : join(wiki, kindPage(k))) }))
|
|
35
|
+
const mine = own.map((k) => {
|
|
36
|
+
const p = at(join(root, k.page))
|
|
37
|
+
if (p.page == null) errors.push(ownPageMissing(k))
|
|
38
|
+
return { id: k.id, for: k.for, own: true, ...p }
|
|
39
|
+
})
|
|
40
|
+
return [...shared, ...mine]
|
|
41
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// what a post is for (wiki guides/post-kinds/index.md): the closed set of kinds a draft's `kind` takes, a project's
|
|
2
|
+
// own kinds from its social unit, the old words each kind replaces, and the one check the load and SK042 share. Pure:
|
|
3
|
+
// the unit module and the hub page import it
|
|
4
|
+
|
|
5
|
+
/** the shared kinds, in the order the desk lists them */
|
|
6
|
+
export const POST_KINDS = ['announcement', 'feature', 'iteration', 'showcase', 'release', 'trailer', 'throwback', 'custom'] as const
|
|
7
|
+
export type PostKind = (typeof POST_KINDS)[number]
|
|
8
|
+
|
|
9
|
+
/** what a post of each kind is for, one line */
|
|
10
|
+
export const KIND_FOR: Readonly<Record<PostKind, string>> = {
|
|
11
|
+
announcement: 'opens a place, or tells big news that is not a version',
|
|
12
|
+
feature: 'shows a change that a user can use now',
|
|
13
|
+
iteration: 'logs a step of the work, unfinished allowed',
|
|
14
|
+
showcase: 'shows the product as it is, with no news',
|
|
15
|
+
release: 'tells a version, from its release file',
|
|
16
|
+
trailer: 'shows a cut that was kept',
|
|
17
|
+
throwback: 'shows where the project started',
|
|
18
|
+
custom: 'fits no kind: the escape hatch, with its kindWhy',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** a shared kind's rules page, from the house wiki's root */
|
|
22
|
+
export const kindPage = (k: PostKind): string => `guides/post-kinds/post-kind-${k}.md`
|
|
23
|
+
|
|
24
|
+
/** the kind a staged draft takes from its source: an approved card shows a change a user can use, a release tells a version */
|
|
25
|
+
export const sourceKind = (s: { review: string } | { release: string }): PostKind => ('review' in s ? 'feature' : 'release')
|
|
26
|
+
|
|
27
|
+
/** a kind a project declares in its social unit: its id, what a post of it is for, its rules page from the repo's root */
|
|
28
|
+
export interface OwnKind {
|
|
29
|
+
id: string
|
|
30
|
+
for: string
|
|
31
|
+
page: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** the words in use before the set closed, each with the kind it maps to by default; null: a text that stays on a
|
|
35
|
+
* venue, a profile row of the identity and no post kind */
|
|
36
|
+
export const OLD_KINDS: Readonly<Record<string, PostKind | null>> = {
|
|
37
|
+
hello: 'announcement',
|
|
38
|
+
welcome: 'announcement',
|
|
39
|
+
devlog: 'iteration',
|
|
40
|
+
wip: 'iteration',
|
|
41
|
+
look: 'iteration',
|
|
42
|
+
roundup: 'iteration',
|
|
43
|
+
people: 'showcase',
|
|
44
|
+
puzzle: 'showcase',
|
|
45
|
+
page: null,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const isPostKind = (k: string): k is PostKind => (POST_KINDS as readonly string[]).includes(k)
|
|
49
|
+
|
|
50
|
+
/** a front matter value as written, trimmed and out of one pair of quotes: `"feature"` is feature, `""` is empty */
|
|
51
|
+
const unquote = (v: string | undefined): string => (v ?? '').trim().replace(/^(["'])(.*)\1$/, '$2').trim()
|
|
52
|
+
|
|
53
|
+
/** a draft's kind and its `kindWhy`, read the one way the load and SK042 read them */
|
|
54
|
+
export const kindOfMeta = (meta: Readonly<Record<string, string | undefined>>): { kind: string; why: string } => ({ kind: unquote(meta['kind']), why: unquote(meta['kindWhy']) })
|
|
55
|
+
|
|
56
|
+
/** why a draft's kind is wrong, or null; `old`: a word of the old words table, which a gate only warns on */
|
|
57
|
+
export type KindProblem = { text: string; old: boolean }
|
|
58
|
+
|
|
59
|
+
const INDEX = 'wiki guides/post-kinds/index.md'
|
|
60
|
+
|
|
61
|
+
/** the kind a draft names, with its `kindWhy`, against the shared set and the project's own kinds */
|
|
62
|
+
export function kindProblem(kind: string, why: string, own: readonly Pick<OwnKind, 'id'>[]): KindProblem | null {
|
|
63
|
+
const k = kind.trim()
|
|
64
|
+
const set = [...POST_KINDS, ...own.map((o) => o.id)].join(', ')
|
|
65
|
+
if (k === '') return { text: `no kind: a draft names what it is for, one of ${set} (${INDEX})`, old: false }
|
|
66
|
+
if (k === 'custom') return why.trim() === '' ? { text: `kind custom names no kindWhy: one line on why no kind fits (wiki ${kindPage('custom')})`, old: false } : null
|
|
67
|
+
if (isPostKind(k) || own.some((o) => o.id === k)) return null
|
|
68
|
+
if (k in OLD_KINDS) {
|
|
69
|
+
const to = OLD_KINDS[k]
|
|
70
|
+
return to == null
|
|
71
|
+
? { text: `kind "${k}" is an old word and no post kind: a text that stays on a venue is a profile row of the identity (wiki tools/shipkit/social-identities.md)`, old: true }
|
|
72
|
+
: { text: `kind "${k}" is an old word: ${to} by default, or the kind its intent reads as (${INDEX}, The old words)`, old: true }
|
|
73
|
+
}
|
|
74
|
+
return { text: `kind "${k}" is not one of ${set}: a project's own kind is declared in its social unit's kinds (${INDEX})`, old: false }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const WORD = /^[a-z][a-z0-9-]*$/
|
|
78
|
+
const REL_MD = /^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$)).+\.md$/
|
|
79
|
+
|
|
80
|
+
/** why a unit's own kinds cannot be read, or null */
|
|
81
|
+
export function ownKindsProblem(kinds: readonly OwnKind[]): string | null {
|
|
82
|
+
const seen = new Set<string>()
|
|
83
|
+
for (const k of kinds) {
|
|
84
|
+
if (typeof k?.id !== 'string' || !WORD.test(k.id)) return `social: kind '${String(k?.id)}' is a lowercase word`
|
|
85
|
+
if (isPostKind(k.id)) return `social: kind '${k.id}' is a shared kind already: a project's kind takes a name of its own`
|
|
86
|
+
if (seen.has(k.id)) return `social: kind '${k.id}' twice`
|
|
87
|
+
seen.add(k.id)
|
|
88
|
+
if (typeof k.for !== 'string' || k.for.trim() === '') return `social: kind '${k.id}' says what a post of it is for (for)`
|
|
89
|
+
if (typeof k.page !== 'string' || !REL_MD.test(k.page)) return `social: kind '${k.id}' page is its rules page, a .md path from the repo's root`
|
|
90
|
+
}
|
|
91
|
+
return null
|
|
92
|
+
}
|
package/src/social/load.ts
CHANGED
|
@@ -5,14 +5,22 @@ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
|
5
5
|
import { join, relative } from 'node:path'
|
|
6
6
|
import { LAYOUT } from '../core/layout.ts'
|
|
7
7
|
import { speakerOf, type Account, type Identities, type Identity } from '../identities/identities.ts'
|
|
8
|
+
import { isPostRating, POST_RATINGS, takes, type PostRating } from '../identities/rating.ts'
|
|
8
9
|
import { fileList, groupKeys, mediaNames, parseDraft, renderedTrailer, resolveMedia, tagList, topicList, type Topic } from './drafts.ts'
|
|
9
10
|
import { compose, fillLink, messageLength } from './compose.ts'
|
|
10
11
|
import { parseFrontmatter, table } from './md.ts'
|
|
11
12
|
import { type Family, familyOf, type Slot, slotOf, type WeeklySlot, weeklySlots } from './presence.ts'
|
|
12
13
|
import { purgedAt } from './media-facts.ts'
|
|
13
|
-
import {
|
|
14
|
+
import { identityProblems } from './identity-words.ts'
|
|
15
|
+
import { deskKinds, type DeskKind } from './kind-pages.ts'
|
|
16
|
+
import { kindOfMeta, kindProblem } from './kinds.ts'
|
|
17
|
+
import { heavyMedia, limitProblem, mbOf, MEDIA_MAX_BYTES } from './media-limit.ts'
|
|
14
18
|
import { pushFailure } from './push.ts'
|
|
15
|
-
import type
|
|
19
|
+
import { ceilingAt, hasLayout, landing, placesOf, type Landing } from './reach.ts'
|
|
20
|
+
import { guardWith, type SocialUnit } from './unit.ts'
|
|
21
|
+
|
|
22
|
+
/** a draft's `release:`, the release it was staged from: `<unit>@<version>` */
|
|
23
|
+
export const RELEASE_REF = /^[a-z0-9][a-z0-9-]*@\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/
|
|
16
24
|
|
|
17
25
|
/** a draft's folder name: the moment it was made, then its topic */
|
|
18
26
|
export const DRAFT_NAME = /^\d{8}-\d{6}-[a-z0-9-]+$/
|
|
@@ -32,6 +40,26 @@ function reviewOf(raw: string | undefined, file: string, errors: string[]): stri
|
|
|
32
40
|
return null
|
|
33
41
|
}
|
|
34
42
|
|
|
43
|
+
function releaseOf(raw: string | undefined, file: string, errors: string[]): string | null {
|
|
44
|
+
const v = raw?.trim() ?? ''
|
|
45
|
+
if (v === '') return null
|
|
46
|
+
if (RELEASE_REF.test(v)) return v
|
|
47
|
+
errors.push(`${file}: release "${v}" is not <unit>@<version>`)
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** a draft's `rating`: unset is safe, but an adult voice's draft names it, and a bad word or an unrated adult draft
|
|
52
|
+
* reads explicit, so it goes only where explicit is taken */
|
|
53
|
+
function ratingOf(raw: string | undefined, adult: boolean, who: string, file: string, errors: string[]): PostRating {
|
|
54
|
+
const v = raw?.trim() ?? ''
|
|
55
|
+
if (isPostRating(v)) return v
|
|
56
|
+
if (v !== '') errors.push(`${file}: rating "${v}" is not ${POST_RATINGS.join(', ')}`)
|
|
57
|
+
else if (adult) errors.push(`${file}: no rating: ${who} is an adult voice, so each draft names one (${POST_RATINGS.join(', ')})`)
|
|
58
|
+
else return 'safe'
|
|
59
|
+
return 'explicit'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
35
63
|
/** a media as the draft names it, and where it is on the disk: its folder, the repo, or anywhere */
|
|
36
64
|
export type Media = { name: string; path: string }
|
|
37
65
|
|
|
@@ -73,6 +101,10 @@ export type SocialPost = {
|
|
|
73
101
|
reply: string
|
|
74
102
|
/** its write page takes the text (`{text}`); else « Open » copies it first */
|
|
75
103
|
prefilled: boolean
|
|
104
|
+
/** the draft's rating: what a publisher labels it with */
|
|
105
|
+
rating: PostRating
|
|
106
|
+
/** why it may not go out: the repo's guard on its draft, or a place under its rating; empty, it may */
|
|
107
|
+
refused: string
|
|
76
108
|
}
|
|
77
109
|
|
|
78
110
|
/** a draft's post.md: a long article of the identity's site */
|
|
@@ -89,6 +121,10 @@ export type Draft = {
|
|
|
89
121
|
identity: string
|
|
90
122
|
title: string
|
|
91
123
|
kind: string
|
|
124
|
+
/** a `custom` draft's line on why no kind fits */
|
|
125
|
+
kindWhy: string
|
|
126
|
+
/** why its kind is wrong (kinds.ts kindProblem), an error line of the load too; null when it is right */
|
|
127
|
+
kindProblem: string | null
|
|
92
128
|
topics: Topic[]
|
|
93
129
|
slot: Slot | null
|
|
94
130
|
status: string
|
|
@@ -97,8 +133,16 @@ export type Draft = {
|
|
|
97
133
|
alt: string
|
|
98
134
|
posts: SocialPost[]
|
|
99
135
|
article: Article | null
|
|
100
|
-
/** the review card it was
|
|
136
|
+
/** the review card it was staged from, any id of its thread; null when none */
|
|
101
137
|
review: string | null
|
|
138
|
+
/** the release it was staged from, `<unit>@<version>`; null when none */
|
|
139
|
+
release: string | null
|
|
140
|
+
/** what it shows: safe, mild or explicit */
|
|
141
|
+
rating: PostRating
|
|
142
|
+
/** the repo's guard's problems with it, one line each: while one stands, nothing of it goes out */
|
|
143
|
+
guard: string[]
|
|
144
|
+
/** the accounts its group headings skip, no place of theirs taking its rating, and why */
|
|
145
|
+
skipped: { account: string; why: string }[]
|
|
102
146
|
}
|
|
103
147
|
|
|
104
148
|
/** an identity's account with the repo's messages to it */
|
|
@@ -114,7 +158,12 @@ export type Desk = {
|
|
|
114
158
|
weekly: WeeklySlot[]
|
|
115
159
|
/** the topics a draft may take: the unit's, else every one the drafts name */
|
|
116
160
|
topics: Topic[]
|
|
161
|
+
/** the kinds a draft may take: the shared set, then the unit's own, each with its rules page */
|
|
162
|
+
kinds: DeskKind[]
|
|
117
163
|
errors: string[]
|
|
164
|
+
/** what is wrong but stays until its repo moves it, one line each: a draft on an old kind word. Shown with the
|
|
165
|
+
* errors, never counted as one */
|
|
166
|
+
warnings: string[]
|
|
118
167
|
}
|
|
119
168
|
|
|
120
169
|
const read = (abs: string): string => readFileSync(abs, 'utf8')
|
|
@@ -175,6 +224,7 @@ function v2Left(root: string, errors: string[]): void {
|
|
|
175
224
|
/** the desk of a repo: every identity with its accounts, the repo's drafts on them, the newest first */
|
|
176
225
|
export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string | undefined; unit?: SocialUnit | null; now?: Date } = {}): Desk {
|
|
177
226
|
const errors = [...ids.errors]
|
|
227
|
+
const warnings: string[] = []
|
|
178
228
|
const unit = o.unit ?? null
|
|
179
229
|
const own = speakerOf(o.speaksAs, ids)
|
|
180
230
|
if (o.speaksAs != null && own == null) errors.push(`repo.config.ts: speaksAs '${o.speaksAs}' is no identity (${ids.identities.map((i) => i.id).join(', ') || 'none'})`)
|
|
@@ -229,7 +279,9 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
|
|
|
229
279
|
dir: ddir,
|
|
230
280
|
identity: speaker.id,
|
|
231
281
|
title: d.meta.title ?? '',
|
|
232
|
-
kind: d.meta.kind
|
|
282
|
+
kind: kindOfMeta(d.meta).kind,
|
|
283
|
+
kindWhy: kindOfMeta(d.meta).why,
|
|
284
|
+
kindProblem: null,
|
|
233
285
|
topics: topicList(d.meta.topics, file, errors, unit?.topics ?? null),
|
|
234
286
|
slot: slotOf(d.meta.slot, file, week, errors),
|
|
235
287
|
status: d.meta.status ?? 'draft',
|
|
@@ -239,7 +291,18 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
|
|
|
239
291
|
posts: [],
|
|
240
292
|
article: article(ddir, root, unit),
|
|
241
293
|
review: reviewOf(d.meta.review, file, errors),
|
|
294
|
+
release: releaseOf(d.meta.release, file, errors),
|
|
295
|
+
rating: ratingOf(d.meta.rating, speaker.adult, speaker.name, file, errors),
|
|
296
|
+
guard: [],
|
|
297
|
+
skipped: [],
|
|
242
298
|
}
|
|
299
|
+
const kp = kindProblem(draft.kind, draft.kindWhy, unit?.kinds ?? [])
|
|
300
|
+
if (kp != null) {
|
|
301
|
+
draft.kindProblem = kp.text
|
|
302
|
+
;(kp.old ? warnings : errors).push(`${file}: ${kp.text}`)
|
|
303
|
+
}
|
|
304
|
+
const landings = new Map<string, Landing[]>()
|
|
305
|
+
const placesFor = (a: DeskAccount): Landing[] => landings.get(a.id) ?? (landings.set(a.id, placesOf(a, errors)), landings.get(a.id)!)
|
|
243
306
|
const footerText = footerOf(accounts)
|
|
244
307
|
// each account heading's message, then a group heading's on every account of the group the draft gives no heading
|
|
245
308
|
const sends: { s: (typeof d.sections)[number]; a: DeskAccount; key: string; from: string }[] = []
|
|
@@ -259,14 +322,32 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
|
|
|
259
322
|
if (b) sends.push({ s, a: b, key, from: s.key })
|
|
260
323
|
}
|
|
261
324
|
for (const { s, a, key, from } of sends) {
|
|
262
|
-
// a place belongs to its account: a group's message lands on the account's own place
|
|
263
|
-
|
|
325
|
+
// a place belongs to its account: a group's message lands on the account's own place, or the first that
|
|
326
|
+
// takes the draft's rating; an account's own heading names its place, which must take it
|
|
327
|
+
const places = placesFor(a)
|
|
328
|
+
let place = s.options.place ?? ''
|
|
329
|
+
let refused = ''
|
|
330
|
+
if (from !== key) {
|
|
331
|
+
const l = landing(a, places, draft.rating)
|
|
332
|
+
if ('skip' in l) {
|
|
333
|
+
draft.skipped.push({ account: a.id, why: l.skip })
|
|
334
|
+
continue
|
|
335
|
+
}
|
|
336
|
+
place = l.place
|
|
337
|
+
} else {
|
|
338
|
+
const ceiling = ceilingAt(a, places, place)
|
|
339
|
+
if (ceiling != null && !takes(ceiling, draft.rating)) {
|
|
340
|
+
refused = `## ${key} goes to ${place || 'its profile'} on ${a.name}, which takes ${ceiling}, and the draft is ${draft.rating}`
|
|
341
|
+
errors.push(`${file}: ${refused}`)
|
|
342
|
+
}
|
|
343
|
+
}
|
|
264
344
|
const footer = from.split('/')[0] === VERTICAL ? footerText : ''
|
|
265
345
|
const tags = tagList(s.options.tags)
|
|
266
346
|
const made = compose(a.id, { text: s.text, tags, footer }, { max: a.max, saturday })
|
|
267
347
|
const at = a.places.find((x) => x.id === place)
|
|
268
|
-
// a Discord place is a channel of
|
|
269
|
-
if (place !== '' &&
|
|
348
|
+
// a Discord place is a channel of its server's layout; with no layout, checked when the bot posts
|
|
349
|
+
if (place !== '' && !places.some((x) => x.id === place) && (a.id !== 'discord' || hasLayout(a)))
|
|
350
|
+
errors.push(`${file}: ## ${a.id} place "${place}" is no ${hasLayout(a) ? `channel of ${a.id}/layout.md` : `file of ${a.id}/places/`}`)
|
|
270
351
|
const title = s.options.title ?? ''
|
|
271
352
|
const write = at?.write || a.write
|
|
272
353
|
const post: SocialPost = {
|
|
@@ -294,11 +375,23 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
|
|
|
294
375
|
pin: s.options.pin === 'true',
|
|
295
376
|
from,
|
|
296
377
|
footer,
|
|
378
|
+
rating: draft.rating,
|
|
379
|
+
refused,
|
|
297
380
|
}
|
|
298
381
|
errors.push(...messageErrors(post, a))
|
|
382
|
+
if (post.media != null) {
|
|
383
|
+
const over = limitProblem(post.media.path, a.limits)
|
|
384
|
+
if (over != null) errors.push(`${file}: media "${post.media.name}" ${over} on ${a.name}: « fit » makes it a copy that fits`)
|
|
385
|
+
}
|
|
299
386
|
a.posts.push(post)
|
|
300
387
|
draft.posts.push(post)
|
|
301
388
|
}
|
|
389
|
+
// the repo's guard reads every public word and every media: while it names a problem, no message goes out
|
|
390
|
+
// a heading's own title (a Reddit or YouTube title) and its tags are public words too
|
|
391
|
+
const said = d.sections.flatMap((s) => [s.text, s.options.title ?? '', s.options.tags ?? ''])
|
|
392
|
+
draft.guard = guardWith(unit, { title: draft.title, alt: draft.alt, texts: [...new Set(said.filter((t) => t.trim() !== ''))], files: draft.media.map((m) => m.path) })
|
|
393
|
+
for (const g of draft.guard) errors.push(`${file}: ${g}`)
|
|
394
|
+
for (const p of draft.posts) if (draft.guard.length > 0) p.refused = `the repo's guard: ${draft.guard[0]}`
|
|
302
395
|
draft.posts.sort((x, y) => accounts.findIndex((a) => a.id === x.platform) - accounts.findIndex((a) => a.id === y.platform))
|
|
303
396
|
drafts.push(draft)
|
|
304
397
|
}
|
|
@@ -313,7 +406,10 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
|
|
|
313
406
|
} else if (i.id === own?.id && !a.posts.some((x) => x.slug === slug)) errors.push(`${a.file}: [[${ref}]] names no draft with a message to ${a.name} in this repo`)
|
|
314
407
|
}
|
|
315
408
|
const topics = unit?.topics ? [...unit.topics] : [...new Set(drafts.flatMap((d) => d.topics))].sort()
|
|
316
|
-
|
|
409
|
+
const kinds = deskKinds(root, ids.dir, unit?.kinds ?? [], errors)
|
|
410
|
+
// the rows and the server of the identity the repo speaks as are public words too: its guard reads them
|
|
411
|
+
if (own != null && unit?.guard != null) errors.push(...identityProblems([unit], own))
|
|
412
|
+
return { root, speaksAs: own?.id ?? null, identities, drafts, weekly: week, topics, kinds, errors, warnings }
|
|
317
413
|
}
|
|
318
414
|
|
|
319
415
|
/** one account of an identity, loud when absent */
|
|
@@ -1,14 +1,75 @@
|
|
|
1
1
|
// the size a committed draft media may take (wiki tools/shipkit/social.md, contract v3): GitHub refuses a file over
|
|
2
2
|
// 100 MB, so the desk's background push would fail with the commit already made. The desk's load reads the disk,
|
|
3
|
-
// SK036 the index at commit
|
|
4
|
-
import { statSync } from 'node:fs'
|
|
3
|
+
// SK036 the index at commit. A venue's own limits (an account's `limits:`) are checked per account it reaches
|
|
4
|
+
import { closeSync, openSync, readSync, statSync } from 'node:fs'
|
|
5
5
|
import { relative } from 'node:path'
|
|
6
6
|
import { gitBin } from '../core/git-bin.ts'
|
|
7
|
+
import type { MediaLimits } from '../identities/identities.ts'
|
|
7
8
|
|
|
8
9
|
export const MEDIA_MAX_BYTES = 95_000_000
|
|
9
10
|
|
|
10
11
|
export const mbOf = (n: number): string => `${Math.round(n / 1e6)} MB`
|
|
11
12
|
|
|
13
|
+
const VIDEO = /\.(mp4|m4v|mov|webm)$/i
|
|
14
|
+
const IMAGE = /\.(png|jpe?g|webp|gif)$/i
|
|
15
|
+
|
|
16
|
+
/** an mp4's length in seconds, read from its `mvhd` box (a few small reads, no ffprobe); null when it has none */
|
|
17
|
+
export function mp4Seconds(path: string): number | null {
|
|
18
|
+
let fd: number
|
|
19
|
+
try {
|
|
20
|
+
fd = openSync(path, 'r')
|
|
21
|
+
} catch {
|
|
22
|
+
return null
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const size = statSync(path).size
|
|
26
|
+
const head = Buffer.alloc(16)
|
|
27
|
+
const box = (at: number): { type: string; len: number; body: number } | null => {
|
|
28
|
+
if (at + 8 > size || readSync(fd, head, 0, 16, at) < 8) return null
|
|
29
|
+
let len = head.readUInt32BE(0)
|
|
30
|
+
let body = at + 8
|
|
31
|
+
if (len === 1) {
|
|
32
|
+
len = Number(head.readBigUInt64BE(8))
|
|
33
|
+
body = at + 16
|
|
34
|
+
} else if (len === 0) len = size - at
|
|
35
|
+
return len < 8 ? null : { type: head.toString('latin1', 4, 8), len, body }
|
|
36
|
+
}
|
|
37
|
+
const find = (from: number, to: number, type: string): { body: number; len: number; at: number } | null => {
|
|
38
|
+
for (let at = from; at < to; ) {
|
|
39
|
+
const b = box(at)
|
|
40
|
+
if (b == null) return null
|
|
41
|
+
if (b.type === type) return { body: b.body, len: b.len, at }
|
|
42
|
+
at += b.len
|
|
43
|
+
}
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
const moov = find(0, size, 'moov')
|
|
47
|
+
const mvhd = moov && find(moov.body, moov.at + moov.len, 'mvhd')
|
|
48
|
+
if (mvhd == null) return null
|
|
49
|
+
const m = Buffer.alloc(32)
|
|
50
|
+
readSync(fd, m, 0, 32, mvhd.body)
|
|
51
|
+
const v1 = m[0] === 1
|
|
52
|
+
const scale = v1 ? m.readUInt32BE(20) : m.readUInt32BE(12)
|
|
53
|
+
const dur = v1 ? Number(m.readBigUInt64BE(24)) : m.readUInt32BE(16)
|
|
54
|
+
return scale > 0 ? dur / scale : null
|
|
55
|
+
} finally {
|
|
56
|
+
closeSync(fd)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** why a media is over a venue's limits (« is 14 MB, over its 5 MB for an image »), or null; a file not on the disk
|
|
61
|
+
* (in the Space) or a kind the venue names no limit for passes */
|
|
62
|
+
export function limitProblem(path: string, l: MediaLimits): string | null {
|
|
63
|
+
const size = statSync(path, { throwIfNoEntry: false })?.size
|
|
64
|
+
if (size == null) return null
|
|
65
|
+
if (IMAGE.test(path) && l.imageBytes != null && size > l.imageBytes) return `is ${mbOf(size)}, over its ${mbOf(l.imageBytes)} for an image`
|
|
66
|
+
if (!VIDEO.test(path)) return null
|
|
67
|
+
if (l.videoBytes != null && size > l.videoBytes) return `is ${mbOf(size)}, over its ${mbOf(l.videoBytes)} for a video`
|
|
68
|
+
const s = l.videoSeconds != null && /\.(mp4|m4v|mov)$/i.test(path) ? mp4Seconds(path) : null
|
|
69
|
+
if (s != null && l.videoSeconds != null && s > l.videoSeconds + 0.05) return `is ${s.toFixed(1)} s, over its ${l.videoSeconds} s for a video`
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
|
|
12
73
|
/** the files of `paths` over the limit that git would commit: inside the repo and not ignored */
|
|
13
74
|
export function heavyMedia(root: string, paths: readonly string[]): { path: string; size: number }[] {
|
|
14
75
|
const big = [...new Set(paths)].flatMap((p) => {
|
package/src/social/presence.ts
CHANGED
|
@@ -216,7 +216,7 @@ export type Slot = { day: string; tag: string }
|
|
|
216
216
|
const SLOT_TAG = /^[a-z0-9-]+$/
|
|
217
217
|
const HOUR = /^(?:[01]\d|2[0-3]):[0-5]\d$/
|
|
218
218
|
|
|
219
|
-
const addDays = (day: string, n: number): string => new Date(dayMs(day) + n * 86_400_000).toISOString().slice(0, 10)
|
|
219
|
+
export const addDays = (day: string, n: number): string => new Date(dayMs(day) + n * 86_400_000).toISOString().slice(0, 10)
|
|
220
220
|
const isDay = (s: string): boolean => /^\d{4}-\d{2}-\d{2}$/.test(s) && !Number.isNaN(dayMs(s)) && addDays(s, 0) === s
|
|
221
221
|
const weekdayOf = (day: string): Weekday => WEEKDAYS[new Date(dayMs(day)).getUTCDay()]!
|
|
222
222
|
/** the Monday that opens a day's week */
|
|
@@ -4,6 +4,7 @@ import { mkdirSync, statSync } from 'node:fs'
|
|
|
4
4
|
import { tmpdir } from 'node:os'
|
|
5
5
|
import { join } from 'node:path'
|
|
6
6
|
import type { Account } from '../../identities/identities.ts'
|
|
7
|
+
import { BLUESKY_ROWS, recordPushed, toPush, type PushReport } from '../../identities/shown.ts'
|
|
7
8
|
import { probeMedia } from '../../trailer/ffmpeg.ts'
|
|
8
9
|
import { richText } from '../richtext.ts'
|
|
9
10
|
import type { SocialPost } from '../load.ts'
|
|
@@ -50,34 +51,31 @@ async function login(a: Account, net: Net = NET): Promise<Session> {
|
|
|
50
51
|
return { did: s.did, accessJwt: s.accessJwt, handle, pds }
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
/** the picture as Bluesky takes it: as it is when small enough, else a jpeg shrunk until it fits */
|
|
54
|
-
function
|
|
55
|
-
const size = (f: string): [number, number] => {
|
|
56
|
-
const p = Bun.spawnSync(['magick', 'identify', '-format', '%w %h', `${f}[0]`], { stdout: 'pipe', stderr: 'pipe' })
|
|
57
|
-
if (p.exitCode !== 0) throw new Error(`magick identify ${f}: ${p.stderr.toString()}`)
|
|
58
|
-
const [w = 0, h = 0] = p.stdout.toString().split(' ').map(Number)
|
|
59
|
-
return [w, h]
|
|
60
|
-
}
|
|
54
|
+
/** the picture as Bluesky takes a blob of it: as it is when small enough, else a jpeg shrunk until it fits */
|
|
55
|
+
function fitted(file: string): { path: string; data: Blob; mime: string } {
|
|
61
56
|
if (!IMAGE.test(file)) throw new Error(`bluesky: ${file} is no picture (png, jpg, webp)`)
|
|
62
57
|
const mime = /\.png$/i.test(file) ? 'image/png' : /\.webp$/i.test(file) ? 'image/webp' : 'image/jpeg'
|
|
63
|
-
if (statSync(file).size <= MAX_IMAGE) {
|
|
64
|
-
const [w, h] = size(file)
|
|
65
|
-
return { data: Bun.file(file), mime, w, h }
|
|
66
|
-
}
|
|
58
|
+
if (statSync(file).size <= MAX_IMAGE) return { path: file, data: Bun.file(file), mime }
|
|
67
59
|
const dir = join(tmpdir(), 'shipkit-social')
|
|
68
60
|
mkdirSync(dir, { recursive: true })
|
|
69
61
|
const out = join(dir, `bluesky-upload-${process.pid}.jpg`)
|
|
70
62
|
for (const [edge, q] of [[2000, 90], [2000, 80], [1600, 80], [1200, 75]] as const) {
|
|
71
63
|
const p = Bun.spawnSync(['magick', file, '-resize', `${edge}x${edge}>`, '-quality', String(q), out], { stderr: 'pipe' })
|
|
72
64
|
if (p.exitCode !== 0) throw new Error(`magick ${file}: ${p.stderr.toString()}`)
|
|
73
|
-
if (statSync(out).size <= MAX_IMAGE) {
|
|
74
|
-
const [w, h] = size(out)
|
|
75
|
-
return { data: Bun.file(out), mime: 'image/jpeg', w, h }
|
|
76
|
-
}
|
|
65
|
+
if (statSync(out).size <= MAX_IMAGE) return { path: out, data: Bun.file(out), mime: 'image/jpeg' }
|
|
77
66
|
}
|
|
78
67
|
throw new Error(`bluesky: ${file} stays over 1 MB even at 1200 px`)
|
|
79
68
|
}
|
|
80
69
|
|
|
70
|
+
/** the picture fitted, with its size for a post's aspect ratio */
|
|
71
|
+
function image(file: string): { data: Blob; mime: string; w: number; h: number } {
|
|
72
|
+
const f = fitted(file)
|
|
73
|
+
const p = Bun.spawnSync(['magick', 'identify', '-format', '%w %h', `${f.path}[0]`], { stdout: 'pipe', stderr: 'pipe' })
|
|
74
|
+
if (p.exitCode !== 0) throw new Error(`magick identify ${f.path}: ${p.stderr.toString()}`)
|
|
75
|
+
const [w = 0, h = 0] = p.stdout.toString().split(' ').map(Number)
|
|
76
|
+
return { data: f.data, mime: f.mime, w, h }
|
|
77
|
+
}
|
|
78
|
+
|
|
81
79
|
/** a service token of the account for `aud`, good for the one method `lxm` */
|
|
82
80
|
async function serviceToken(net: Net, s: Session, aud: string, lxm: string): Promise<string> {
|
|
83
81
|
const q = new URLSearchParams({ aud, lxm, exp: String(Math.floor(Date.now() / 1000) + 30 * 60) })
|
|
@@ -146,14 +144,55 @@ export async function embedOf(post: Pick<SocialPost, 'media' | 'alt'>, s: Sessio
|
|
|
146
144
|
return { $type: 'app.bsky.embed.video', video: clip.blob, alt: post.alt, aspectRatio: { width: clip.w, height: clip.h } }
|
|
147
145
|
}
|
|
148
146
|
|
|
149
|
-
/** the
|
|
150
|
-
|
|
147
|
+
/** the self label a rated post carries, so Bluesky hides it from who opted out: `nudity` for mild, `porn` for
|
|
148
|
+
* explicit; none for safe */
|
|
149
|
+
export function selfLabels(rating: SocialPost['rating']): Record<string, unknown> | null {
|
|
150
|
+
if (rating === 'safe') return null
|
|
151
|
+
return { $type: 'com.atproto.label.defs#selfLabels', values: [{ val: rating === 'mild' ? 'nudity' : 'porn' }] }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** the record a draft's part posts: the message's composed text (the one « Copier » copies) with its facets, its embed,
|
|
155
|
+
* its rating's self label */
|
|
156
|
+
export async function recordOf(a: Account, post: SocialPost, s: Session, net: Net = NET): Promise<Record<string, unknown>> {
|
|
151
157
|
if (post.posted !== '') throw new Error(`${post.slug} is already posted: ${post.posted}`)
|
|
152
158
|
if (post.text === '') throw new Error(`${post.slug}: its ## ${post.from} is empty`)
|
|
153
159
|
if (a.max !== null && post.length > a.max) throw new Error(`${post.slug} is ${post.length} long, over ${a.max}`)
|
|
154
160
|
const embed = await embedOf(post, s, net)
|
|
155
161
|
const rich = richText(post.text)
|
|
156
|
-
|
|
162
|
+
const labels = selfLabels(post.rating)
|
|
163
|
+
return { $type: 'app.bsky.feed.post', text: rich.text, facets: rich.facets, langs: ['en'], createdAt: new Date().toISOString(), embed, ...(labels ? { labels } : {}) }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const PROFILE = 'app.bsky.actor.profile'
|
|
167
|
+
|
|
168
|
+
/** the account's stale avatar and banner rows set on its profile record (wiki tools/shipkit/social-identities.md, What
|
|
169
|
+
* each account shows): each picture a blob, the record's other fields kept, swapped against the cid it was read at,
|
|
170
|
+
* each row recorded in shown.md. No login when nothing is stale; `s` a test's session */
|
|
171
|
+
export async function pushProfilePictures(a: Account, o: { dry: boolean }, net: Net = NET, s?: Session): Promise<PushReport> {
|
|
172
|
+
const out: PushReport = { changes: [], left: [], recorded: [] }
|
|
173
|
+
const stale = toPush(a.uploads, 'bluesky')
|
|
174
|
+
if (stale.length === 0) return out
|
|
175
|
+
const words = stale.map((u) => `${u.field} (${u.files[0]})`).join(', ')
|
|
176
|
+
out.changes.push(o.dry ? `would set the profile's ${words}` : `set the profile's ${words}`)
|
|
177
|
+
if (o.dry) return out
|
|
178
|
+
const session = s ?? (await login(a, net))
|
|
179
|
+
const auth = { Authorization: `Bearer ${session.accessJwt}` }
|
|
180
|
+
const q = new URLSearchParams({ repo: session.did, collection: PROFILE, rkey: 'self' })
|
|
181
|
+
const r = await net.fetch(`${PDS}/com.atproto.repo.getRecord?${q}`, { headers: auth, signal: AbortSignal.timeout(20_000) })
|
|
182
|
+
if (!r.ok && r.status !== 400) throw new Error(`bluesky getRecord: ${r.status} ${await r.text()}`)
|
|
183
|
+
const now = r.ok ? ((await r.json()) as { cid?: string; value?: Record<string, unknown> }) : {}
|
|
184
|
+
const record: Record<string, unknown> = { ...(now.value ?? {}), $type: PROFILE }
|
|
185
|
+
for (const u of stale) {
|
|
186
|
+
const f = fitted(u.abs[0]!)
|
|
187
|
+
const { blob } = await xrpc<{ blob: unknown }>(net, 'com.atproto.repo.uploadBlob', f.data, { ...auth, 'Content-Type': f.mime })
|
|
188
|
+
record[BLUESKY_ROWS[u.field]!] = blob
|
|
189
|
+
}
|
|
190
|
+
await xrpc(net, 'com.atproto.repo.putRecord', JSON.stringify({ repo: session.did, collection: PROFILE, rkey: 'self', record, ...(now.cid ? { swapRecord: now.cid } : {}) }), {
|
|
191
|
+
...auth,
|
|
192
|
+
'Content-Type': 'application/json',
|
|
193
|
+
})
|
|
194
|
+
for (const u of stale) out.recorded.push(recordPushed(a, u))
|
|
195
|
+
return out
|
|
157
196
|
}
|
|
158
197
|
|
|
159
198
|
/** posts a message on the identity's Bluesky account; its link, which the caller records */
|