Add configurable plugin system and move hardcoded IP to config

Introduces a plugin registry so the display mode is selectable per
device via the NixOS module config (defaults to "calendar"). Moves
the hardcoded render URL base into config.base_url. Adds tests
exercising the plugin system with a synthetic ICS feed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kate Meerburg 2026-05-24 21:24:32 +02:00
parent 6188ecebb9
commit ddcb03d3dd
5 changed files with 175 additions and 17 deletions

View file

@ -1,17 +1,21 @@
import { SHA256 } from 'bun';
import { devices } from './devices';
import { createPlugin } from './plugins';
import { makeScreenshot } from './render';
import { render } from './template';
import { ICSRenderable } from './xlcalendar';
let renderMap = new Map();
interface DeviceConfiguration {
plugin?: string;
settings?: Record<string, any>;
refresh?: number;
model: string;
}
interface Configuration {
[mac: string]: {
urls: string[];
refresh?: number;
model: string;
};
base_url: string;
devices: Record<string, DeviceConfiguration>;
}
const config: Configuration = JSON.parse(
@ -40,15 +44,16 @@ Bun.serve({
const id = req.headers.get('ID') ?? 'unknown';
const newfriendly = id.replaceAll(':', '');
const device = config[id] ?? {
urls: [],
const device = config.devices[id] ?? {
plugin: 'calendar',
settings: {},
refresh: undefined,
model: 'inkplate_10',
};
console.log(`Rendering for ${id}..`);
let plugin = new ICSRenderable(device.urls);
let plugin = createPlugin(device.plugin ?? 'calendar', device.settings ?? {});
const rendered = makeScreenshot(
[[plugin, 'full']],
devices.find((a) => a.name === device.model)!
@ -74,7 +79,7 @@ Bun.serve({
return Response.json({
status: 0,
image_url: `http://192.168.50.124:2300/api/render/${id.toLowerCase()}/${plugin.hash ?? Math.random()}.png`,
image_url: `${config.base_url}/api/render/${id.toLowerCase()}/${plugin.hash ?? Math.random()}.png`,
refresh_rate: nextRefresh.toString(),
update_firmware: false,
firmware_url: null,
@ -87,13 +92,14 @@ Bun.serve({
const id = req.headers.get('ID') ?? 'unknown';
const newfriendly = id.replaceAll(':', '');
const device = config[id] ?? {
urls: [],
const device = config.devices[id] ?? {
plugin: 'calendar',
settings: {},
refresh: undefined,
model: 'inkplate_10',
};
let plugin = new ICSRenderable(device.urls);
let plugin = createPlugin(device.plugin ?? 'calendar', device.settings ?? {});
const rendered = await render(
[[plugin, 'full']],
devices.find((a) => a.name === device.model)!