mirror of
https://github.com/Since-3/since3-portal.git
synced 2026-10-12 19:51:17 +00:00
20 lines
875 B
TypeScript
20 lines
875 B
TypeScript
import "server-only"
|
|
import { cache } from "react"
|
|
import { createClient } from "@/lib/supabase/server"
|
|
import { resolveContent } from "../lib/content"
|
|
import { getTemplate } from "../lib/registry"
|
|
|
|
const TOKEN = /^[A-Za-z0-9_-]{20,64}$/
|
|
|
|
// Öffentlich (siehe proxy.ts): nur die eine Variante zum Token, abgelaufene Links ergeben null
|
|
export const getSharedVariant = cache(async (token: string) => {
|
|
if (!TOKEN.test(token)) return null
|
|
|
|
const supabase = await createClient()
|
|
const { data } = await supabase.rpc("get_shared_template_variant", { p_token: token }).maybeSingle()
|
|
const shared = data as { template_key: string; name: string; content: unknown } | null
|
|
const def = shared ? getTemplate(shared.template_key) : undefined
|
|
if (!shared || !def) return null
|
|
|
|
return { name: shared.name, def, content: resolveContent(def, shared.content) }
|
|
})
|