Files
dashtab/app/config/integrations.js
raucao b057e3edca Add custom site links with icon discovery and upload
Users can add any website as a dashboard quick link from Settings → Site
Links. The link is stored in the integrations namespace as a `custom`
type so it flows through the existing sites/integrations/settings
pipeline, and appears in a new "Links" group.

Its icon is discovered with the existing favicon pipeline; an uploaded
icon overrides it and stays pinned until the user chooses "Use site's
icon" again. resolveIcons and refreshIcon skip pinned sites (and
re-check the live list before writing back) so an in-flight discovery
can never clobber a freshly uploaded icon.

URLs are normalized to http(s) only, with embedded credentials stripped,
so a value can never reach an anchor's href as javascript:/data:.
Uploads are validated, size-capped and downscaled to 192px (SVGs kept
as-is), and only ever rendered through an <img>.

Adds app/utils/site-url.js and app/utils/image-file.js, a custom-link
form, a `custom` registry entry/group and adapter, and tests.
2026-11-13 15:57:57 +04:00

162 lines
5.6 KiB
JavaScript

import { GITHUB_ICON_BACKGROUND, GITHUB_ICON_URL } from './github';
import { GITEA_ICON_BACKGROUND, GITEA_ICON_URL } from './gitea';
import {
HOME_ASSISTANT_ICON_URL,
HOME_ASSISTANT_ICON_BACKGROUND,
} from './home-assistant';
const CALENDAR_ICON_PATH =
'M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5A2.25 2.25 0 0 1 21 11.25v7.5';
// B-only glyph from the official Simple Icons bitcoin path. The full mark is
// a circle with the B cut out; extracting the B subpath and anchoring its
// relative move absolutely keeps the glyph centred in the 24x24 viewBox.
export const BITCOIN_ICON_PATH =
'M17.288 10.291c.24-1.59-.974-2.45-2.64-3.03l.54-2.153-1.315-.33-.525 2.107c-.345-.087-.705-.167-1.064-.25l.526-2.127-1.32-.33-.54 2.165c-.285-.067-.565-.132-.84-.2l-1.815-.45-.35 1.407s.975.225.955.236c.535.136.63.486.615.766l-1.477 5.92c-.075.166-.24.406-.614.314.015.02-.96-.24-.96-.24l-.66 1.51 1.71.426.93.242-.54 2.19 1.32.327.54-2.17c.36.1.705.19 1.05.273l-.51 2.154 1.32.33.545-2.19c2.24.427 3.93.257 4.64-1.774.57-1.637-.03-2.58-1.217-3.196.854-.193 1.5-.76 1.68-1.93h.01zm-3.01 4.22c-.404 1.64-3.157.75-4.05.53l.72-2.9c.896.23 3.757.67 3.33 2.37zm.41-4.24c-.37 1.49-2.662.735-3.405.55l.654-2.64c.744.18 3.137.524 2.75 2.084v.006z';
// Scale the B glyph around its visual centre so it fills more of the avatar.
export const BITCOIN_ICON_TRANSFORM =
'translate(11.575 11.775) scale(1.5) translate(-11.575 -11.775)';
// Heroicons link (outline), a single path so it fits the registry avatar.
const CUSTOM_LINK_ICON_PATH =
'M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244';
export const FEEDBIN_ICON_URL = '/img/icons/feedbin.png';
// Official Discourse square icon, used for the Add/Manage lists and as the
// dashboard tile's fallback until a forum's own favicon is resolved.
export const DISCOURSE_ICON_URL = '/img/icons/discourse.svg';
// Metadata for every integration the app knows about. `hasSettings` controls
// whether the Manage screen exposes an edit affordance; `reconnectable` marks
// integrations with an auth token that can be refreshed; `supportsMultiple`
// allows more than one connected instance.
export const INTEGRATIONS = [
{
id: 'discourse',
label: 'Discourse',
description: 'Notifications from your discussion forums',
colorClass: 'bg-indigo-500',
iconUrl: DISCOURSE_ICON_URL,
available: true,
supportsMultiple: true,
hasSettings: false,
reconnectable: true,
},
{
id: 'bitcoin',
label: 'Bitcoin Price Ticker',
description: 'Live BTC price',
colorClass: 'bg-[#F7931A]',
iconPath: BITCOIN_ICON_PATH,
iconTransform: BITCOIN_ICON_TRANSFORM,
iconFill: true,
available: true,
supportsMultiple: false,
hasSettings: true,
reconnectable: false,
},
{
id: 'feedbin',
label: 'Feedbin',
description: 'Unread count from your Feedbin RSS reader',
colorClass: 'bg-emerald-600',
iconUrl: FEEDBIN_ICON_URL,
available: true,
supportsMultiple: false,
hasSettings: true,
reconnectable: false,
},
{
id: 'github',
label: 'GitHub',
description: 'Unread notifications from GitHub',
colorClass: 'bg-gray-800',
iconUrl: GITHUB_ICON_URL,
themeColor: GITHUB_ICON_BACKGROUND,
available: true,
supportsMultiple: false,
hasSettings: true,
reconnectable: false,
},
{
id: 'gitea',
label: 'Gitea',
description: 'Unread notifications from your Gitea instances',
colorClass: 'bg-[#609926]',
iconUrl: GITEA_ICON_URL,
themeColor: GITEA_ICON_BACKGROUND,
available: true,
supportsMultiple: true,
hasSettings: true,
reconnectable: false,
},
{
id: 'calendar-caldav',
label: 'CalDAV',
description: 'Upcoming events from your CalDAV calendars',
colorClass: 'bg-rose-500',
iconPath: CALENDAR_ICON_PATH,
iconFill: false,
available: true,
supportsMultiple: true,
hasSettings: true,
reconnectable: false,
},
{
id: 'calendar-ics',
label: 'ICS / WebCal',
description: 'Upcoming events from a published calendar link',
colorClass: 'bg-rose-500',
iconPath: CALENDAR_ICON_PATH,
iconFill: false,
available: true,
supportsMultiple: true,
hasSettings: true,
reconnectable: false,
},
{
id: 'homeassistant',
label: 'Home Assistant',
description: 'Notifications from your Home Assistant instances',
colorClass: 'bg-[#18BCF2]',
iconUrl: HOME_ASSISTANT_ICON_URL,
themeColor: HOME_ASSISTANT_ICON_BACKGROUND,
available: true,
supportsMultiple: true,
hasSettings: true,
reconnectable: false,
},
{
id: 'openrouter',
label: 'OpenRouter Spend',
description: 'Daily, weekly, or monthly',
colorClass: 'bg-indigo-600',
iconUrl: '/img/icons/openrouter.svg',
// The glyph fills its square viewBox, so it needs to be inset rather than
// treated as a maskable full-bleed icon.
iconInset: true,
available: true,
supportsMultiple: false,
hasSettings: true,
reconnectable: false,
},
{
id: 'custom',
label: 'Custom Link',
description: 'Add any website as a quick link',
colorClass: 'bg-slate-500',
iconPath: CUSTOM_LINK_ICON_PATH,
iconFill: false,
available: true,
supportsMultiple: true,
hasSettings: true,
reconnectable: false,
},
];
export function integrationFor(type) {
return INTEGRATIONS.find((integration) => integration.id === type) ?? null;
}