import { defineStore } from "pinia"; import { ref } from "vue"; import { repo } from "../adapters"; export interface PublicConfig { site_name: string; allow_registration: boolean; version: string; enable_url_unfurl: boolean; // How many days a note survives in Trash before the server purges it. 0 = forever. trash_retention_days: number; } // Public, unauthenticated app config (site name, whether signups are open). export const useConfigStore = defineStore("config", () => { const siteName = ref("ThoughtSync"); const allowRegistration = ref(true); const version = ref(""); const enableUrlUnfurl = ref(true); // Mirrors the server default (settings.REGISTRY). Only used if /api/config is // unreachable — and 30 is a safer stand-in than 0, since claiming "kept forever" // when the server is actually purging is the wrong way to be wrong. const trashRetentionDays = ref(30); const loaded = ref(false); async function load(): Promise { if (loaded.value) return; try { const cfg = await repo.config.get(); siteName.value = cfg.site_name; allowRegistration.value = cfg.allow_registration; version.value = cfg.version; enableUrlUnfurl.value = cfg.enable_url_unfurl ?? true; trashRetentionDays.value = cfg.trash_retention_days ?? 30; } catch { // Keep defaults if the config endpoint is unreachable. } finally { loaded.value = true; } } async function reload(): Promise { loaded.value = false; await load(); } return { siteName, allowRegistration, version, enableUrlUnfurl, trashRetentionDays, loaded, load, reload }; });