~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

A group's site is published and deleted from its settings, and linked

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:console/site
docs/design/sites.md+14−7
@@ -3,9 +3,10 @@
A group can have a website: a front page that says who it is, or as many
pages as it likes. The host serves it at the group's address,
`https://<address>/`, as static files, the way they were published. It has
no templates, no build step and no rendering on the server. A page that
wants live data, such as the group's events or members, asks the host's
public methods from the browser.
no templates, no build step and no rendering on the server. A page is
what was published: it cannot read the host's methods, as nobody is
signed in in its sandbox, and the methods don't let another origin read
their answers.
## What a site is
@@ -41,10 +42,16 @@ hash of its bytes, so a file that has not changed is the same blob. It
answers how many files were new. `fyi.opensocial.deleteSite` takes the
site down.
Both require `group.configure`. The `opensocial site publish` command
reads a folder and sends its files, leaving out those whose names start
with a dot; `site delete` takes the site down. An AI app connected over
MCP publishes with `site_publish`, writing each file as text.
Both require `group.configure`. In the console, a group's own page links
to its site while it has one, and its settings have a Site page, which
says where the site is, how many files it has and when it was published,
and publishes a folder chosen in the browser, or deletes the site, asked to be
sure of. The `opensocial site publish` command reads a folder and sends
its files; `site delete` takes the site down. Both leave out files whose
names start with a dot, send each file as text if it is UTF-8 and as
bytes otherwise, and take the folder's own name off each path. An AI app
connected over MCP publishes with `site_publish`, writing each file as
text.
An app signed in as the group may also write the record itself, with
`com.atproto.repo.putRecord`, after uploading the blobs. The host holds
docs/guides/shots/apps-activity-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-activity.png+0−0
A binary file, not shown.
docs/guides/shots/apps-dialog-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-dialog.png+0−0
A binary file, not shown.
docs/guides/shots/apps-empty-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-empty.png+0−0
A binary file, not shown.
docs/guides/shots/apps-empty.txt+1−0
@@ -6,6 +6,7 @@
- heading "Settings" [level=1]
- navigation "Settings":
- link "Profile":
- link "Site":
- link "Rules":
- link "Labels":
- link "Roles":
docs/guides/shots/apps-made-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-made.png+0−0
A binary file, not shown.
docs/guides/shots/apps-revoke-access-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-revoke-password-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-revoke-password.png+0−0
A binary file, not shown.
docs/guides/shots/apps-signed-in-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-signed-in.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-escalate-sent-dark.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-escalate-sent.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-label-dialog-dark.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-label-dialog.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-queue-dark.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-queue.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-remove-dialog-dark.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-remove-dialog.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-removed-dark.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-removed.png+0−0
A binary file, not shown.
docs/guides/shots/recovery-added-dark.png+0−0
A binary file, not shown.
docs/guides/shots/recovery-added.png+0−0
A binary file, not shown.
docs/guides/shots/recovery-dialog-dark.png+0−0
A binary file, not shown.
docs/guides/shots/recovery-dialog.png+0−0
A binary file, not shown.
docs/guides/shots/recovery-refused-dark.png+0−0
A binary file, not shown.
docs/guides/shots/recovery-refused.png+0−0
A binary file, not shown.
docs/guides/shots/recovery-removed-dark.png+0−0
A binary file, not shown.
docs/guides/shots/recovery-removed.png+0−0
A binary file, not shown.
docs/guides/shots/recovery-tab-dark.png+0−0
A binary file, not shown.
docs/guides/shots/recovery-tab.png+0−0
A binary file, not shown.
docs/guides/shots/recovery-tab.txt+1−0
@@ -6,6 +6,7 @@
- heading "Settings" [level=1]
- navigation "Settings":
- link "Profile":
- link "Site":
- link "Rules":
- link "Labels":
- link "Roles":
docs/guides/shots/rules-add-dark.png+0−0
A binary file, not shown.
docs/guides/shots/rules-create-role.png+0−0
A binary file, not shown.
docs/guides/shots/rules-delete-dark.png+0−0
A binary file, not shown.
docs/guides/shots/rules-give-dark.png+0−0
A binary file, not shown.
docs/guides/shots/rules-give.png+0−0
A binary file, not shown.
docs/guides/shots/rules-given-dark.png+0−0
A binary file, not shown.
docs/guides/shots/rules-given.png+0−0
A binary file, not shown.
docs/guides/shots/rules-menu-dark.png+0−0
A binary file, not shown.
docs/guides/shots/rules-menu.png+0−0
A binary file, not shown.
docs/guides/shots/starting-avatar-dark.png+0−0
A binary file, not shown.
docs/guides/shots/starting-words.txt+1−0
@@ -6,6 +6,7 @@
- heading "Settings" [level=1]
- navigation "Settings":
- link "Profile":
- link "Site":
- link "Rules":
- link "Labels":
- link "Roles":
harness/e2e/flows.spec.mjs+60−0
@@ -2,6 +2,9 @@
// PDS, see her groups, sign an app in as one of them, and decline one;
// and what the app then does as the group, read back from the host.
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { expect, test } from '@playwright/test';
import {
App,
@@ -540,6 +543,63 @@ test('giving a group a picture, and taking it away', async () => {
await expect(page.locator('.identity img.av')).toHaveCount(0);
});
test('publishing a site from a folder, and deleting it', async () => {
// A folder as people keep a site: a front page, a page under it, a
// picture, and a file of their tools', which is left out.
const dir = mkdtempSync(join(tmpdir(), 'e2e-site-'));
mkdirSync(join(dir, 'rides'));
writeFileSync(join(dir, 'index.html'), '<h1>Hikers</h1>');
writeFileSync(join(dir, 'rides/index.html'), '<h1>Walks</h1>');
writeFileSync(join(dir, 'face.png'), PIXEL);
writeFileSync(join(dir, '.DS_Store'), 'tools');
await page.goto(url('/g/hikers.groups.test/settings'));
await page
.getByRole('navigation', { name: 'Settings' })
.getByRole('link', { name: 'Site' })
.click();
await expect(page.getByText('Nothing published yet')).toBeVisible();
await page.getByRole('button', { name: 'Publish a site' }).click();
const publishing = page.getByRole('dialog', { name: 'Publish a site' });
await publishing.getByLabel('Folder').setInputFiles(dir);
await publishing.getByRole('button', { name: 'Publish' }).click();
await expect(publishing).toBeHidden();
await expect(page.getByText(/^3 files, published /)).toBeVisible();
// Kept as the group's, each file at its path under the folder, typed by
// its extension: a page sent as text, the picture as its bytes, whole.
const { did } = await fetch(
`${world.host}/xrpc/com.atproto.identity.resolveHandle?handle=hikers.groups.test`
).then((r) => r.json());
const { value } = await fetch(
`${world.host}/xrpc/com.atproto.repo.getRecord?repo=${did}&collection=fyi.opensocial.site&rkey=self`
).then((r) => r.json());
const files = Object.fromEntries(
value.files.map((f) => [f.path, [f.blob.mimeType, f.blob.size]])
);
expect(files).toEqual({
'index.html': ['text/html', 15],
'rides/index.html': ['text/html', 14],
'face.png': ['image/png', PIXEL.length]
});
// Its page links to it, at its address.
await page.goto(url('/g/hikers.groups.test'));
const website = page
.getByRole('navigation', { name: 'The group' })
.getByRole('link', { name: 'Website' });
await expect(website).toHaveAttribute('href', 'https://hikers.groups.test/');
await page.goto(url('/g/hikers.groups.test/settings/site'));
await page.getByRole('button', { name: 'Delete the site' }).click();
await page
.getByRole('dialog', { name: 'Delete this site?' })
.getByRole('button', { name: 'Delete' })
.click();
await expect(page.getByText('Nothing published yet')).toBeVisible();
await page.goto(url('/g/hikers.groups.test'));
await expect(page.getByRole('link', { name: 'Website' })).toHaveCount(0);
});
test("hiding a group's profile, and showing it again", async () => {
// Found on the network while its declaration is in its public repo,
// which anyone may read.
harness/look/seeds/site.mjsnew+15−0
@@ -0,0 +1,15 @@
// Riders with a website published: a front page, a page under it, and a
// style sheet.
import { mkdtempSync, mkdirSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
export default async ({ opensocial }) => {
const dir = mkdtempSync(join(tmpdir(), 'look-site-'));
mkdirSync(join(dir, 'rides'));
writeFileSync(join(dir, 'index.html'), '<h1>Riders</h1><p>Saturday rides.</p>');
writeFileSync(join(dir, 'rides/index.html'), '<h1>Rides</h1>');
writeFileSync(join(dir, 'style.css'), 'h1 { color: teal }');
opensocial('alice', 'site', 'publish', 'riders.groups.test', dir);
};
web/src/lib/organisms/GroupSite.sveltenew+77−0
@@ -0,0 +1,77 @@
<script lang="ts">
import Address from '#lib/atoms/Address.svelte';
import ConfirmDialog from '#lib/molecules/ConfirmDialog.svelte';
import Empty from '#lib/molecules/Empty.svelte';
import FormDialog from '#lib/molecules/FormDialog.svelte';
import { day } from '#lib/dates.ts';
/**
* A group's website: where it is served, how many files it has and
* when it was published, to open or delete (asked to be sure of); and
* the dialog publishing a folder in place of it, opened by a button
* whose `popovertarget` is `publish-site`. `address`, the name it is
* served at.
*/
let {
address,
site
}: { address: string; site: { url: string; files: number; publishedAt: string } | null } =
$props();
// Each file's path under the folder chosen, as the browser gives them,
// in the files' order: a form sends each file by its name alone.
let paths = $state('[]');
</script>
{#if site}
<ul class="sites">
<li>
<span class="row-main">
<strong class="mono"><Address {address} /></strong>
<span class="what"
>{site.files === 1 ? '1 file' : `${site.files} files`}, published {day(
site.publishedAt
)}</span
>
</span>
<span class="row-actions"
><a class="button quiet small" href={site.url} aria-label="Open the site">Open</a><button
class="quiet small"
type="button"
popovertarget="delete-site"
aria-label="Delete the site">Delete</button
></span
>
<ConfirmDialog id="delete-site" title="Delete this site?" action="?/unsite" confirm="Delete">
Its pages at <span class="mono">{address}</span> go offline. Anyone who opens that address sees
the group's page here instead.
</ConfirmDialog>
</li>
</ul>
{:else}
<Empty title="Nothing published yet">Publish a folder of web pages to put them online.</Empty>
{/if}
<FormDialog id="publish-site" title="Publish a site" action="?/site" submit="Publish" multipart>
{#snippet intro()}{`Choose the folder with your site's pages. Put the front page at the top, named index.html.${site ? " This replaces the site that's there now." : ''}`}{/snippet}
<label class="field"
>Folder
<input
name="files"
type="file"
multiple
webkitdirectory
required
onchange={(e) =>
(paths = JSON.stringify(
[...(e.currentTarget.files ?? [])].map((f) => f.webkitRelativePath || f.name)
))}
/></label
>
<input type="hidden" name="paths" value={paths} />
<label class="field"
>Page for addresses that aren't found, if you like
<input name="notFound" maxlength="512" placeholder="404.html" /></label
>
<label class="field"
>One page for every address, if you like
<input name="fallback" maxlength="512" placeholder="index.html, for an app" /></label
>
</FormDialog>
web/src/lib/server/settings.ts+50−0
@@ -476,6 +476,20 @@ const all = {
label: text(form, 'label')
});
},
site: async (event) => {
const { group, form } = await asked(event);
const files = await siteFiles(form);
if (!files.length)
return fail(400, { failed: 'Choose a folder with the pages of your site in it.' });
const named = Object.fromEntries(
['fallback', 'notFound'].filter((k) => text(form, k)).map((k) => [k, text(form, k)])
);
return act(event, 'fyi.opensocial.putSite', { group, files, ...named });
},
unsite: async (event) => {
const { group } = await asked(event);
return act(event, 'fyi.opensocial.deleteSite', { group });
},
delete: async (event) => {
const { group } = await asked(event);
// Gone, there is no page of it to come back to.
@@ -483,6 +497,41 @@ const all = {
}
} satisfies Record<string, Action<{ handle: string }>>;
/** A file's bytes as text, where they are UTF-8: kept as they are, a byte-order mark included. */
const UTF8 = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
/**
* The files of a folder chosen to publish, as `putSite` takes them, each
* at its path under the folder (`paths`, as the browser gives them, in
* the files' order, or else each file's name); those whose names start
* with a dot left out, as the command leaves them. Each as text if it is
* UTF-8, else as bytes.
*/
async function siteFiles(form: FormData) {
const paths: unknown = JSON.parse(text(form, 'paths') || '[]');
const given = form.getAll('files').filter((f): f is File => f instanceof File && f.name !== '');
const named = given.map((file, i) => ({
file,
path: (Array.isArray(paths) && typeof paths[i] === 'string' && paths[i]) || file.name
}));
// The folder's own name is no part of the site's paths.
const top = named[0]?.path.split('/')[0] ?? '';
const under = named.every((n) => n.path.startsWith(`${top}/`));
const files = [];
for (const { file, path: whole } of named) {
const path = under ? whole.slice(top.length + 1) : whole;
if (path.split('/').some((s) => s.startsWith('.'))) continue;
const bytes = new Uint8Array(await file.arrayBuffer());
try {
files.push({ path, text: UTF8.decode(bytes) });
} catch {
const $bytes = Buffer.from(bytes).toString('base64').replace(/=+$/, '');
files.push({ path, bytes: { $bytes } });
}
}
return files;
}
/** The writes named, as a page's actions. */
const pick = <K extends keyof typeof all>(...names: K[]) =>
Object.fromEntries(names.map((n) => [n, all[n]])) as Pick<typeof all, K>;
@@ -504,3 +553,4 @@ export const labelActions = pick('define', 'undefine');
export const roleActions = pick('role', 'unrole');
export const appActions = pick('revoke', 'password', 'unpassword');
export const recoveryActions = pick('key', 'unkey');
export const siteActions = pick('site', 'unsite');
web/src/lib/server/site.tsnew+32−0
@@ -0,0 +1,32 @@
// A group's website, as its public repo holds it: what the group's page
// links to, and what its settings publish and delete.
import { error } from '@sveltejs/kit';
/** The record of a group's site, at `self` in its public repo. */
const SITE = 'fyi.opensocial.site';
/** A site as the pages show it: where it is, how many files it has, and when it was published. */
export type Site = { url: string; files: number; publishedAt: string };
type Load = { fetch: typeof fetch; url: URL };
/**
* The group's site, or null while it has none: served at `address`, over
* https wherever the console is. Anyone may read it, as the record is
* public.
*/
export async function siteOf(event: Load, group: string, address: string): Promise<Site | null> {
const query = new URLSearchParams({ repo: group, collection: SITE, rkey: 'self' });
const res = await event.fetch(`/xrpc/com.atproto.repo.getRecord?${query}`);
const answer = await res.json().catch(() => null);
if (!res.ok) {
if (answer?.error === 'RecordNotFound') return null;
error(res.status, answer?.message ?? res.statusText);
}
return {
url: `${event.url.protocol}//${address}/`,
files: answer.value.files?.length ?? 0,
publishedAt: answer.value.createdAt
};
}
web/src/routes/g/[handle]/settings/site/+page.server.tsnew+15−0
@@ -0,0 +1,15 @@
import type { PageServerLoad } from './$types';
import { siteActions } from '#lib/server/settings.ts';
import { siteOf } from '#lib/server/site.ts';
/** The group's site, where it is served, to one who configures it. */
export const load: PageServerLoad = async (event) => {
const view = await event.parent();
const address = view.group.address ?? view.group.handle;
return {
address,
site: view.configures ? await siteOf(event, view.group.did, address) : null
};
};
export const actions = siteActions;
web/src/routes/g/[handle]/settings/site/+page.sveltenew+19−0
web/src/routes/g/[handle]/settings/+layout.server.ts+3−3
web/src/routes/g/[handle]/settings/+layout.svelte+1−0
web/src/routes/g/[handle]/+page.server.ts+6−1
web/src/routes/g/[handle]/+page.svelte+6−4