mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 05:37:19 +01:00
Private tiles on bitbaum.orangecat.ch/private/ now render through the same tile as the public work grid (bitbaum PR #136). This adds the picture they show: GET /api/fleet/private/shot/<slug>, owner only, a 1280x800 picture of the project's site (a preview through Loki's own route with the owner's cookie, its widget left out), kept for twelve hours. A site behind its own access-code page is not photographed, so its tile is text, not a code page. takePagePicture takes a viewport; wider than a phone is a desktop browser. The owner check is one helper (studioOwnerCheck) shared by the list and its pictures. A preview can now move: POST /api/previews/<slug>/move { to, name } attaches the new address, renames the folder, moves the project row and its name in one transaction (the folder moves back if that fails), points the widget at the new address and detaches the old one. Center SOM was born center-com-3 from a domain spelled in look-alike Latin letters; this is how it becomes tsentr-som. previews.yml gains `move` and `ask` (send the builder a change). A website preview's one line names the site by host ("center-com.ru"), not by its URL. Claude-Session: https://claude.ai/code/session_01Y9KbVEpxKLC9nhKhpWncU1 Co-authored-by: Claude <noreply@anthropic.com>
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { isAccessGate, tileShotPlan, TILE_VIEWPORT } from "../../src/lib/register/private-shot";
|
|
|
|
const app = "https://loki.example";
|
|
|
|
// A preview is photographed through Loki's own route, with the owner's cookie,
|
|
// and told it is being photographed (so its widget stays out of the picture).
|
|
const preview = tileShotPlan({
|
|
slug: "tsentr-som",
|
|
live: "https://tsentr-som.orangecat.ch",
|
|
appOrigin: app,
|
|
previewCookie: "123.sig",
|
|
});
|
|
assert.equal(preview.target, `${app}/p/tsentr-som/`);
|
|
assert.deepEqual(preview.opts.viewport, TILE_VIEWPORT, "the public tiles' size");
|
|
assert.equal(preview.opts.cookies?.[0].value, "123.sig");
|
|
assert.equal(preview.opts.cookies?.[0].url, app);
|
|
assert.equal(preview.opts.headers?.["x-loki-picture"], "1");
|
|
|
|
// Any other site: its own address, as a visitor sees it, with nothing of ours.
|
|
const site = tileShotPlan({
|
|
slug: "aoz",
|
|
live: "https://aoz.example",
|
|
appOrigin: app,
|
|
previewCookie: null,
|
|
});
|
|
assert.equal(site.target, "https://aoz.example");
|
|
assert.equal(
|
|
site.opts.cookies,
|
|
undefined,
|
|
"no cookie of Loki's is ever sent to someone else's site",
|
|
);
|
|
assert.equal(site.opts.headers, undefined);
|
|
|
|
// The picture is named by what is photographed: a moved project is a new picture.
|
|
const moved = tileShotPlan({
|
|
slug: "aoz",
|
|
live: "https://aoz.example/new",
|
|
appOrigin: app,
|
|
previewCookie: null,
|
|
});
|
|
assert.notEqual(site.key, moved.key);
|
|
assert.match(site.key, /^aoz-[0-9a-f]{12}$/);
|
|
|
|
assert.equal(isAccessGate(new Headers({ "x-access-gate": "1" })), true);
|
|
assert.equal(isAccessGate(new Headers()), false);
|
|
console.log("private-shot: ok");
|