rvlib-shipkit 2.19.0 → 2.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/package.json +1 -1
- package/src/annex/annex.ts +227 -0
- package/src/annex/offload.ts +279 -0
- package/src/checks/SK004-gitignore-policy.check.ts +6 -3
- 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_GlobalProcesses.ts +2 -107
- package/src/cli/cmd_Home.ts +4 -3
- package/src/cli/cmd_Messages.ts +155 -0
- package/src/cli/cmd_Overview.ts +2 -1
- package/src/cli/cmd_Releases.ts +84 -0
- package/src/cli/cmd_Review.ts +176 -12
- package/src/cli/cmd_Shot.ts +4 -4
- package/src/cli/cmd_Social.ts +151 -8
- package/src/cli/cmd_Sound.ts +17 -4
- package/src/cli/cmd_Trailer.ts +67 -1
- 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 +7 -1
- package/src/collections/collection-types.ts +8 -1
- package/src/collections/providers.ts +4 -1
- package/src/collections/review.ts +23 -4
- 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 +11 -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 +337 -5
- package/src/home/gui-app.ts +64 -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-switch.ts +112 -0
- 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 +121 -14
- 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 +182 -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 +94 -0
- package/src/releases/before.ts +31 -0
- package/src/releases/collection.ts +36 -0
- package/src/releases/from-card.ts +151 -0
- package/src/releases/model.ts +327 -0
- package/src/releases/pictures.ts +110 -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/http.ts +1 -1
- package/src/review/model.ts +102 -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 +47 -1
- package/src/review/trailer-card.ts +99 -0
- package/src/review/trailer-desk.ts +76 -4
- package/src/review/trailer-model.ts +106 -7
- package/src/review/trailer-notes.ts +45 -0
- package/src/review/trailer-routes.ts +119 -13
- package/src/review/trailer-voices.ts +144 -0
- package/src/review/watchers.ts +58 -1
- package/src/serve/hub-app/app-bridge.ts +71 -0
- package/src/serve/hub-app/benign-errors.ts +22 -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 +59 -8
- package/src/serve/hub-app/home-st.ts +19 -2
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/hub-app.tsx +8 -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/project-list.css +7 -2
- package/src/serve/hub-app/project-list.tsx +9 -0
- package/src/serve/hub-app/projects-svc.ts +16 -6
- package/src/serve/hub-app/releases/releases-page.tsx +187 -0
- package/src/serve/hub-app/releases/releases-st.ts +111 -0
- package/src/serve/hub-app/releases.css +52 -0
- package/src/serve/hub-app/repo-sections.ts +16 -2
- package/src/serve/hub-app/repo-st.ts +66 -10
- package/src/serve/hub-app/review/clip-st.ts +34 -4
- package/src/serve/hub-app/review/kit.tsx +3 -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 +92 -36
- package/src/serve/hub-app/review/trailer-st.ts +306 -34
- package/src/serve/hub-app/review/trailer-timeline.tsx +68 -23
- package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
- package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
- package/src/serve/hub-app/review.css +137 -6
- package/src/serve/hub-app/social/comms-page.tsx +65 -28
- 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/next-release.tsx +118 -0
- package/src/serve/hub-app/social/post-card.tsx +10 -2
- package/src/serve/hub-app/social/social-model.ts +39 -3
- package/src/serve/hub-app/social/social-page.tsx +179 -65
- package/src/serve/hub-app/social/social-st.ts +117 -27
- 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 +68 -1
- package/src/serve/hub-app/tree-build.ts +40 -1
- package/src/serve/hub-app/tree-svc.ts +10 -3
- package/src/serve/project-gutter-route.ts +12 -2
- package/src/serve/project-gutter.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/box.ts +33 -12
- package/src/shot/client.ts +1 -1
- package/src/shot/shooter.ts +22 -12
- package/src/shot/shot-ask.ts +14 -3
- package/src/shot/shot.shipkit.ts +1 -1
- package/src/social/desk-index.ts +49 -8
- package/src/social/discord-layout.ts +54 -7
- package/src/social/drafts.ts +1 -1
- 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 +93 -0
- package/src/social/load.ts +125 -10
- 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 +47 -6
- package/src/social/reach.ts +49 -0
- package/src/social/release-stage.ts +277 -0
- package/src/social/routes.ts +44 -8
- package/src/social/stage.ts +246 -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/bed.ts +111 -0
- package/src/trailer/build.ts +72 -40
- package/src/trailer/ffmpeg.ts +6 -0
- package/src/trailer/grammar.ts +37 -6
- package/src/trailer/graph.ts +12 -1
- package/src/trailer/public-words.ts +41 -0
- package/src/trailer/shot-plan.ts +75 -0
- package/src/trailer/shot-state.ts +191 -0
- package/src/trailer/sound/audio.ts +28 -0
- package/src/trailer/sound/brand.ts +53 -3
- package/src/trailer/sound/gen.ts +61 -2
- package/src/trailer/sound/index.ts +25 -11
- package/src/trailer/sound/presets.ts +86 -5
- package/src/trailer/sound/run.ts +1 -1
- package/src/trailer/sound/takes.ts +94 -0
- package/src/trailer/titles.ts +36 -0
- package/src/trailer/url.ts +1 -1
|
@@ -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 */
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
// the accounts shipkit posts to itself (`automation: live`): one publisher a platform, the desk's « Publish
|
|
1
|
+
// the accounts shipkit posts to itself (`automation: live`): one publisher a platform, the desk's « Publish », and
|
|
2
|
+
// `sk social post --publish`, every waiting message of a draft on its live accounts (`--only` one of them), `--edit` a
|
|
3
|
+
// posted one sent again at its link where the venue edits in place
|
|
2
4
|
import { accountOf, draftPost, type Desk } from '../load.ts'
|
|
3
5
|
import { setPosted } from '../writes.ts'
|
|
4
6
|
import { postBluesky } from './bluesky.ts'
|
|
@@ -6,19 +8,58 @@ import { postDiscord } from './discord.ts'
|
|
|
6
8
|
import type { Account } from '../../identities/identities.ts'
|
|
7
9
|
import type { SocialPost } from '../load.ts'
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
export type Publishers = Readonly<Record<string, (a: Account, post: SocialPost) => Promise<string>>>
|
|
12
|
+
|
|
13
|
+
const PUBLISHERS: Publishers = {
|
|
10
14
|
discord: postDiscord,
|
|
11
15
|
bluesky: postBluesky,
|
|
12
16
|
}
|
|
13
17
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
18
|
+
/** the messages `--only` keeps: a message's key (`discord`, `discord/nsfw`) that one alone, else an account's every
|
|
19
|
+
* message. So a release's `--only discord` posts its #announcements message, never the nsfw one beside it */
|
|
20
|
+
export function onlyOf<P extends Pick<SocialPost, 'key' | 'platform'>>(posts: readonly P[], only: string | undefined): P[] {
|
|
21
|
+
if (only == null) return [...posts]
|
|
22
|
+
const one = posts.filter((p) => p.key === only)
|
|
23
|
+
return one.length > 0 ? one : posts.filter((p) => p.platform === only)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** the venues whose publisher edits a posted message at its link; any other refuses a second send */
|
|
27
|
+
const EDITS_IN_PLACE: ReadonlySet<string> = new Set(['discord'])
|
|
28
|
+
|
|
29
|
+
/** posts one message of a draft and records its link; the files written. `publishers` is a test's stub */
|
|
30
|
+
export async function publish(desk: Desk, slug: string, key: string, publishers: Publishers = PUBLISHERS): Promise<{ url: string; files: string[] }> {
|
|
16
31
|
const post = draftPost(desk, slug, key)
|
|
17
32
|
const a = accountOf(desk, post.identity, post.platform)
|
|
18
|
-
|
|
33
|
+
if (post.refused !== '') throw new Error(`${slug} may not go out on ${a.name}: ${post.refused}`)
|
|
34
|
+
const run = publishers[post.platform]
|
|
19
35
|
if (run == null) throw new Error(`${post.platform}: nothing posts there by itself`)
|
|
20
36
|
if (a.automation !== 'live') throw new Error(`${a.file}: its automation is not live`)
|
|
21
|
-
if (post.posted !== '' && post.platform
|
|
37
|
+
if (post.posted !== '' && !EDITS_IN_PLACE.has(post.platform)) throw new Error(`${slug} is already posted on ${a.name}: ${post.posted}`)
|
|
22
38
|
const url = await run(a, post)
|
|
23
39
|
return { url, files: url === post.posted ? [] : setPosted(desk, slug, key, url) }
|
|
24
40
|
}
|
|
41
|
+
|
|
42
|
+
/** each waiting message of a draft on a live account posted, the others named as waiting for his paste; `only` keeps
|
|
43
|
+
* one account's, `edit` sends a posted one again as an edit where its venue edits in place. `before` brings a media
|
|
44
|
+
* the disk let go back first */
|
|
45
|
+
export async function publishDraft(
|
|
46
|
+
desk: Desk,
|
|
47
|
+
slug: string,
|
|
48
|
+
o: { only?: string; edit?: boolean; publishers?: Publishers; before?: (p: SocialPost) => Promise<void> } = {},
|
|
49
|
+
): Promise<{ key: string; line: string }[]> {
|
|
50
|
+
const d = desk.drafts.find((x) => x.slug === slug)
|
|
51
|
+
if (d == null) throw new Error(`no draft ${slug}`)
|
|
52
|
+
const out: { key: string; line: string }[] = []
|
|
53
|
+
for (const p of onlyOf(d.posts, o.only)) {
|
|
54
|
+
const a = accountOf(desk, p.identity, p.platform)
|
|
55
|
+
const live = a.automation === 'live'
|
|
56
|
+
if (p.posted !== '' && !o.edit) out.push({ key: p.key, line: `already posted, ${p.posted}${live && EDITS_IN_PLACE.has(p.platform) ? ' (--edit sends its text again at its link)' : ''}` })
|
|
57
|
+
else if (p.posted !== '' && !EDITS_IN_PLACE.has(p.platform)) out.push({ key: p.key, line: `already posted, ${p.posted}: ${a.name} cannot edit a post in place, nothing sent` })
|
|
58
|
+
else if (!live) out.push({ key: p.key, line: p.posted !== '' ? `already posted, ${p.posted}: ${a.file} is not automation: live, edit it by hand` : 'waits for his paste' })
|
|
59
|
+
else {
|
|
60
|
+
await o.before?.(p)
|
|
61
|
+
out.push({ key: p.key, line: `${p.posted !== '' ? 'edited at its link' : 'posted'}, ${(await publish(desk, slug, p.key, o.publishers)).url}` })
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return out
|
|
65
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// where a rated message lands on an account (wiki tools/shipkit/social-identities.md, The accounts): every place has a
|
|
2
|
+
// ceiling, the most a post there may show; a Discord server's channels take theirs from its layout (age restricted:
|
|
3
|
+
// explicit, else safe), any other place from its `posts:`, the account's own profile (`me`) from the account's. A
|
|
4
|
+
// group's message goes to the account's place when it takes the rating, else to its first place in order that does,
|
|
5
|
+
// else it skips that account. Unrated is safe: fail closed
|
|
6
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
import { ME, type Account } from '../identities/identities.ts'
|
|
9
|
+
import { takes, type PostRating } from '../identities/rating.ts'
|
|
10
|
+
import { parseLayout } from './discord-layout.ts'
|
|
11
|
+
|
|
12
|
+
/** one place a message may land on, the most a post there may show, and whether everyone sees it: a group's message
|
|
13
|
+
* falls back only to a place everyone sees, never to a channel of a few roles */
|
|
14
|
+
export type Landing = { id: string; ceiling: PostRating; open: boolean }
|
|
15
|
+
|
|
16
|
+
/** an account's places in their order: its server's text channels when it has a layout, else its places/ files; a
|
|
17
|
+
* layout that does not read is an error line and lends no channel */
|
|
18
|
+
export function placesOf(a: Pick<Account, 'dir' | 'places'>, errors: string[]): Landing[] {
|
|
19
|
+
const layout = join(a.dir, 'layout.md')
|
|
20
|
+
if (!existsSync(layout)) return a.places.map((p) => ({ id: p.id, ceiling: p.ceiling, open: true }))
|
|
21
|
+
try {
|
|
22
|
+
const l = parseLayout(readFileSync(layout, 'utf8'), layout)
|
|
23
|
+
return l.categories.flatMap((c) =>
|
|
24
|
+
c.channels.filter((x) => !x.voice).map((x) => ({ id: x.name, ceiling: x.ageRestricted ? ('explicit' as const) : ('safe' as const), open: x.only.length === 0 })),
|
|
25
|
+
)
|
|
26
|
+
} catch (e) {
|
|
27
|
+
errors.push((e as Error).message)
|
|
28
|
+
return []
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** the account's places are its server's channels, read from a layout */
|
|
33
|
+
export const hasLayout = (a: Pick<Account, 'dir'>): boolean => existsSync(join(a.dir, 'layout.md'))
|
|
34
|
+
|
|
35
|
+
/** the ceiling of one place of the account, `me` or '' its own profile; null when the account has no such place */
|
|
36
|
+
export function ceilingAt(a: Pick<Account, 'ceiling'>, places: readonly Landing[], place: string): PostRating | null {
|
|
37
|
+
if (place === '' || place === ME) return a.ceiling
|
|
38
|
+
return places.find((p) => p.id === place)?.ceiling ?? null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** where a group's message rated `r` lands on the account: its own place when that takes it, else its first place in
|
|
42
|
+
* order that does; a skip names why */
|
|
43
|
+
export function landing(a: Pick<Account, 'name' | 'place' | 'ceiling'>, places: readonly Landing[], r: PostRating): { place: string } | { skip: string } {
|
|
44
|
+
const own = ceilingAt(a, places, a.place)
|
|
45
|
+
if (own != null && takes(own, r)) return { place: a.place }
|
|
46
|
+
const other = places.find((p) => p.open && p.id !== a.place && takes(p.ceiling, r))
|
|
47
|
+
if (other != null) return { place: other.id }
|
|
48
|
+
return { skip: `${r} > ${own ?? 'safe'}: no place of ${a.name} takes ${/^[aeiou]/.test(r) ? 'an' : 'a'} ${r} post` }
|
|
49
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// a release as the second source of a staged post (wiki tools/shipkit/social.md, A post staged): one draft for the
|
|
2
|
+
// beat, a heading per venue the repo's social unit declares, the release's message under each, its notes in its angle,
|
|
3
|
+
// its polish note raised. Its media: the release file's pictures, each venue the one its place takes (`shotFor`): the
|
|
4
|
+
// safe one for the draft, a heading of its own where the place takes an nsfw one, and the nsfw twin of a venue that
|
|
5
|
+
// cannot (Discord's -nsfw channel), staged to wait for his Publish; else his pick, later, among the approved cards the
|
|
6
|
+
// release ships. Idempotent: one draft a release. A repo with no `release` headings stages nothing. Before the cut,
|
|
7
|
+
// Communications shows next.md as the same input loaded on a scratch copy (`previewNextRelease`), nothing written
|
|
8
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
9
|
+
import { basename, dirname, join } from 'node:path'
|
|
10
|
+
import { loadIdentities } from '../identities/identities.ts'
|
|
11
|
+
import { isPostRating, POST_RATINGS, takes, type PostRating } from '../identities/rating.ts'
|
|
12
|
+
import { localPicture } from '../releases/pictures.ts'
|
|
13
|
+
import { ceilingAt, landing, placesOf } from './reach.ts'
|
|
14
|
+
import { isApproved, verdictOf, type ReviewItem } from '../review/model.ts'
|
|
15
|
+
import { stageablesOf, stageFileOf, type Stageable } from '../review/stage-card.ts'
|
|
16
|
+
import { readAll, storeDir } from '../review/store.ts'
|
|
17
|
+
import { threadsOf, type Thread } from '../review/threads.ts'
|
|
18
|
+
import { changesOf, NEXT, picturesOf, ratingOf, shotFor, type Picture, type Release } from '../releases/model.ts'
|
|
19
|
+
import { hasReleases, readRelease } from '../releases/store.ts'
|
|
20
|
+
import { gitBin } from '../core/git-bin.ts'
|
|
21
|
+
import { setHeadingText } from './drafts.ts'
|
|
22
|
+
import { DRAFT_NAME, draftsDir, type Draft } from './load.ts'
|
|
23
|
+
import { parseFrontmatter, setMeta } from './md.ts'
|
|
24
|
+
import { askPolish, contextOf, draftText, dryLoad, mediaFile, stageDraft, stageDry, type Staged, type StageHeading, type StageInput, type StageMedia } from './stage.ts'
|
|
25
|
+
import { stripCopy } from './strip.ts'
|
|
26
|
+
import { guardWith, type ReleaseHeading, type SocialUnit } from './unit.ts'
|
|
27
|
+
import { commitPaths } from './writes.ts'
|
|
28
|
+
|
|
29
|
+
export type ReleaseAsk = {
|
|
30
|
+
/** the unit released, its id */
|
|
31
|
+
unit: string
|
|
32
|
+
version: string
|
|
33
|
+
/** the release's notes, markdown: its lines go to the angle and, with no message, under each heading */
|
|
34
|
+
notes: string
|
|
35
|
+
/** the short message for users, under each heading */
|
|
36
|
+
message?: string
|
|
37
|
+
/** the release's tag, and the one before it: the range whose approved cards lend it their media */
|
|
38
|
+
tag?: string
|
|
39
|
+
since?: string
|
|
40
|
+
/** the draft's title; unset, `<unit> <version>` */
|
|
41
|
+
title?: string
|
|
42
|
+
now?: Date
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const head = (raw: string): Record<string, string> => parseFrontmatter(raw).meta
|
|
46
|
+
|
|
47
|
+
/** the draft a release already staged, by its `release:` */
|
|
48
|
+
export function releaseDraft(root: string, ref: string): string | null {
|
|
49
|
+
const dir = draftsDir(root)
|
|
50
|
+
if (!existsSync(dir)) return null
|
|
51
|
+
for (const slug of readdirSync(dir).sort()) {
|
|
52
|
+
if (!DRAFT_NAME.test(slug)) continue
|
|
53
|
+
const f = join(dir, slug, 'draft.md')
|
|
54
|
+
if (existsSync(f) && head(readFileSync(f, 'utf8')).release === ref) return slug
|
|
55
|
+
}
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** markdown notes as post lines: its bullets, its plain lines; its headings and comments left out */
|
|
60
|
+
export function noteLines(md: string): string[] {
|
|
61
|
+
return md
|
|
62
|
+
.replace(/<!--[\s\S]*?-->/g, '')
|
|
63
|
+
.split('\n')
|
|
64
|
+
.map((l) => l.trim())
|
|
65
|
+
.filter((l) => l !== '' && !l.startsWith('#'))
|
|
66
|
+
.map((l) => (/^[-*+]\s/.test(l) ? `- ${l.slice(2).trim()}` : l))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type StageCtx = { speaksAs?: string; identitiesDir?: string | null }
|
|
70
|
+
|
|
71
|
+
const ctxOf = (unit: SocialUnit | null, o: StageCtx) => ({ unit, ...(o.speaksAs !== undefined ? { speaksAs: o.speaksAs } : {}), ...(o.identitiesDir !== undefined ? { identitiesDir: o.identitiesDir } : {}) })
|
|
72
|
+
|
|
73
|
+
/** a release's first picture, in the file's order, that a venue whose ceiling is `ceiling` shows; with `nsfw`, its first
|
|
74
|
+
* such picture rated above safe (what a venue that takes more shows that a safe one cannot); null, none */
|
|
75
|
+
function firstFor(file: Release, ceiling: PostRating, nsfw = false): Picture | null {
|
|
76
|
+
for (const ch of changesOf(file)) {
|
|
77
|
+
const s = shotFor(ch, ceiling)
|
|
78
|
+
if (s && (!nsfw || ratingOf(s.picture) !== 'safe')) return s.picture
|
|
79
|
+
}
|
|
80
|
+
return null
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** a release picture as a stage's media, its local file named by its rating and sha */
|
|
84
|
+
async function stagedPicture(root: string, p: Picture): Promise<StageMedia> {
|
|
85
|
+
const file = await localPicture(root, p.url)
|
|
86
|
+
return { file, name: `release-${ratingOf(p)}-${basename(file).slice(0, 12)}` }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** each release heading with the picture its place takes (wiki tools/shipkit/social.md, A post staged): the draft's
|
|
90
|
+
* media is the release's first safe picture, which every place takes; an account heading whose place takes more gets
|
|
91
|
+
* the first nsfw picture its ceiling takes as its own, with its rating; and an account heading under the release's highest
|
|
92
|
+
* rating gets a twin, `name: nsfw`, on the place a message of that rating lands (Discord: its -nsfw channel), its
|
|
93
|
+
* nsfw picture. A group heading lands on many places, so it keeps the safe one */
|
|
94
|
+
async function venueMedia(root: string, file: Release | null, headings: readonly ReleaseHeading[], o: StageCtx): Promise<{ media: StageMedia | null; alt: string; headings: StageHeading[] }> {
|
|
95
|
+
const safe = file ? firstFor(file, 'safe') : null
|
|
96
|
+
const media = safe ? await stagedPicture(root, safe) : null
|
|
97
|
+
const top = file ? picturesOf({ shots: changesOf(file).flatMap((c) => c.shots) }).map(ratingOf).sort((a, b) => POST_RATINGS.indexOf(b) - POST_RATINGS.indexOf(a))[0] : undefined
|
|
98
|
+
if (file == null || top == null || top === 'safe') return { media, alt: safe?.alt ?? '', headings: [...headings] }
|
|
99
|
+
const c = await contextOf(root, { unit: null, ...(o.speaksAs !== undefined ? { speaksAs: o.speaksAs } : {}), ...(o.identitiesDir !== undefined ? { identitiesDir: o.identitiesDir } : {}) })
|
|
100
|
+
const ids = await loadIdentities({ ...(c.identitiesDir != null ? { dir: c.identitiesDir } : {}), cwd: root })
|
|
101
|
+
const accounts = ids.identities.find((i) => i.id === c.speaksAs)?.accounts ?? []
|
|
102
|
+
const out: StageHeading[] = []
|
|
103
|
+
for (const h of headings) {
|
|
104
|
+
const a = accounts.find((x) => x.id === h.id)
|
|
105
|
+
if (a == null) {
|
|
106
|
+
out.push(h)
|
|
107
|
+
continue
|
|
108
|
+
}
|
|
109
|
+
const errors: string[] = []
|
|
110
|
+
const places = placesOf(a, errors)
|
|
111
|
+
const ceiling = ceilingAt(a, places, h.place ?? '') ?? 'safe'
|
|
112
|
+
const own = firstFor(file, ceiling, true)
|
|
113
|
+
out.push(own ? { ...h, rating: ratingOf(own), media: await stagedPicture(root, own) } : h)
|
|
114
|
+
if (takes(ceiling, top)) continue
|
|
115
|
+
const l = landing({ name: a.name, place: h.place ?? '', ceiling: a.ceiling }, places, top)
|
|
116
|
+
if (!('place' in l) || l.place === (h.place ?? '')) continue
|
|
117
|
+
const twin = firstFor(file, ceilingAt(a, places, l.place) ?? 'safe', true)
|
|
118
|
+
if (twin) out.push({ id: h.id, name: 'nsfw', place: l.place, rating: ratingOf(twin), media: await stagedPicture(root, twin) })
|
|
119
|
+
}
|
|
120
|
+
return { media, alt: safe?.alt ?? '', headings: out }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** what a release stages: its file's change titles when the repo keeps one (the notes handed in are only its fallback),
|
|
124
|
+
* else its notes' lines, and each venue's picture. The one builder of the stage and of its preview, so both write the
|
|
125
|
+
* same draft */
|
|
126
|
+
async function releaseInput(root: string, ask: ReleaseAsk, file: Release | null, headings: readonly ReleaseHeading[], o: StageCtx): Promise<StageInput> {
|
|
127
|
+
const ref = `${ask.unit}@${ask.version}`
|
|
128
|
+
const lines = file ? changesOf(file).map((c) => `- ${c.title}`) : noteLines(ask.notes)
|
|
129
|
+
const m = await venueMedia(root, file, headings, o)
|
|
130
|
+
return {
|
|
131
|
+
source: { release: ref },
|
|
132
|
+
title: ask.title ?? (file?.title ? `${file.version}: ${file.title}` : `${ask.unit} ${ask.version}`),
|
|
133
|
+
text: (ask.message?.trim() ? noteLines(ask.message).join('\n') : lines.join('\n')) || `${ask.unit} ${ask.version} is out.`,
|
|
134
|
+
rating: 'safe',
|
|
135
|
+
status: 'draft',
|
|
136
|
+
headings: m.headings,
|
|
137
|
+
...(m.media ? { media: m.media, alt: m.alt } : {}),
|
|
138
|
+
angle: [`Staged from the release ${ref}${ask.tag ? ` (${ask.since ? `${ask.since}..` : ''}${ask.tag})` : ''}. Its notes:`, '', ...lines].join('\n'),
|
|
139
|
+
...(ask.now ? { now: ask.now } : {}),
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** one draft of the release, waiting in Communications: null when the unit declares no release headings; the draft
|
|
144
|
+
* already staged for the same release when there is one, nothing written */
|
|
145
|
+
export async function stageRelease(root: string, unit: SocialUnit | null, ask: ReleaseAsk, o: StageCtx = {}): Promise<(Staged & { created: boolean }) | null> {
|
|
146
|
+
const headings = unit?.release?.headings
|
|
147
|
+
if (headings == null || headings.length === 0) return null
|
|
148
|
+
const ref = `${ask.unit}@${ask.version}`
|
|
149
|
+
const had = releaseDraft(root, ref)
|
|
150
|
+
if (had != null) return { slug: had, files: [], draft: null, errors: [], created: false }
|
|
151
|
+
const input = await releaseInput(root, ask, releaseFileOf(root, ref), headings, o)
|
|
152
|
+
const r = await stageDraft(root, input, ctxOf(unit, o))
|
|
153
|
+
// the range its media comes from, read back by Communications
|
|
154
|
+
if (ask.tag) {
|
|
155
|
+
const f = join(draftsDir(root), r.slug, 'draft.md')
|
|
156
|
+
writeFileSync(f, setMeta(readFileSync(f, 'utf8'), 'range', `${ask.since ? `${ask.since}..` : ''}${ask.tag}`))
|
|
157
|
+
commitPaths([f], `social: ${r.slug} names the range of ${ref}`)
|
|
158
|
+
}
|
|
159
|
+
await askPolish(root, r.slug, input.title, unit, 'release')
|
|
160
|
+
return { ...r, created: true }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** the release being filled as Communications shows it: next.md, and the draft a release would stage from it */
|
|
164
|
+
export type NextRelease = {
|
|
165
|
+
release: Release
|
|
166
|
+
/** `root@next`: the root unit, the only one with release files */
|
|
167
|
+
ref: string
|
|
168
|
+
headings: readonly ReleaseHeading[]
|
|
169
|
+
/** the draft as `stageRelease` writes it, loaded from a scratch folder; null when the unit declares no headings */
|
|
170
|
+
draft: Draft | null
|
|
171
|
+
/** its draft.md; empty when the unit declares no headings */
|
|
172
|
+
text: string
|
|
173
|
+
/** the guard's and the load's lines about it */
|
|
174
|
+
errors: string[]
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** next.md as the release that cuts it would stage it, `version` still `next`: the same input as `stageRelease`, loaded
|
|
178
|
+
* by `stageDry` from a scratch folder, so nothing in the repo is written. Null without next.md; a next.md that does
|
|
179
|
+
* not parse throws */
|
|
180
|
+
export async function previewNextRelease(root: string, unit: SocialUnit | null, o: StageCtx & { now?: Date } = {}): Promise<NextRelease | null> {
|
|
181
|
+
const release = hasReleases(root) ? readRelease(root, NEXT) : null
|
|
182
|
+
if (release == null) return null
|
|
183
|
+
const headings = unit?.release?.headings ?? []
|
|
184
|
+
const ask: ReleaseAsk = { unit: 'root', version: NEXT, notes: '', ...(o.now ? { now: o.now } : {}) }
|
|
185
|
+
const ref = `${ask.unit}@${ask.version}`
|
|
186
|
+
if (headings.length === 0) return { release, ref, headings, draft: null, text: '', errors: [] }
|
|
187
|
+
// a picture the disk and the Space cannot give (offline) leaves the preview its words, and says why
|
|
188
|
+
const fetched = await releaseInput(root, ask, release, headings, o).then(
|
|
189
|
+
(input) => ({ input, why: null }),
|
|
190
|
+
async (e: unknown) => ({ input: await releaseInput(root, ask, null, headings, o).then((i) => ({ ...i, text: changesOf(release).map((c) => `- ${c.title}`).join('\n') || i.text })), why: `its pictures: ${(e as Error).message}` }),
|
|
191
|
+
)
|
|
192
|
+
const { input } = fetched
|
|
193
|
+
const r = await stageDry(root, input, ctxOf(unit, o))
|
|
194
|
+
// `next` is no version yet: the load's line on the ref is the one a cut release never meets
|
|
195
|
+
const errors = [...r.errors.filter((e) => !e.includes(`release "${ref}"`)), ...(fetched.why ? [fetched.why] : [])]
|
|
196
|
+
return { release, ref, headings, draft: r.draft, text: draftText(input, input.media ? mediaFile(input.media) : null), errors }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** the commits of a range, full shas; the range `a..b`, or a tag alone (every commit up to it) */
|
|
200
|
+
function commitsOf(root: string, range: string): Set<string> {
|
|
201
|
+
const r = Bun.spawnSync([gitBin(), 'rev-list', range], { cwd: root, stdout: 'pipe', stderr: 'pipe' })
|
|
202
|
+
if (r.exitCode !== 0) throw new Error(`git rev-list ${range}: ${r.stderr.toString().trim()}`)
|
|
203
|
+
return new Set(r.stdout.toString().split('\n').filter((l) => l !== ''))
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** the cards a release file names for `<unit>@<version>`, or null when the repo keeps no such file (only the root unit
|
|
207
|
+
* has release files: wiki tools/shipkit/units.md) */
|
|
208
|
+
function releasedCards(root: string, ref: string | undefined): Set<string> | null {
|
|
209
|
+
const r = releaseFileOf(root, ref)
|
|
210
|
+
return r == null ? null : new Set(changesOf(r).flatMap((c) => (c.card ? [c.card] : [])))
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** the release file of `<unit>@<version>`: the root unit's, named `root` or as the repo's folder; null without one */
|
|
214
|
+
export function releaseFileOf(root: string, ref: string | undefined): Release | null {
|
|
215
|
+
const m = ref ? /^([^@]+)@(\d+\.\d+\.\d+)$/.exec(ref) : null
|
|
216
|
+
if (!m || (m[1] !== 'root' && m[1] !== basename(root)) || !hasReleases(root)) return null
|
|
217
|
+
return readRelease(root, m[2]!)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** the approved cards a release ships, newest first: a card its release file names, else one whose commit is in its
|
|
221
|
+
* range; its head's media */
|
|
222
|
+
export function releaseCards(root: string, slug: string): { range: string; cards: { id: string; title: string; media: Stageable[] }[] } {
|
|
223
|
+
const f = join(draftsDir(root), slug, 'draft.md')
|
|
224
|
+
if (!DRAFT_NAME.test(slug) || !existsSync(f)) throw new Error(`no draft ${slug}`)
|
|
225
|
+
const meta = head(readFileSync(f, 'utf8'))
|
|
226
|
+
const range = meta.range ?? ''
|
|
227
|
+
// the release's own file names its cards, one per change: its words and its media are one source
|
|
228
|
+
const listed = releasedCards(root, meta.release)
|
|
229
|
+
if (range === '' && listed == null) return { range, cards: [] }
|
|
230
|
+
const shas = listed == null ? [...commitsOf(root, range)] : []
|
|
231
|
+
const inRange = (c: string | undefined): boolean => c != null && c.length >= 7 && shas.some((s) => s.startsWith(c))
|
|
232
|
+
const items: ReviewItem[] = existsSync(storeDir(root)) ? readAll(storeDir(root)).items : []
|
|
233
|
+
const ships = (t: Thread): boolean => (listed == null ? inRange(t.head.item.commit) : t.versions.some((v) => listed.has(v.item.id)))
|
|
234
|
+
const cards = threadsOf(items)
|
|
235
|
+
.filter(ships)
|
|
236
|
+
.map((t) => t.head)
|
|
237
|
+
.filter((x) => x.item.origin.by === 'agent' && isApproved(verdictOf(x)?.status ?? 'rejected'))
|
|
238
|
+
.sort((a, b) => b.item.created.localeCompare(a.item.created))
|
|
239
|
+
.map((x) => ({ id: x.item.id, title: x.item.title, media: stageablesOf(x.item, 1) }))
|
|
240
|
+
return { range, cards }
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** a release draft with his picked media: the file copied clean into its media/, its `media`, `alt` and `rating` set,
|
|
244
|
+
* `## short` given his text; a dry run loads that on a scratch copy and writes nothing */
|
|
245
|
+
export async function releaseMedia(
|
|
246
|
+
root: string,
|
|
247
|
+
slug: string,
|
|
248
|
+
ask: { card: string; pick: string; rating: PostRating; alt?: string; text?: string; dry?: boolean },
|
|
249
|
+
o: { unit?: SocialUnit | null; speaksAs?: string; font?: string } = {},
|
|
250
|
+
): Promise<Staged> {
|
|
251
|
+
if (!isPostRating(ask.rating)) throw new Error('rating: safe, mild or explicit')
|
|
252
|
+
const f = join(draftsDir(root), slug, 'draft.md')
|
|
253
|
+
const { cards } = releaseCards(root, slug)
|
|
254
|
+
const card = cards.find((c) => c.id === ask.card)
|
|
255
|
+
const m = card?.media.find((x) => x.key === ask.pick)
|
|
256
|
+
if (card == null || m == null) throw new Error(`${ask.pick} is no media of a card this release ships`)
|
|
257
|
+
const file = await stageFileOf(storeDir(root), m, o.font)
|
|
258
|
+
const name = mediaFile({ file, name: `release-${m.label.split(' ')[0]!.replace('.', '').toLowerCase()}-${card.id.slice(16, 40)}`, vertical: m.kind === 'clip' && m.ratio < 0.6 })
|
|
259
|
+
let raw = readFileSync(f, 'utf8')
|
|
260
|
+
raw = setMeta(setMeta(raw, 'media', name), 'rating', ask.rating)
|
|
261
|
+
if (ask.alt !== undefined) raw = setMeta(raw, 'alt', ask.alt.replace(/\s*\n\s*/g, ' ').trim())
|
|
262
|
+
if (ask.text?.trim()) raw = setHeadingText(raw, 'short', ask.text)
|
|
263
|
+
const c = { ...(o.unit !== undefined ? { unit: o.unit } : {}), ...(o.speaksAs !== undefined ? { speaksAs: o.speaksAs } : {}) }
|
|
264
|
+
const problems = guardWith(o.unit, { alt: ask.alt ?? '', texts: ask.text ? [ask.text] : [], files: [file] })
|
|
265
|
+
if (problems.length > 0 && !ask.dry) throw new Error(`the repo's guard refuses it: ${problems.join('; ')}`)
|
|
266
|
+
if (ask.dry) {
|
|
267
|
+
// the media the draft holds already (a heading's own picture) beside the one picked
|
|
268
|
+
const dir = join(draftsDir(root), slug)
|
|
269
|
+
const had = existsSync(join(dir, 'media')) ? readdirSync(join(dir, 'media')).map((n) => ({ name: `media/${n}`, file: join(dir, 'media', n) })) : []
|
|
270
|
+
return dryLoad(root, slug, raw, [...had.filter((x) => x.name !== name), { name, file }], c)
|
|
271
|
+
}
|
|
272
|
+
mkdirSync(dirname(join(draftsDir(root), slug, name)), { recursive: true })
|
|
273
|
+
stripCopy(file, join(draftsDir(root), slug, name))
|
|
274
|
+
writeFileSync(f, raw)
|
|
275
|
+
commitPaths([f, join(draftsDir(root), slug, name)], `social: ${slug} takes the media of the card ${card.id}`)
|
|
276
|
+
return { slug, files: [f], draft: null, errors: [] }
|
|
277
|
+
}
|
package/src/social/routes.ts
CHANGED
|
@@ -6,17 +6,21 @@ import { existsSync } from 'node:fs'
|
|
|
6
6
|
import { homedir } from 'node:os'
|
|
7
7
|
import { isAbsolute, join, relative, resolve } from 'node:path'
|
|
8
8
|
import { bad, FRESH, NO_STORE, ranged } from '../review/http.ts'
|
|
9
|
-
import {
|
|
9
|
+
import { noteOn, notesBy } from '../review/notes.ts'
|
|
10
|
+
import { answerOf, voiceOf } from '../review/stage-routes.ts'
|
|
11
|
+
import { isPostRating } from '../identities/rating.ts'
|
|
12
|
+
import { noteLines, releaseCards, releaseMedia } from './release-stage.ts'
|
|
10
13
|
import { readAllCached, storeDir } from '../review/store.ts'
|
|
11
14
|
import { DRAFT_NAME, draftsDir, type Desk } from './load.ts'
|
|
12
|
-
import { deskAnswer } from './desk-index.ts'
|
|
15
|
+
import { deskAnswer, nextReleaseAnswer } from './desk-index.ts'
|
|
13
16
|
import { socialMediaBack, socialMediaUrl } from './media-kind.ts'
|
|
14
17
|
import { openDesk } from './open.ts'
|
|
15
18
|
import { openAll } from '../veille/chrome.ts'
|
|
16
19
|
import { noteOpen, searchHistory, settleSeen, trackerView } from './tracker.ts'
|
|
17
20
|
import { publish } from './publish/index.ts'
|
|
18
21
|
import { socialStats } from './stats.ts'
|
|
19
|
-
import { setLive, setPosted, setStep, setText } from './writes.ts'
|
|
22
|
+
import { setLive, setPosted, setShown, setStep, setText } from './writes.ts'
|
|
23
|
+
import { pictureVersion } from '../identities/identities.ts'
|
|
20
24
|
|
|
21
25
|
const KEY = /^[a-z0-9-]+(?:\/[a-z0-9-]+)?$/
|
|
22
26
|
const ID = /^[a-z0-9-]+$/
|
|
@@ -39,6 +43,8 @@ function draftMedia(desk: Desk, slug: string, name: string): string {
|
|
|
39
43
|
throw new Error(`${slug} names no media ${name}`)
|
|
40
44
|
}
|
|
41
45
|
|
|
46
|
+
const IMMUTABLE = { 'Cache-Control': 'public, max-age=31536000, immutable' }
|
|
47
|
+
|
|
42
48
|
/** a picture under an identity's `files` folder, or one its `pictures` list from a folder elsewhere; never another */
|
|
43
49
|
function picture(desk: Desk, identity: string, rel: string): string {
|
|
44
50
|
const i = desk.identities.find((x) => x.id === identity)
|
|
@@ -59,6 +65,7 @@ export async function socialRoutes(root: string, req: Request, path: string): Pr
|
|
|
59
65
|
try {
|
|
60
66
|
if (req.method === 'GET') {
|
|
61
67
|
if (sub === 'desk.json') return deskAnswer(req, root)
|
|
68
|
+
if (sub === 'next-release.json') return nextReleaseAnswer(req, root)
|
|
62
69
|
if (sub === 'stats.json') {
|
|
63
70
|
const { desk } = await openDesk(root)
|
|
64
71
|
const out: Record<string, Record<string, string>> = {}
|
|
@@ -71,15 +78,23 @@ export async function socialRoutes(root: string, req: Request, path: string): Pr
|
|
|
71
78
|
for (const i of desk.identities) out[i.id] = trackerView(i.id)
|
|
72
79
|
return Response.json(out, { headers: NO_STORE })
|
|
73
80
|
}
|
|
74
|
-
if (sub === 'asked') {
|
|
75
|
-
const dir = storeDir(root)
|
|
76
|
-
return Response.json({ asked: askedPosts(readAllCached(dir).items) }, { headers: NO_STORE })
|
|
77
|
-
}
|
|
78
81
|
if (sub === 'notes') {
|
|
79
82
|
const slug = str(new URL(req.url).searchParams.get('slug'), 'draft', DRAFT_NAME)
|
|
80
83
|
const dir = storeDir(root)
|
|
81
84
|
return Response.json({ notes: notesBy(dir, readAllCached(dir).items)({ kind: 'draft', slug }) }, { headers: NO_STORE })
|
|
82
85
|
}
|
|
86
|
+
// a release draft's stage popup: the approved cards it ships as its media strip, its notes as chips
|
|
87
|
+
if (sub === 'release-media') {
|
|
88
|
+
const slug = str(new URL(req.url).searchParams.get('slug'), 'draft', DRAFT_NAME)
|
|
89
|
+
const { desk } = await openDesk(root)
|
|
90
|
+
const d = desk.drafts.find((x) => x.slug === slug)
|
|
91
|
+
if (d?.release == null) return bad(`${slug} is no release draft`, 404)
|
|
92
|
+
const { range, cards } = releaseCards(root, slug)
|
|
93
|
+
const words = noteLines(d.angle).filter((l) => !l.startsWith('Staged from')).map((l) => ({ from: 'card' as const, text: l.replace(/^- /, '') }))
|
|
94
|
+
const voice = await voiceOf(root, { id: slug, title: d.title })
|
|
95
|
+
const media = cards.flatMap((c) => c.media.map((m) => ({ ...m, label: `${m.label.replace(/^1\./, '')} · ${c.title}` })))
|
|
96
|
+
return Response.json({ head: slug, first: slug, title: d.title, media, words, ...voice, rating: d.rating, drafts: [], range }, { headers: NO_STORE })
|
|
97
|
+
}
|
|
83
98
|
const media = /^media\/([^/]+)\/(.+)$/.exec(sub)
|
|
84
99
|
if (media) {
|
|
85
100
|
const { desk } = await openDesk(root)
|
|
@@ -91,7 +106,10 @@ export async function socialRoutes(root: string, req: Request, path: string): Pr
|
|
|
91
106
|
const pic = /^picture\/([a-z0-9-]+)\/(.+)$/.exec(sub)
|
|
92
107
|
if (pic) {
|
|
93
108
|
const { desk } = await openDesk(root)
|
|
94
|
-
|
|
109
|
+
const abs = picture(desk, pic[1]!, decodeURIComponent(pic[2]!))
|
|
110
|
+
// a url naming the file's version as it is now keeps for good; an old version or none is asked again
|
|
111
|
+
const v = new URL(req.url).searchParams.get('v')
|
|
112
|
+
return ranged(req, abs, v != null && v !== '' && v === pictureVersion(abs) ? IMMUTABLE : FRESH)
|
|
95
113
|
}
|
|
96
114
|
const prev = /^preview\/([^/]+)$/.exec(sub)
|
|
97
115
|
if (prev) {
|
|
@@ -117,6 +135,20 @@ export async function socialRoutes(root: string, req: Request, path: string): Pr
|
|
|
117
135
|
const text = String(b.text ?? '')
|
|
118
136
|
return Response.json(await noteOn(storeDir(root), { subject: { kind: 'draft', slug }, origin: { by: 'owner', from: 'communications' }, topic: unit?.notes ?? 'social', name: String(b.title ?? '') || slug, text }))
|
|
119
137
|
}
|
|
138
|
+
if (sub === 'release-media') {
|
|
139
|
+
const { desk, unit } = await openDesk(root)
|
|
140
|
+
const slug = str(b.slug, 'draft', DRAFT_NAME)
|
|
141
|
+
const pick = str(b.pick, 'media')
|
|
142
|
+
const rating = str(b.rating, 'rating')
|
|
143
|
+
if (!isPostRating(rating)) throw new Error('rating: safe, mild or explicit')
|
|
144
|
+
const r = await releaseMedia(
|
|
145
|
+
root,
|
|
146
|
+
slug,
|
|
147
|
+
{ card: pick.split('#')[0]!, pick, rating, ...(typeof b.alt === 'string' ? { alt: b.alt } : {}), ...(typeof b.text === 'string' ? { text: b.text } : {}), dry: b.dry === true },
|
|
148
|
+
{ unit, ...(desk.speaksAs ? { speaksAs: desk.speaksAs } : {}) },
|
|
149
|
+
)
|
|
150
|
+
return Response.json(answerOf(r), { headers: NO_STORE })
|
|
151
|
+
}
|
|
120
152
|
if (sub === 'reveal') {
|
|
121
153
|
const { desk } = await openDesk(root)
|
|
122
154
|
// an identity's picture, or a draft's media (brought back from the Space when the disk let it go)
|
|
@@ -129,6 +161,8 @@ export async function socialRoutes(root: string, req: Request, path: string): Pr
|
|
|
129
161
|
const { desk } = await openDesk(root)
|
|
130
162
|
if (sub === 'posted') return Response.json({ files: setPosted(desk, str(b.slug, 'draft', DRAFT_NAME), str(b.key, 'message', KEY), urlOrNull(b.url)) })
|
|
131
163
|
if (sub === 'live') return Response.json({ files: setLive(desk, str(b.identity, 'identity', ID), str(b.account, 'account', ID), urlOrNull(b.url)) })
|
|
164
|
+
if (sub === 'shown')
|
|
165
|
+
return Response.json({ files: setShown(desk, str(b.identity, 'identity', ID), str(b.account, 'account', ID), str(b.row, 'row'), typeof b.file === 'string' ? b.file : undefined, typeof b.sha === 'string' ? b.sha : undefined) })
|
|
132
166
|
if (sub === 'step') {
|
|
133
167
|
const index = Number(b.index)
|
|
134
168
|
if (!Number.isInteger(index) || index < 0) throw new Error(`step ${String(b.index)}?`)
|
|
@@ -165,6 +199,8 @@ export async function socialRoutes(root: string, req: Request, path: string): Pr
|
|
|
165
199
|
const d = desk.drafts.find((x) => x.slug === slug)
|
|
166
200
|
const posts = d?.posts.filter((p) => p.from === from) ?? []
|
|
167
201
|
if (d == null || posts.length === 0) return bad(`no message ${from} in ${slug}`, 404)
|
|
202
|
+
const refused = posts.find((p) => p.refused !== '')
|
|
203
|
+
if (refused != null) return bad(`${slug} may not go out: ${refused.refused}`)
|
|
168
204
|
const accounts = desk.identities.find((i) => i.id === d.identity)?.accounts ?? []
|
|
169
205
|
// a live account posts with « Publish », a posted one is done: neither needs a window
|
|
170
206
|
const open = posts.flatMap((p) => {
|