From 55d2b9433f7d638cb469fe31aa5e2b02a2b3e061 Mon Sep 17 00:00:00 2001 From: Philipp Traber Date: Wed, 14 Oct 2026 16:31:56 +0200 Subject: [PATCH] Let page owners turn logo.dev logos on and off Link pages get a "Website logos" switch on the appearance tab (stored as pages.show_logos, default on). When off, buttons show the letter placeholder and the logo.dev credit is hidden. The switch is disabled with a hint when the server has no LOGO_DEV_TOKEN, which /me now reports as `logoDev`. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- drizzle/0001_page_show_logos.sql | 1 + drizzle/meta/0001_snapshot.json | 591 +++++++++++++++++++++++ drizzle/meta/_journal.json | 7 + src/server/api.ts | 4 +- src/server/db/schema.ts | 2 + src/server/lib/pages.ts | 5 +- src/server/public/routes.tsx | 3 +- src/shared/api-types.ts | 3 + src/shared/validation.ts | 1 + src/web/components/ui/form.tsx | 42 ++ src/web/screens/detail/AppearanceTab.tsx | 35 +- src/web/screens/detail/DetailScreen.tsx | 2 +- test/api.test.ts | 26 +- test/helpers.ts | 3 +- 15 files changed, 712 insertions(+), 15 deletions(-) create mode 100644 drizzle/0001_page_show_logos.sql create mode 100644 drizzle/meta/0001_snapshot.json diff --git a/README.md b/README.md index 9ff9f82..01344ad 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ Copy `.env.template` to `.env` and fill it in: | `TIMEZONE` | | Timezone for "today" and the daily stats, default `UTC` | | `TRUST_PROXY` | | `true` behind a reverse proxy, so `X-Forwarded-For` is used for the visitor IP | | `DATA_DIR` | | Database and uploads, default `./data` (`/data` in Docker) | -| `LOGO_DEV_TOKEN` | | Shows website logos on link page buttons via [logo.dev](https://logo.dev) (adds an attribution) | +| `LOGO_DEV_TOKEN` | | Enables website logos on link page buttons via [logo.dev](https://logo.dev). Page owners can turn them off per page; the logo.dev credit only shows where logos are on | | `DISABLE_ATTRIBUTION` | | `true` hides the "powered by" footer | ### 3. Run diff --git a/drizzle/0001_page_show_logos.sql b/drizzle/0001_page_show_logos.sql new file mode 100644 index 0000000..229925c --- /dev/null +++ b/drizzle/0001_page_show_logos.sql @@ -0,0 +1 @@ +ALTER TABLE `pages` ADD `show_logos` integer DEFAULT true NOT NULL; \ No newline at end of file diff --git a/drizzle/meta/0001_snapshot.json b/drizzle/meta/0001_snapshot.json new file mode 100644 index 0000000..ba31af3 --- /dev/null +++ b/drizzle/meta/0001_snapshot.json @@ -0,0 +1,591 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "d686eb3d-38c6-4fa3-bdbd-6a774f85ddb0", + "prevId": "a6b76847-cea9-41ad-931d-e57ddc8613c4", + "tables": { + "api_tokens": { + "name": "api_tokens", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + }, + "last_used_at": { + "name": "last_used_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "api_tokens_token_hash_unique": { + "name": "api_tokens_token_hash_unique", + "columns": [ + "token_hash" + ], + "isUnique": true + } + }, + "foreignKeys": { + "api_tokens_user_id_users_id_fk": { + "name": "api_tokens_user_id_users_id_fk", + "tableFrom": "api_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "blocks": { + "name": "blocks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "page_id": { + "name": "page_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "markdown": { + "name": "markdown", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "blocks_page": { + "name": "blocks_page", + "columns": [ + "page_id", + "position" + ], + "isUnique": false + }, + "blocks_target": { + "name": "blocks_target", + "columns": [ + "target_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "blocks_page_id_pages_id_fk": { + "name": "blocks_page_id_pages_id_fk", + "tableFrom": "blocks", + "tableTo": "pages", + "columnsFrom": [ + "page_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "blocks_target_id_pages_id_fk": { + "name": "blocks_target_id_pages_id_fk", + "tableFrom": "blocks", + "tableTo": "pages", + "columnsFrom": [ + "target_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "clicks": { + "name": "clicks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "page_id": { + "name": "page_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "at": { + "name": "at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "day": { + "name": "day", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "visitor": { + "name": "visitor", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "clicks_page_day": { + "name": "clicks_page_day", + "columns": [ + "page_id", + "day", + "visitor" + ], + "isUnique": false + }, + "clicks_at": { + "name": "clicks_at", + "columns": [ + "at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "clicks_page_id_pages_id_fk": { + "name": "clicks_page_id_pages_id_fk", + "tableFrom": "clicks", + "tableTo": "pages", + "columnsFrom": [ + "page_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "daily_stats": { + "name": "daily_stats", + "columns": { + "page_id": { + "name": "page_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "day": { + "name": "day", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "clicks": { + "name": "clicks", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "uniques": { + "name": "uniques", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "last_at": { + "name": "last_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "daily_stats_page_id_pages_id_fk": { + "name": "daily_stats_page_id_pages_id_fk", + "tableFrom": "daily_stats", + "tableTo": "pages", + "columnsFrom": [ + "page_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "daily_stats_page_id_day_pk": { + "columns": [ + "page_id", + "day" + ], + "name": "daily_stats_page_id_day_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "pages": { + "name": "pages", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "namespace": { + "name": "namespace", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "dest": { + "name": "dest", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "avatar": { + "name": "avatar", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "theme": { + "name": "theme", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "show_logos": { + "name": "show_logos", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + } + }, + "indexes": { + "pages_namespace_code": { + "name": "pages_namespace_code", + "columns": [ + "namespace", + "code" + ], + "isUnique": true + } + }, + "foreignKeys": { + "pages_created_by_users_id_fk": { + "name": "pages_created_by_users_id_fk", + "tableFrom": "pages", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "sessions": { + "name": "sessions", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "settings": { + "name": "settings", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "sub": { + "name": "sub", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "is_admin": { + "name": "is_admin", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + } + }, + "indexes": { + "users_sub_unique": { + "name": "users_sub_unique", + "columns": [ + "sub" + ], + "isUnique": true + }, + "users_username_unique": { + "name": "users_username_unique", + "columns": [ + "username" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 089c463..093d048 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -8,6 +8,13 @@ "when": 1791978231861, "tag": "0000_init", "breakpoints": true + }, + { + "idx": 1, + "version": "6", + "when": 1791988240968, + "tag": "0001_page_show_logos", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/server/api.ts b/src/server/api.ts index 309500a..fe2c58d 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -2,7 +2,7 @@ import { Hono } from "hono"; import { bodyLimit } from "hono/body-limit"; import { desc, eq, and } from "drizzle-orm"; import type { z } from "zod"; -import type { ApiToken, CreatedToken } from "../shared/api-types.js"; +import type { ApiToken, CreatedToken, Me } from "../shared/api-types.js"; import { createBlockSchema, createPageSchema, @@ -65,7 +65,7 @@ export function apiRoutes(deps: Deps) { .get("/me", (c) => { const { username, isAdmin } = c.var.actor; - return c.json({ username, isAdmin }); + return c.json({ username, isAdmin, logoDev: !!config.logoDevToken } satisfies Me); }) // Pages (redirects and link pages) diff --git a/src/server/db/schema.ts b/src/server/db/schema.ts index 33c9368..d84f324 100644 --- a/src/server/db/schema.ts +++ b/src/server/db/schema.ts @@ -27,6 +27,8 @@ export const pages = sqliteTable( title: text("title"), avatar: text("avatar"), theme: text("theme", { mode: "json" }), + // Link pages only: show website logos from logo.dev (needs LOGO_DEV_TOKEN). + showLogos: integer("show_logos", { mode: "boolean" }).notNull().default(true), createdBy: integer("created_by").references(() => users.id, { onDelete: "set null" }), createdAt: createdAt(), updatedAt: integer("updated_at", { mode: "timestamp" }) diff --git a/src/server/lib/pages.ts b/src/server/lib/pages.ts index 7803065..ee57995 100644 --- a/src/server/lib/pages.ts +++ b/src/server/lib/pages.ts @@ -103,8 +103,8 @@ export function createPage(db: Db, actor: Actor, input: CreatePageInput): PageSu export function updatePage(db: Db, actor: Actor, id: number, input: UpdatePageInput): PageDetail { const page = loadManagedPage(db, actor, id); if (input.dest !== undefined && page.kind !== "redirect") throw new HttpError(400, "Only redirects have a destination"); - if ((input.title !== undefined || input.theme !== undefined) && page.kind !== "linkpage") { - throw new HttpError(400, "Only link pages have a title and theme"); + if ((input.title !== undefined || input.theme !== undefined || input.showLogos !== undefined) && page.kind !== "linkpage") { + throw new HttpError(400, "Only link pages have a title, theme and logos"); } if (input.code !== undefined && input.code !== page.code && codeTaken(db, page.namespace, input.code)) { throw new HttpError(409, "Shortcode is not available", { code: ["Already in use or reserved"] }); @@ -207,6 +207,7 @@ export function getPageDetail(db: Db, actor: Actor, id: number): PageDetail { return { ...toSummary(page, clicks, getPinnedPageId(db) === id), theme: (page.theme as Theme | null) ?? DEFAULT_THEME, + showLogos: page.showLogos, avatarUrl: avatarUrl(page.avatar), blocks: page.kind === "linkpage" ? getBlocks(db, id) : [], }; diff --git a/src/server/public/routes.tsx b/src/server/public/routes.tsx index 0ce9d60..fe50ae7 100644 --- a/src/server/public/routes.tsx +++ b/src/server/public/routes.tsx @@ -52,7 +52,8 @@ export function publicRoutes({ db, config }: Deps) { avatarUrl={avatarUrl(page.avatar)} theme={(page.theme as Theme | null) ?? DEFAULT_THEME} blocks={getBlocks(db, page.id)} - logoDevToken={config.logoDevToken} + // Logos and their attribution only appear when the page owner enabled them. + logoDevToken={page.showLogos ? config.logoDevToken : undefined} showAttribution={!config.disableAttribution} />, ); diff --git a/src/shared/api-types.ts b/src/shared/api-types.ts index 20d5ff9..45a1ca9 100644 --- a/src/shared/api-types.ts +++ b/src/shared/api-types.ts @@ -6,6 +6,8 @@ export type PageKind = "redirect" | "linkpage"; export interface Me { username: string; isAdmin: boolean; + /** Whether the server has a logo.dev token, i.e. link pages can show website logos. */ + logoDev: boolean; } export interface PageSummary { @@ -31,6 +33,7 @@ export interface Block { export interface PageDetail extends PageSummary { theme: Theme; + showLogos: boolean; avatarUrl: string | null; blocks: Block[]; } diff --git a/src/shared/validation.ts b/src/shared/validation.ts index e4f6ff5..d1c264c 100644 --- a/src/shared/validation.ts +++ b/src/shared/validation.ts @@ -67,6 +67,7 @@ export const updatePageSchema = z.object({ dest: destSchema.optional(), title: titleSchema.optional(), theme: themeSchema.optional(), + showLogos: z.boolean().optional(), }); export type UpdatePageInput = z.infer; diff --git a/src/web/components/ui/form.tsx b/src/web/components/ui/form.tsx index 8fbca6a..6289804 100644 --- a/src/web/components/ui/form.tsx +++ b/src/web/components/ui/form.tsx @@ -102,3 +102,45 @@ export function ColorInput({ value, onChange, label }: { value: string; onChange ); } + +// On/off switch with a label and optional description, e.g. for settings. +export function Switch({ + checked, + onChange, + label, + description, + disabled, +}: { + checked: boolean; + onChange: (checked: boolean) => void; + label: string; + description?: ReactNode; + disabled?: boolean; +}) { + const id = useId(); + return ( +
+
+ + {description &&
{description}
} +
+ +
+ ); +} diff --git a/src/web/screens/detail/AppearanceTab.tsx b/src/web/screens/detail/AppearanceTab.tsx index ddded5c..da21f4a 100644 --- a/src/web/screens/detail/AppearanceTab.tsx +++ b/src/web/screens/detail/AppearanceTab.tsx @@ -1,10 +1,10 @@ import { useRef, useState, type ReactNode } from "react"; import { Check, ExternalLink, ImageUp, Trash2 } from "lucide-react"; -import type { PageDetail } from "../../../shared/api-types.js"; +import type { Me, PageDetail } from "../../../shared/api-types.js"; import type { Theme } from "../../../shared/validation.js"; import { api } from "../../api.js"; import { Button } from "../../components/ui/button.js"; -import { ColorInput, Field, Input, Segmented } from "../../components/ui/form.js"; +import { ColorInput, Field, Input, Segmented, Switch } from "../../components/ui/form.js"; import { Card, CardBody, CardFooter, CardHeader } from "../../components/ui/surface.js"; import { useAction } from "../../components/ui/toast.js"; import { cx } from "../../lib/cx.js"; @@ -241,16 +241,17 @@ function MockPreview({ title, avatarUrl, theme, page }: { title: string; avatarU ); } -export function AppearanceTab({ page, onChange }: { page: PageDetail; onChange: (page: PageDetail) => void }) { +export function AppearanceTab({ page, me, onChange }: { page: PageDetail; me: Me; onChange: (page: PageDetail) => void }) { const [title, setTitle] = useState(page.title ?? ""); const [theme, setTheme] = useState(page.theme); + const [showLogos, setShowLogos] = useState(page.showLogos); const { busy, run } = useAction(); const upload = useAction(); const fileInput = useRef(null); - const dirty = title !== (page.title ?? "") || !sameTheme(theme, page.theme); + const dirty = title !== (page.title ?? "") || !sameTheme(theme, page.theme) || showLogos !== page.showLogos; - const save = () => run(async () => onChange(await api("PATCH", `/pages/${page.id}`, { title, theme })), "Appearance saved"); + const save = () => run(async () => onChange(await api("PATCH", `/pages/${page.id}`, { title, theme, showLogos })), "Appearance saved"); const uploadAvatar = (file: File | undefined) => { if (!file) return; @@ -311,8 +312,29 @@ export function AppearanceTab({ page, onChange }: { page: PageDetail; onChange: - + +
+ + Show the logo of each link's website on its button, provided by{" "} + + logo.dev + + . When off, buttons show the first letter instead and the logo.dev credit is hidden. + + ) : ( + "Not available on this server. An admin can enable it by setting LOGO_DEV_TOKEN." + ) + } + /> +
{dirty && Unsaved changes} @@ -322,6 +344,7 @@ export function AppearanceTab({ page, onChange }: { page: PageDetail; onChange: onClick={() => { setTitle(page.title ?? ""); setTheme(page.theme); + setShowLogos(page.showLogos); }} > Discard diff --git a/src/web/screens/detail/DetailScreen.tsx b/src/web/screens/detail/DetailScreen.tsx index 0cb408c..f4f89b4 100644 --- a/src/web/screens/detail/DetailScreen.tsx +++ b/src/web/screens/detail/DetailScreen.tsx @@ -109,7 +109,7 @@ export function DetailScreen({ id, kind, tab, me }: { id: number; kind: PageKind
{active === "content" && } - {active === "appearance" && } + {active === "appearance" && } {active === "analytics" && } {active === "qr" && } {active === "settings" && } diff --git a/test/api.test.ts b/test/api.test.ts index ab1f15f..cec2c3a 100644 --- a/test/api.test.ts +++ b/test/api.test.ts @@ -46,7 +46,7 @@ describe("authentication", () => { expect(callback.status).toBe(302); const session = callback.headers.getSetCookie().find((c) => c.startsWith("short_session="))!.split(";")[0]!; const me = await (await app.request("/~/api/me", { headers: { cookie: session } })).json(); - expect(me).toEqual({ username: "alice", isAdmin: true }); + expect(me).toEqual({ username: "alice", isAdmin: true, logoDev: false }); // A renamed account keeps its original namespace; losing the group removes admin. const login2 = await app.request("/~/auth/login"); @@ -58,6 +58,7 @@ describe("authentication", () => { expect(await (await app.request("/~/api/me", { headers: { cookie: session2 } })).json()).toEqual({ username: "alice", isAdmin: false, + logoDev: false, }); }); @@ -209,6 +210,29 @@ describe("link pages", () => { expect(html).not.toContain('href="javascript:'); }); + it("shows logo.dev logos and attribution only when enabled for the page", async () => { + const { app, user } = setup({ logoDevToken: "pk_test" }); + const alice = user("alice"); + expect((await (await alice.api("GET", "/me")).json()).logoDev).toBe(true); + + const page = await (await alice.api("POST", "/pages", { kind: "linkpage", code: "me", title: "Alice" })).json(); + const link = await (await alice.api("POST", "/pages", { kind: "redirect", code: "gh", dest: "https://github.com" })).json(); + await alice.api("POST", `/pages/${page.id}/blocks`, { kind: "link", targetId: link.id, label: "GitHub" }); + + const enabled = await (await app.request("/alice/me")).text(); + expect(enabled).toContain("img.logo.dev/github.com"); + expect(enabled).toContain("Logos provided by"); + + const updated = await (await alice.api("PATCH", `/pages/${page.id}`, { showLogos: false })).json(); + expect(updated.showLogos).toBe(false); + const disabled = await (await app.request("/alice/me")).text(); + expect(disabled).not.toContain("img.logo.dev"); + expect(disabled).not.toContain("Logos provided by"); + + // Redirects have no logos setting. + expect((await alice.api("PATCH", `/pages/${link.id}`, { showLogos: false })).status).toBe(400); + }); + it("removes blocks, stats and pin when a linked page is deleted", async () => { const { app, user } = setup(); const admin = user("root", true); diff --git a/test/helpers.ts b/test/helpers.ts index ca3c90f..ed94bed 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -9,7 +9,7 @@ import { openDb } from "../src/server/db/index.js"; export const BASE_URL = "https://short.test"; -export function setup() { +export function setup(overrides: Partial = {}) { const config: Config = { baseUrl: BASE_URL, oidc: { issuer: "https://auth.test/", clientId: "id", clientSecret: "secret" }, @@ -22,6 +22,7 @@ export function setup() { disableAttribution: false, retentionDays: 90, port: 0, + ...overrides, }; const db = openDb(":memory:");