· 2 min read

A cover picker, only in dev

/covergen, a page that only exists in pnpm dev. It shows every post's drafts as the site will show them: in any theme, with the glow, the masks, and the real…

What we did

  • /covergen, a page that only exists in pnpm dev. It shows every post's drafts as the site will show them: in any theme, with the glow, the masks, and the real card in colour and grey, next to the current cover.
  • From the page I can use a draft (with its alt text), reject it, add the post to the retry list, edit the titles and scene, and make drafts for one or more posts. I can choose how many, the seeds and the steps.
  • It's a small Vite plugin, like the CMS, not a SvelteKit route. The page and pnpm covers share scripts/covers/library.ts, and drafts are made by running the same command.
  • The commands got better too: several posts at once, --from next, --steps and --free. Ctrl+C also cancels the image in SwarmUI. A lock stops the page and a terminal from making drafts at the same time.

What I learned

  • A page on localhost isn't private by itself: other sites open in the same browser can send it requests. Checking Origin stops them from changing anything, and checking Host stops a site that points its own name at my computer.
  • spawn() without a shell passes each value as it is, so a value can't become a second command.
  • A lock file with a process id can tell a running job from one that crashed: process.kill(pid, 0) only checks that it exists.
  • When two files only work together, make and check both before writing either one.

Problems & fixes

  • Saving one scene with the YAML library wrapped every long line in covers.yaml again. Now only that scene's lines are replaced, then the file is read again to check that nothing else changed.
  • A preview took 6 seconds, mostly to make the AVIF. Previews now use WebP and take 1.2 seconds. The final covers are still exactly the same.
  • There wasn't enough memory for a real draft (34 GB in use, and Krea needs about 22 GB more), so the script refused to start. I tested making and stopping drafts with a small stand-in for SwarmUI. Real drafts from the page are still untested.

Next

  • Choose covers for the posts.