Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/dashboard-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ all. A step that posts a message (verification, honeypot) or updates AutoMod is
named in the preview before you confirm. Each import is written to the audit
log.

## Public pages

Server settings → **Public pages** (Edit access only) gives the pages your members open without the dashboard their
own look: the application form (and the web shop), the ban appeal, the quote page and the two leaderboards. Two
things change and nothing else: the **accent colour** (buttons, links and highlights) and a **background**. The
background is none, a picture you upload (PNG, JPEG or WebP, at most 2 MB; Sylo stores a re-encoded copy without
metadata, at most 1920 pixels wide, and serves it itself), or the server's **invite background** on Discord or
Fluxer: Sylo downloads it once, keeps its own copy, checks it once a day and serves it itself, so a visitor's
browser never talks to Discord or Fluxer. The settings show a live preview of the application form page. The section
is saved with the Settings page's own Save bar, so leaving the page with unsaved changes here asks first, like any other
form. On a phone the page keeps a margin around its panel so the picture shows on every side.

What stays Sylo's: the layout, the type, the components, the light and dark themes, the readability and the small
"Powered by Sylo" link (to sylobot.com) at the bottom of every public page, which cannot be turned off. The page always
sits on a semi-opaque card over a dim overlay (a light veil in the light theme, and an all but opaque panel, so Sylo's
own text stays readable on any picture; fully opaque for visitors who ask for reduced transparency). The accent is held
to 3:1 against the card for fills, borders and focus rings: below that it is not used in that theme (the light or the
dark one), Sylo's own colour stays there, and the settings say so. Where the accent is used as text (links, the active
pill, top ranks) the pages use a text colour made from it: the accent itself when it reaches 4.5:1 on the card and the
page, otherwise the same hue lightened (dark theme) or darkened (light theme) until it does. The text on a button
fill is black or white, whichever reads better, also when hovered. The dashboard and the Sylo app are never restyled.
The event pages take no server look, because they carry no server address on purpose. The file addresses are
`/look/<server>.<hash>.css` and `.webp`; the style sheet is kept by caches for a year (its address is its content),
a picture for a day. The content security policy is unchanged (styles and images from Sylo only).

## Duplicate and templates

The "⋯" menu of a reminder, an embed message, a reaction-role set, a custom
Expand Down
33 changes: 32 additions & 1 deletion docs/mobile-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ in there:
| `login` | Whether sign-in is available (false in open mode) |
| `loginProviders` | The configured logins, for example `["discord", "fluxer"]`; empty when `login` is false |
| `platforms` | The platforms the bot runs on, for example `["discord"]` |
| `features` | What this version's app API supports, so the app can hide what an older Sylo lacks. Today: `app-login`, `live-access`, `changelog`, `collectibles`, `welcome-trigger`, `member-search`, `access-levels`, `health`, `app-connect`, `setup-wizard`, `config-history`, `inbox-search`, `config-import`, `duplicate`, `message-templates` and `message-move`, plus `push` and `push-pigeon` when this instance can send notifications. See the list below |
| `features` | What this version's app API supports, so the app can hide what an older Sylo lacks. Today: `app-login`, `live-access`, `changelog`, `collectibles`, `welcome-trigger`, `member-search`, `access-levels`, `health`, `app-connect`, `setup-wizard`, `config-history`, `inbox-search`, `config-import`, `duplicate`, `message-templates`, `message-move` and `public-page-look`, plus `push` and `push-pigeon` when this instance can send notifications. See the list below |

The feature strings:

Expand All @@ -338,6 +338,7 @@ The feature strings:
- `duplicate`: the `duplicate` routes for reminders, embed messages, reaction-role sets, custom commands and shop items.
- `message-templates`: the built-in message templates and the raw message JSON import and export.
- `message-move`: when the channel of a posted **embed message**, the **Welcome channel** message or a **role panel** changes and is published, the server posts a fresh message in the new channel, stores it and then deletes the old one, so the app must not unpublish first. Other bot posts (verification, honeypot traps, applications and so on) are not covered. A publish that loses a race with another publish of the same embed message answers `409` with the current record.
- `public-page-look`: the server's [look on its public pages](#public-page-look): `GET` and `POST /api/v2/guilds/:id/public-page-look`, the background upload and the invite-background check.
- `app-connect`: [adding the other login](#adding-the-other-login). Only where sign-in is on and both Discord and Fluxer logins are set up.
- `push`, `push-pigeon`: this instance can send notifications to signed-in apps.

Expand Down Expand Up @@ -393,6 +394,36 @@ Actions that post to the platform (test messages, publishing a message or role
menu, locking or unlocking every channel) share a limit of 10 per minute per
server and account, answered with `429` and an `{ "error" }`.

### Public page look

`public-page-look` in `features`. A server may give the pages its members open without the dashboard (the
application form, the ban appeal, the quote and leaderboard pages and the web shop) its own accent colour and a
background. That is all it can change: the layout, the type, the components, the light and dark themes and the
"Powered by Sylo" link at the bottom of every public page stay Sylo's, and the dashboard and the app are never
restyled. The form always sits on a semi-opaque card over a dim overlay (opaque when the visitor asks for reduced
transparency). Every route here needs the **edit** level, the read too (a lower level gets the usual `403`).

| Call | What it does |
| --- | --- |
| `GET /api/v2/guilds/:id/public-page-look` | The choice and what it comes to (below) |
| `POST /api/v2/guilds/:id/public-page-look` | Saves `{ "accent": "#5865f2" or "", "background": "none", "upload" or "discord-splash" }` and answers like the `GET` |
| `POST /api/v2/guilds/:id/public-page-look/image` | Uploads the background: a multipart body with the field `file` (PNG, JPEG or WebP, at most 2 MB, at most 16 megapixels). Sylo stores a new WebP of at most 1920 pixels, so metadata is gone. Answers like the `GET`. It does not change the choice: save `"background": "upload"` after it |
| `POST /api/v2/guilds/:id/public-page-look/image/delete` | Deletes the uploaded picture (a choice of `upload` falls back to `none`) and answers like the `GET` |
| `POST /api/v2/guilds/:id/public-page-look/splash/refresh` | Checks the invite background against the platform now and answers like the `GET`. Without it Sylo checks once a day, when a page that uses it is opened |

The answer has `accent` and `background` (what was saved), `platform`, `upload` (`null` or `{ bytes, url, updatedAt }`),
`splash` (`available`: the server has an invite background on the platform, Discord and Fluxer both have one;
`copied`: `null` or `{ url, checkedAt, updatedAt }`, Sylo's own copy), `limits` and `sylo` (Sylo's accent per theme)
`backgrounds` (the three values the app may send) and `effective`: `accent` (the colour really used for fills and
borders, per theme: `dark` and `light`), `accentText` (the colour used for text, per theme: the accent, or the same hue
lightened or darkened to reach 4.5:1), `contrast` (the ratio of the accent to the card per theme and whether it reaches
the 3:1 Sylo asks for), `fallback` (the themes where it does not and Sylo's own colour is used instead), `note` (the
sentence to show when `fallback` is not empty, else `null`), `backgroundUrl` (the picture of the chosen background,
or `null`) and `css` (the path of the style sheet public pages load, or `null` when the server chose nothing).
A `400` for a colour that is not `#rgb` or `#rrggbb`, for `upload` with no picture or for `discord-splash`
when the server has none; `502` when the invite background could not be downloaded. The urls are paths on the
Sylo server itself (the app prefixes the server address); the pictures are never loaded from the platform's CDN.

---

## Tokens and signed-in devices
Expand Down
1 change: 1 addition & 0 deletions docs/privacy-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ the public-leaderboard vanity slug.
- **Birthdays** — the day and month (and optionally year) a member registers.
- **Giveaways** — the host, the entrants (with whether an entry fee was refunded), the drawn winners, and the currency prizes paid to members.
- **Events** — the host and, for each event, who pressed Join or Maybe. A server can switch on a page for each event that shows its title, time, place, description, image, capacity and how many pressed Join or Maybe, but no names, no host and no ids. For an event in a channel everyone can read, anyone with the link can open the page. For an event in a private channel, only a person who signs in with the Dashboard login (Discord or Fluxer, the platform the event was posted on), is a member of that server and can see that channel can open it: Sylo checks this against the platform's data on every request and keeps only a plain yes or no, in memory, for a few seconds, and shows a signed-in person who may not open the page the same "not found" page as for a wrong address. A visitor who is not signed in sees a plain sign-in page that shows nothing about the event. An event in an age-restricted channel has no page for anyone. These pages are not cached by browsers or search engines, and nothing about the check is stored beyond the ordinary Dashboard login described in section 3 (a first sign-in creates a dashboard account and a session, which you can delete as described in section 7). The address of each event's page is a random code stored with the event. A visitor's browser contacts only Sylo: Sylo fetches the server icon and the event image from Discord's image servers itself and keeps a copy in memory only, for about ten minutes (a sweep removes expired copies every minute) and hands it out only to a visitor who passes the checks, and the pages carry no visit-count script when they are not found or ask for a sign-in.
- **Public page look** — a server's accent colour and background choice for its public member pages, and the background picture: one the server's staff upload (Sylo keeps a re-encoded copy without metadata) and/or a copy of the server's invite background from Discord or Fluxer, which Sylo downloads itself and re-checks against the platform at most once a day (when a page that uses it is opened), downloading it again only when it changed. A visitor's browser loads these from Sylo only. A picture a server removes is deleted at once; copies that browsers or shared caches already hold are kept for up to a day (the style sheet, which holds only a colour and an address, up to a year). Both go when the server's data is deleted.
- **Suggestions** — the text of each suggestion, who wrote it (unless they erase it), the staff member who decided it, and each member's 👍 / 👎 vote.
- **Temporary roles** — which member holds which temporary role, when it ends, the reason, and the staff member who set it.
- **Introductions** — the answers a member gave in the DM questionnaire (up to eight short texts, with @everyone, @here and role mentions removed), the channel and message ids of their card, and when it was made and last changed. The card itself is a public message in the server's introductions channel: it shows the member's avatar, name, answers, the roles they have from the server's role groups, and when they joined.
Expand Down
2 changes: 1 addition & 1 deletion scripts/migrate-sqlite-to-postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const DRY_RUN = process.argv.includes('--dry-run');
const CHUNK = 1000;
// A table with a binary column (the pictures of collectibles, up to about a megabyte each) is copied in small
// chunks, so a chunk never holds hundreds of megabytes. The bytes are copied as they are (a Buffer is a BYTEA).
const CHUNK_OF = { collectible_images: 10 };
const CHUNK_OF = { collectible_images: 10, public_look_images: 10 };

function fail(msg) {
console.error(`\n✖ ${msg}`);
Expand Down
26 changes: 26 additions & 0 deletions src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,32 @@ export const MIGRATIONS = [
if (!has.has('decided_by_user_id'))
database.exec('ALTER TABLE appeals ADD COLUMN decided_by_user_id TEXT;');
},

// The server's own look on the public member pages (src/db/publicLook.js, which bootstraps the same tables
// on Postgres): an accent colour and a background choice per server, and the picture of the background
// (an upload, or a copy of the server's invite splash that Sylo keeps itself). One picture per source.
(database) => {
database.exec(`
CREATE TABLE guild_public_look (
guild_id TEXT PRIMARY KEY,
accent TEXT NOT NULL DEFAULT '',
background TEXT NOT NULL DEFAULT 'none',
updated_at INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE public_look_images (
guild_id TEXT NOT NULL,
source TEXT NOT NULL,
hash TEXT NOT NULL,
mime TEXT NOT NULL,
bytes INTEGER NOT NULL,
data BLOB NOT NULL,
origin TEXT NOT NULL DEFAULT '',
checked_at INTEGER NOT NULL,
created_at INTEGER NOT NULL,
PRIMARY KEY (guild_id, source)
);
`);
},
];

/** Highest schema version this build knows how to run. */
Expand Down
138 changes: 138 additions & 0 deletions src/db/publicLook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// The server's own look on its public member pages, stored in the database.
//
// guild_public_look guild_id, accent ('#rrggbb' or ''), background ('none', 'upload' or 'discord-splash'),
// updated_at
// public_look_images guild_id, source ('upload' or 'splash'), hash (the first 16 hex characters of the SHA-256
// of the stored bytes: it is in the picture's address), mime, bytes, data (BLOB on SQLite,
// BYTEA on Postgres), origin (for a splash: the hash Discord or Fluxer gave it, so a
// daily check can tell whether it changed without downloading it again), checked_at
// (when the splash was last checked), created_at
//
// Like a collectible's picture, what is stored is never what came in: lib/collectibleImage.js decodes it and
// encodes a new WebP of at most BACKGROUND_MAX_SIDE pixels, so metadata and anything that was not a picture are
// gone. There is one picture per source and server, so replacing one deletes the old one in the same statement,
// and the pictures are part of every backup. Both tables hold rows per server and go with the server's data
// (purge.js).
import { prepare, registerPostgresBootstrap } from './driver.js';

/** The background is scaled to fit in a box of this many pixels, at this WebP quality. */
export const BACKGROUND_MAX_SIDE = 1920;
export const BACKGROUND_QUALITY = 78;
/** The two places a background picture comes from. */
export const SOURCES = Object.freeze(['upload', 'splash']);

registerPostgresBootstrap(`
CREATE TABLE IF NOT EXISTS guild_public_look (
guild_id TEXT PRIMARY KEY,
accent TEXT NOT NULL DEFAULT '',
background TEXT NOT NULL DEFAULT 'none',
updated_at BIGINT NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS public_look_images (
guild_id TEXT NOT NULL,
source TEXT NOT NULL,
hash TEXT NOT NULL,
mime TEXT NOT NULL,
bytes INTEGER NOT NULL,
data BYTEA NOT NULL,
origin TEXT NOT NULL DEFAULT '',
checked_at BIGINT NOT NULL,
created_at BIGINT NOT NULL,
PRIMARY KEY (guild_id, source)
);
-- A WebP does not compress any further: do not let Postgres try.
ALTER TABLE public_look_images ALTER COLUMN data SET STORAGE EXTERNAL;
`);

const s = {
getLook: prepare('SELECT accent, background, updated_at FROM guild_public_look WHERE guild_id = ?'),
setLook: prepare(`
INSERT INTO guild_public_look (guild_id, accent, background, updated_at) VALUES (?, ?, ?, ?)
ON CONFLICT (guild_id) DO UPDATE SET
accent = excluded.accent, background = excluded.background, updated_at = excluded.updated_at
`),
meta: prepare(
'SELECT hash, mime, bytes, origin, checked_at, created_at FROM public_look_images WHERE guild_id = ? AND source = ?'
),
put: prepare(`
INSERT INTO public_look_images (guild_id, source, hash, mime, bytes, data, origin, checked_at, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (guild_id, source) DO UPDATE SET
hash = excluded.hash, mime = excluded.mime, bytes = excluded.bytes, data = excluded.data,
origin = excluded.origin, checked_at = excluded.checked_at, created_at = excluded.created_at
`),
touch: prepare('UPDATE public_look_images SET checked_at = ? WHERE guild_id = ? AND source = ?'),
drop: prepare('DELETE FROM public_look_images WHERE guild_id = ? AND source = ?'),
byHash: prepare('SELECT mime, bytes, data FROM public_look_images WHERE guild_id = ? AND hash = ?'),
};

/**
* What a server chose. Never null: a server that chose nothing has no accent and no background.
* @returns {Promise<{ accent: string, background: string, updatedAt: number }>}
*/
export async function getPublicLook(guildId) {
const row = await s.getLook.get(guildId);
return row
? {
// only a colour this code wrote (normaliseAccent): anything else in the row (a restored backup) is none
accent: /^#[0-9a-f]{6}$/.test(row.accent) ? row.accent : '',
background: row.background,
updatedAt: Number(row.updated_at),
}
: { accent: '', background: 'none', updatedAt: 0 };
}

/** Save the choice (already checked by the caller). */
export async function setPublicLook(guildId, { accent, background }, now = Date.now()) {
await s.setLook.run(guildId, accent, background, now);
}

/**
* The facts about a stored picture, without its bytes, or null.
* @param {string} guildId
* @param {'upload' | 'splash'} source
* @returns {Promise<{ hash: string, mime: string, bytes: number, origin: string, checkedAt: number, createdAt: number } | null>}
*/
export async function getLookImageMeta(guildId, source) {
const row = await s.meta.get(guildId, source);
return row
? {
hash: row.hash,
mime: row.mime,
bytes: Number(row.bytes),
origin: row.origin,
checkedAt: Number(row.checked_at),
createdAt: Number(row.created_at),
}
: null;
}

/**
* Store a picture for a source, replacing (and so deleting) the one it had.
* @param {string} guildId
* @param {'upload' | 'splash'} source
* @param {{ hash: string, mime: string, data: Buffer, origin?: string, now?: number }} image
*/
export async function putLookImage(guildId, source, { hash, mime, data, origin = '', now = Date.now() }) {
await s.put.run(guildId, source, hash, mime, data.length, data, origin, now, now);
}

/** Note that a splash was checked and is still the same picture. */
export async function touchLookImage(guildId, source, now = Date.now()) {
await s.touch.run(now, guildId, source);
}

/** Delete the picture of a source. @returns {Promise<boolean>} whether there was one */
export async function deleteLookImage(guildId, source) {
return (await s.drop.run(guildId, source)).changes > 0;
}

/**
* A stored picture by the hash in its address, for this server only, or null.
* @returns {Promise<{ mime: string, bytes: number, data: Buffer } | null>}
*/
export async function readLookImage(guildId, hash) {
if (typeof hash !== 'string' || !/^[0-9a-f]{16}$/.test(hash)) return null;
const row = await s.byHash.get(guildId, hash);
return row ? { mime: row.mime, bytes: Number(row.bytes), data: Buffer.from(row.data) } : null;
}
Loading
Loading