forked from coracle/caravel
Update frontend to fit backend
This commit is contained in:
@@ -50,7 +50,7 @@ export default function AppShell(props: { children?: any }) {
|
||||
if (!query) return list
|
||||
|
||||
const fuse = new Fuse(list, {
|
||||
keys: ["name", "subdomain"],
|
||||
keys: ["info_name", "subdomain"],
|
||||
threshold: 0.35,
|
||||
ignoreLocation: true,
|
||||
})
|
||||
@@ -224,7 +224,7 @@ export default function AppShell(props: { children?: any }) {
|
||||
class="block rounded-lg border border-gray-200 bg-white p-3"
|
||||
onClick={closeSearchModal}
|
||||
>
|
||||
<p class="text-sm font-medium text-gray-900">{relay.name}</p>
|
||||
<p class="text-sm font-medium text-gray-900">{relay.info_name || relay.subdomain}</p>
|
||||
<p class="text-xs text-gray-500">{relay.subdomain}.spaces.coracle.social</p>
|
||||
</A>
|
||||
</li>
|
||||
|
||||
@@ -97,7 +97,11 @@ type RelayDetailCardProps = {
|
||||
|
||||
export default function RelayDetailCard(props: RelayDetailCardProps) {
|
||||
const r = () => props.relay
|
||||
const cfg = () => r().config
|
||||
const flag = (value: number, fallback: boolean) => {
|
||||
if (value === 0) return false
|
||||
if (value === 1) return true
|
||||
return fallback
|
||||
}
|
||||
const [menuOpen, setMenuOpen] = createSignal(false)
|
||||
const [planModalOpen, setPlanModalOpen] = createSignal(false)
|
||||
const [selectedPlan, setSelectedPlan] = createSignal<RelayPlanId>("free")
|
||||
@@ -170,19 +174,19 @@ export default function RelayDetailCard(props: RelayDetailCardProps) {
|
||||
{/* Header */}
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div class="flex items-start gap-4 min-w-0">
|
||||
<Show when={r().icon}>
|
||||
<img src={r().icon} alt="" class="w-14 h-14 rounded-xl object-cover flex-shrink-0 border border-gray-200" />
|
||||
<Show when={r().info_icon}>
|
||||
<img src={r().info_icon} alt="" class="w-14 h-14 rounded-xl object-cover flex-shrink-0 border border-gray-200" />
|
||||
</Show>
|
||||
<div class="min-w-0">
|
||||
<h1 class="text-2xl font-bold text-gray-900">{r().name}</h1>
|
||||
<h1 class="text-2xl font-bold text-gray-900">{r().info_name || r().subdomain}</h1>
|
||||
<a
|
||||
href={`wss://${r().subdomain}.spaces.coracle.social`}
|
||||
class="text-sm text-blue-600 hover:underline break-all"
|
||||
>
|
||||
wss://{r().subdomain}.spaces.coracle.social
|
||||
</a>
|
||||
<Show when={r().description.trim()}>
|
||||
<p class="mt-2 text-sm text-gray-600">{r().description}</p>
|
||||
<Show when={r().info_description.trim()}>
|
||||
<p class="mt-2 text-sm text-gray-600">{r().info_description}</p>
|
||||
</Show>
|
||||
</div>
|
||||
</div>
|
||||
@@ -233,13 +237,13 @@ export default function RelayDetailCard(props: RelayDetailCardProps) {
|
||||
<DetailSection title="Policy">
|
||||
<ToggleField label="Public join">
|
||||
<ToggleButton
|
||||
enabled={cfg()?.policy.public_join ?? false}
|
||||
enabled={flag(r().policy_public_join, false)}
|
||||
onToggle={props.onTogglePublicJoin}
|
||||
/>
|
||||
</ToggleField>
|
||||
<ToggleField label="Strip signatures">
|
||||
<ToggleButton
|
||||
enabled={cfg()?.policy.strip_signatures ?? false}
|
||||
enabled={flag(r().policy_strip_signatures, false)}
|
||||
onToggle={props.onToggleStripSignatures}
|
||||
/>
|
||||
</ToggleField>
|
||||
@@ -250,19 +254,19 @@ export default function RelayDetailCard(props: RelayDetailCardProps) {
|
||||
<DetailSection title="Features">
|
||||
<ToggleField label="Rooms">
|
||||
<ToggleButton
|
||||
enabled={cfg()?.groups.enabled ?? true}
|
||||
enabled={flag(r().groups_enabled, true)}
|
||||
onToggle={props.onToggleGroups}
|
||||
/>
|
||||
</ToggleField>
|
||||
<ToggleField label="Management API">
|
||||
<ToggleButton
|
||||
enabled={cfg()?.management.enabled ?? true}
|
||||
enabled={flag(r().management_enabled, true)}
|
||||
onToggle={props.onToggleManagement}
|
||||
/>
|
||||
</ToggleField>
|
||||
<ToggleField label="Push notifications">
|
||||
<ToggleButton
|
||||
enabled={cfg()?.push.enabled ?? true}
|
||||
enabled={flag(r().push_enabled, true)}
|
||||
onToggle={props.onTogglePushNotifications}
|
||||
/>
|
||||
</ToggleField>
|
||||
@@ -270,7 +274,7 @@ export default function RelayDetailCard(props: RelayDetailCardProps) {
|
||||
<Show
|
||||
when={!planLimited()}
|
||||
fallback={
|
||||
<Show when={showPlanActions()} fallback={<ToggleButton enabled={cfg()?.blossom.enabled ?? false} onToggle={props.onToggleMediaStorage} />}>
|
||||
<Show when={showPlanActions()} fallback={<ToggleButton enabled={flag(r().blossom_enabled, false)} onToggle={props.onToggleMediaStorage} />}>
|
||||
<Show
|
||||
when={props.onUpdatePlan}
|
||||
fallback={
|
||||
@@ -294,7 +298,7 @@ export default function RelayDetailCard(props: RelayDetailCardProps) {
|
||||
}
|
||||
>
|
||||
<ToggleButton
|
||||
enabled={cfg()?.blossom.enabled ?? true}
|
||||
enabled={flag(r().blossom_enabled, true)}
|
||||
onToggle={props.onToggleMediaStorage}
|
||||
/>
|
||||
</Show>
|
||||
@@ -303,7 +307,7 @@ export default function RelayDetailCard(props: RelayDetailCardProps) {
|
||||
<Show
|
||||
when={!planLimited()}
|
||||
fallback={
|
||||
<Show when={showPlanActions()} fallback={<ToggleButton enabled={cfg()?.livekit.enabled ?? false} onToggle={props.onToggleLivekitSupport} />}>
|
||||
<Show when={showPlanActions()} fallback={<ToggleButton enabled={flag(r().livekit_enabled, false)} onToggle={props.onToggleLivekitSupport} />}>
|
||||
<Show
|
||||
when={props.onUpdatePlan}
|
||||
fallback={
|
||||
@@ -327,7 +331,7 @@ export default function RelayDetailCard(props: RelayDetailCardProps) {
|
||||
}
|
||||
>
|
||||
<ToggleButton
|
||||
enabled={cfg()?.livekit.enabled ?? true}
|
||||
enabled={flag(r().livekit_enabled, true)}
|
||||
onToggle={props.onToggleLivekitSupport}
|
||||
/>
|
||||
</Show>
|
||||
|
||||
+112
-84
@@ -20,6 +20,11 @@ type EventSigner = {
|
||||
signEvent(event: UnsignedEvent): Promise<SignedEvent>
|
||||
}
|
||||
|
||||
type ApiOk<T> = {
|
||||
data: T
|
||||
code: string
|
||||
}
|
||||
|
||||
export class ApiError extends Error {
|
||||
status: number
|
||||
|
||||
@@ -36,6 +41,12 @@ function getActiveSigner(): EventSigner {
|
||||
return account.signer
|
||||
}
|
||||
|
||||
function getActivePubkey(): string {
|
||||
const account = accounts.getActive() as { pubkey?: string } | undefined
|
||||
if (!account?.pubkey) throw new Error("Not logged in")
|
||||
return account.pubkey
|
||||
}
|
||||
|
||||
async function createNip98Header(url: string, method: string): Promise<string> {
|
||||
const signer = getActiveSigner()
|
||||
const event = await signer.signEvent({
|
||||
@@ -75,69 +86,63 @@ async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
} catch {
|
||||
// ignored
|
||||
}
|
||||
if (response.status === 403 && path.startsWith("/admin/") && typeof window !== "undefined") {
|
||||
window.location.replace("/relays")
|
||||
}
|
||||
throw new ApiError(message, response.status)
|
||||
}
|
||||
|
||||
if (response.status === 204) {
|
||||
return undefined as T
|
||||
}
|
||||
|
||||
return response.json() as Promise<T>
|
||||
if (response.status === 204) return undefined as T
|
||||
const body = await response.json() as ApiOk<T>
|
||||
return body.data
|
||||
}
|
||||
|
||||
export type RelayConfig = {
|
||||
policy: {
|
||||
public_join: boolean
|
||||
strip_signatures: boolean
|
||||
}
|
||||
groups: {
|
||||
enabled: boolean
|
||||
auto_join: boolean
|
||||
}
|
||||
management: {
|
||||
enabled: boolean
|
||||
|
||||
}
|
||||
blossom: {
|
||||
enabled: boolean
|
||||
}
|
||||
livekit: {
|
||||
enabled: boolean
|
||||
}
|
||||
push: {
|
||||
enabled: boolean
|
||||
async function ensureTenant() {
|
||||
try {
|
||||
await request<Tenant>("/tenants", { method: "POST" })
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError && e.status === 422) return
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
export type Relay = {
|
||||
id: string
|
||||
tenant: string
|
||||
name: string
|
||||
subdomain: string
|
||||
schema: string
|
||||
icon: string
|
||||
description: string
|
||||
subdomain: string
|
||||
plan: string
|
||||
status: string
|
||||
config: RelayConfig
|
||||
sync_error: string
|
||||
info_name: string
|
||||
info_icon: string
|
||||
info_description: string
|
||||
policy_public_join: number
|
||||
policy_strip_signatures: number
|
||||
groups_enabled: number
|
||||
management_enabled: number
|
||||
blossom_enabled: number
|
||||
livekit_enabled: number
|
||||
push_enabled: number
|
||||
}
|
||||
|
||||
export type Tenant = {
|
||||
pubkey: string
|
||||
status: string
|
||||
tenant_nwc_url: string
|
||||
nwc_url: string
|
||||
created_at: number
|
||||
billing_anchor: number
|
||||
}
|
||||
|
||||
export type Invoice = {
|
||||
id: string
|
||||
tenant: string
|
||||
amount: number
|
||||
status: string
|
||||
created_at: string
|
||||
invoice: string
|
||||
created_at: number
|
||||
attempted_at: number
|
||||
error: string
|
||||
closed_at: number
|
||||
sent_at: number
|
||||
paid_at: number
|
||||
bolt11: string
|
||||
period_start: number
|
||||
period_end: number
|
||||
}
|
||||
|
||||
export type TenantDetail = {
|
||||
@@ -145,12 +150,34 @@ export type TenantDetail = {
|
||||
relays: Relay[]
|
||||
}
|
||||
|
||||
export type UpdateRelayInput = {
|
||||
name: string
|
||||
export type CreateRelayInput = {
|
||||
subdomain: string
|
||||
icon: string
|
||||
description: string
|
||||
config: RelayConfig
|
||||
plan: string
|
||||
info_name?: string
|
||||
info_icon?: string
|
||||
info_description?: string
|
||||
policy_public_join?: number
|
||||
policy_strip_signatures?: number
|
||||
groups_enabled?: number
|
||||
management_enabled?: number
|
||||
blossom_enabled?: number
|
||||
livekit_enabled?: number
|
||||
push_enabled?: number
|
||||
}
|
||||
|
||||
export type UpdateRelayInput = {
|
||||
subdomain?: string
|
||||
plan?: string
|
||||
info_name?: string
|
||||
info_icon?: string
|
||||
info_description?: string
|
||||
policy_public_join?: number
|
||||
policy_strip_signatures?: number
|
||||
groups_enabled?: number
|
||||
management_enabled?: number
|
||||
blossom_enabled?: number
|
||||
livekit_enabled?: number
|
||||
push_enabled?: number
|
||||
}
|
||||
|
||||
export type AdminCheck = {
|
||||
@@ -158,100 +185,101 @@ export type AdminCheck = {
|
||||
}
|
||||
|
||||
export function listTenantRelays() {
|
||||
return request<Relay[]>("/tenant/relays")
|
||||
return request<Relay[]>("/relays")
|
||||
}
|
||||
|
||||
export function getTenant() {
|
||||
return request<Tenant>("/tenant")
|
||||
export async function getTenant() {
|
||||
const pubkey = getActivePubkey()
|
||||
await ensureTenant()
|
||||
return request<Tenant>(`/tenants/${pubkey}`)
|
||||
}
|
||||
|
||||
export type CreateRelayInput = {
|
||||
name: string
|
||||
subdomain: string
|
||||
icon: string
|
||||
description: string
|
||||
plan: string
|
||||
config: RelayConfig
|
||||
}
|
||||
|
||||
export function createTenantRelay(input: CreateRelayInput) {
|
||||
return request<Relay>("/tenant/relays", {
|
||||
export async function createTenantRelay(input: CreateRelayInput) {
|
||||
await ensureTenant()
|
||||
return request<Relay>("/relays", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(input),
|
||||
body: JSON.stringify({ tenant: getActivePubkey(), ...input }),
|
||||
})
|
||||
}
|
||||
|
||||
export function getTenantRelay(id: string) {
|
||||
return request<Relay>(`/tenant/relays/${id}`)
|
||||
return request<Relay>(`/relays/${id}`)
|
||||
}
|
||||
|
||||
export function updateTenantRelay(id: string, input: UpdateRelayInput) {
|
||||
return request<Relay>(`/tenant/relays/${id}`, {
|
||||
return request<Relay>(`/relays/${id}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(input),
|
||||
})
|
||||
}
|
||||
|
||||
export function updateTenantRelayPlan(id: string, plan: string) {
|
||||
return request<Relay>(`/tenant/relays/${id}/plan`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({ plan }),
|
||||
})
|
||||
return updateTenantRelay(id, { plan })
|
||||
}
|
||||
|
||||
export function deactivateTenantRelay(id: string) {
|
||||
return request<Relay>(`/tenant/relays/${id}/deactivate`, {
|
||||
return request<void>(`/relays/${id}/deactivate`, {
|
||||
method: "POST",
|
||||
})
|
||||
}
|
||||
|
||||
export function listTenantInvoices() {
|
||||
return request<Invoice[]>("/tenant/invoices")
|
||||
export async function listTenantInvoices() {
|
||||
await ensureTenant()
|
||||
return request<Invoice[]>("/invoices")
|
||||
}
|
||||
|
||||
export function updateTenantBilling(tenant_nwc_url: string) {
|
||||
return request<Tenant>("/tenant/billing", {
|
||||
export function updateTenantBilling(nwc_url: string) {
|
||||
return request<{ nwc_url: string }>(`/tenants/${getActivePubkey()}/billing`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({ tenant_nwc_url }),
|
||||
body: JSON.stringify({ nwc_url }),
|
||||
})
|
||||
}
|
||||
|
||||
export function adminListTenants() {
|
||||
return request<Tenant[]>("/admin/tenants")
|
||||
return request<Tenant[]>("/tenants")
|
||||
}
|
||||
|
||||
export function adminCheck() {
|
||||
return request<AdminCheck>("/admin/check")
|
||||
export async function adminCheck() {
|
||||
try {
|
||||
await request<Tenant[]>("/tenants")
|
||||
return { is_admin: true }
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError && e.status === 403) return { is_admin: false }
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
export function adminGetTenant(pubkey: string) {
|
||||
return request<TenantDetail>(`/admin/tenants/${pubkey}`)
|
||||
export async function adminGetTenant(pubkey: string) {
|
||||
const [tenant, relays] = await Promise.all([
|
||||
request<Tenant>(`/tenants/${pubkey}`),
|
||||
request<Relay[]>(`/relays?tenant=${encodeURIComponent(pubkey)}`),
|
||||
])
|
||||
return { tenant, relays }
|
||||
}
|
||||
|
||||
export function adminUpdateTenantStatus(pubkey: string, status: string) {
|
||||
return request<Tenant>(`/admin/tenants/${pubkey}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({ status }),
|
||||
})
|
||||
void pubkey
|
||||
void status
|
||||
throw new Error("Tenant status updates are not supported by this API")
|
||||
}
|
||||
|
||||
export function adminListRelays() {
|
||||
return request<Relay[]>("/admin/relays")
|
||||
return request<Relay[]>("/relays")
|
||||
}
|
||||
|
||||
export function adminGetRelay(id: string) {
|
||||
return request<Relay>(`/admin/relays/${id}`)
|
||||
return request<Relay>(`/relays/${id}`)
|
||||
}
|
||||
|
||||
export function adminUpdateRelay(id: string, input: UpdateRelayInput) {
|
||||
return request<Relay>(`/admin/relays/${id}`, {
|
||||
return request<Relay>(`/relays/${id}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(input),
|
||||
})
|
||||
}
|
||||
|
||||
export function adminDeactivateRelay(id: string) {
|
||||
return request<Relay>(`/admin/relays/${id}/deactivate`, {
|
||||
return request<void>(`/relays/${id}/deactivate`, {
|
||||
method: "POST",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ export default function Account() {
|
||||
const invoicesLoading = useMinLoading(() => invoices.loading)
|
||||
|
||||
const hasBillingChanges = createMemo(() => {
|
||||
const current = tenant()?.tenant_nwc_url?.trim() ?? ""
|
||||
const current = tenant()?.nwc_url?.trim() ?? ""
|
||||
const next = nwcUrl().trim()
|
||||
return current !== next
|
||||
})
|
||||
|
||||
createEffect(() => {
|
||||
setNwcUrl(tenant()?.tenant_nwc_url ?? "")
|
||||
setNwcUrl(tenant()?.nwc_url ?? "")
|
||||
})
|
||||
|
||||
async function saveBilling() {
|
||||
@@ -47,7 +47,7 @@ export default function Account() {
|
||||
<Show when={tenant()}>
|
||||
{(t) => (
|
||||
<span class="rounded-full border border-gray-300 bg-gray-100 px-2.5 py-1 text-xs font-medium uppercase tracking-wide text-gray-700">
|
||||
{t().status}
|
||||
tenant
|
||||
</span>
|
||||
)}
|
||||
</Show>
|
||||
@@ -93,11 +93,11 @@ export default function Account() {
|
||||
{(invoice) => (
|
||||
<li class="rounded-lg border border-gray-200 p-3 text-sm text-gray-700">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<span class="font-medium">{invoice.amount.toLocaleString()} sats</span>
|
||||
<span class="font-medium">—</span>
|
||||
<span class="uppercase text-xs tracking-wide text-gray-500">{invoice.status}</span>
|
||||
</div>
|
||||
<p class="text-xs text-gray-500 mt-1">{new Date(invoice.created_at).toLocaleString()}</p>
|
||||
<p class="text-xs mt-2 break-all">{invoice.invoice}</p>
|
||||
<p class="text-xs text-gray-500 mt-1">{new Date(invoice.created_at * 1000).toLocaleString()}</p>
|
||||
<p class="text-xs mt-2 break-all">{invoice.bolt11}</p>
|
||||
</li>
|
||||
)}
|
||||
</For>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useParams } from "@solidjs/router"
|
||||
import { createResource, createSignal, Show } from "solid-js"
|
||||
import { adminDeactivateRelay, adminGetRelay, adminUpdateRelay, type RelayConfig } from "../../lib/api"
|
||||
import { adminDeactivateRelay, adminGetRelay, adminUpdateRelay, type Relay } from "../../lib/api"
|
||||
import BackLink from "../../components/BackLink"
|
||||
import PageContainer from "../../components/PageContainer"
|
||||
import RelayDetailCard from "../../components/RelayDetailCard"
|
||||
@@ -29,118 +29,100 @@ export default function AdminRelayDetail() {
|
||||
}
|
||||
}
|
||||
|
||||
function withDefaults(config?: RelayConfig): RelayConfig {
|
||||
return {
|
||||
policy: {
|
||||
public_join: config?.policy.public_join ?? false,
|
||||
strip_signatures: config?.policy.strip_signatures ?? false,
|
||||
},
|
||||
groups: {
|
||||
enabled: config?.groups.enabled ?? true,
|
||||
auto_join: config?.groups.auto_join ?? true,
|
||||
},
|
||||
management: {
|
||||
enabled: config?.management.enabled ?? true,
|
||||
},
|
||||
blossom: {
|
||||
enabled: config?.blossom.enabled ?? (relay()?.plan !== "free"),
|
||||
},
|
||||
livekit: {
|
||||
enabled: config?.livekit.enabled ?? (relay()?.plan !== "free"),
|
||||
},
|
||||
push: {
|
||||
enabled: config?.push.enabled ?? true,
|
||||
},
|
||||
}
|
||||
function toBool(value: number | undefined, fallback: boolean): boolean {
|
||||
if (value === 0) return false
|
||||
if (value === 1) return true
|
||||
return fallback
|
||||
}
|
||||
|
||||
async function updateFlags(nextConfig: RelayConfig, previousConfig: RelayConfig) {
|
||||
function toInt(value: boolean): number {
|
||||
return value ? 1 : 0
|
||||
}
|
||||
|
||||
async function updateRelay(next: Relay, previous: Relay) {
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
|
||||
setError("")
|
||||
const optimisticRelay = {
|
||||
...current,
|
||||
config: nextConfig,
|
||||
}
|
||||
mutate(optimisticRelay)
|
||||
mutate(next)
|
||||
|
||||
try {
|
||||
await adminUpdateRelay(relayId(), {
|
||||
name: current.name,
|
||||
subdomain: current.subdomain,
|
||||
icon: current.icon,
|
||||
description: current.description,
|
||||
config: nextConfig,
|
||||
})
|
||||
await adminUpdateRelay(relayId(), next)
|
||||
await refetch()
|
||||
} catch (e) {
|
||||
mutate({ ...current, config: previousConfig })
|
||||
mutate(previous)
|
||||
setError(e instanceof Error ? e.message : "Failed to update relay settings")
|
||||
}
|
||||
}
|
||||
|
||||
function togglePublicJoin() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
policy: { ...config.policy, public_join: !config.policy.public_join },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
policy_public_join: toInt(!toBool(current.policy_public_join, false)),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
function toggleStripSignatures() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
policy: { ...config.policy, strip_signatures: !config.policy.strip_signatures },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
policy_strip_signatures: toInt(!toBool(current.policy_strip_signatures, false)),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
function toggleGroups() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
groups: { ...config.groups, enabled: !config.groups.enabled },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
groups_enabled: toInt(!toBool(current.groups_enabled, true)),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
function toggleManagement() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
management: { enabled: !config.management.enabled },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
management_enabled: toInt(!toBool(current.management_enabled, true)),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
function toggleMediaStorage() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
blossom: { enabled: !config.blossom.enabled },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
blossom_enabled: toInt(!toBool(current.blossom_enabled, current.plan !== "free")),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
function togglePushNotifications() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
push: { enabled: !config.push.enabled },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
push_enabled: toInt(!toBool(current.push_enabled, true)),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
function toggleLivekitSupport() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
livekit: { enabled: !config.livekit.enabled },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
livekit_enabled: toInt(!toBool(current.livekit_enabled, current.plan !== "free")),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useNavigate, useParams } from "@solidjs/router"
|
||||
import { Show, createEffect, createResource, createSignal } from "solid-js"
|
||||
import { adminGetRelay, adminUpdateRelay, type RelayConfig } from "../../lib/api"
|
||||
import { adminGetRelay, adminUpdateRelay } from "../../lib/api"
|
||||
import RelayForm from "../../components/RelayForm"
|
||||
import { slugify } from "../../lib/slugify"
|
||||
import BackLink from "../../components/BackLink"
|
||||
@@ -8,15 +8,6 @@ import PageContainer from "../../components/PageContainer"
|
||||
import ResourceState from "../../components/ResourceState"
|
||||
import useMinLoading from "../../components/useMinLoading"
|
||||
|
||||
const DEFAULT_CONFIG: RelayConfig = {
|
||||
policy: { public_join: false, strip_signatures: false },
|
||||
groups: { enabled: false, auto_join: false },
|
||||
management: { enabled: false },
|
||||
blossom: { enabled: false },
|
||||
livekit: { enabled: false },
|
||||
push: { enabled: false },
|
||||
}
|
||||
|
||||
export default function AdminRelayEdit() {
|
||||
const navigate = useNavigate()
|
||||
const params = useParams()
|
||||
@@ -34,10 +25,10 @@ export default function AdminRelayEdit() {
|
||||
createEffect(() => {
|
||||
const data = relay()
|
||||
if (!data) return
|
||||
setName(data.name)
|
||||
setName(data.info_name)
|
||||
setSubdomain(data.subdomain)
|
||||
setIcon(data.icon)
|
||||
setDescription(data.description)
|
||||
setIcon(data.info_icon)
|
||||
setDescription(data.info_description)
|
||||
})
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
@@ -46,11 +37,10 @@ export default function AdminRelayEdit() {
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await adminUpdateRelay(relayId(), {
|
||||
name: name().trim(),
|
||||
subdomain: slugify(subdomain()),
|
||||
icon: icon().trim(),
|
||||
description: description().trim(),
|
||||
config: relay()?.config ?? DEFAULT_CONFIG,
|
||||
info_name: name().trim(),
|
||||
info_icon: icon().trim(),
|
||||
info_description: description().trim(),
|
||||
})
|
||||
navigate(`/admin/relays/${relayId()}`)
|
||||
} catch (e) {
|
||||
|
||||
@@ -18,7 +18,7 @@ export default function AdminRelayList() {
|
||||
if (!q) return list
|
||||
|
||||
return new Fuse(list, {
|
||||
keys: ["name", "subdomain", "tenant"],
|
||||
keys: ["info_name", "subdomain", "tenant"],
|
||||
threshold: 0.35,
|
||||
ignoreLocation: true,
|
||||
}).search(q).map((result) => result.item)
|
||||
@@ -60,7 +60,7 @@ export default function AdminRelayList() {
|
||||
<A href={`/admin/relays/${relay.id}`} class="block border border-gray-200 rounded-lg p-4 bg-white hover:border-gray-300">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div>
|
||||
<p class="font-medium text-gray-900">{relay.name}</p>
|
||||
<p class="font-medium text-gray-900">{relay.info_name || relay.subdomain}</p>
|
||||
<p class="text-xs text-gray-500">{relay.subdomain}.spaces.coracle.social</p>
|
||||
<p class="text-xs text-gray-500 break-all mt-1">Tenant: {relay.tenant}</p>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useParams, A } from "@solidjs/router"
|
||||
import { createResource, createSignal, For, Show } from "solid-js"
|
||||
import { adminGetTenant, adminUpdateTenantStatus } from "../../lib/api"
|
||||
import { createResource, For, Show } from "solid-js"
|
||||
import { adminGetTenant } from "../../lib/api"
|
||||
import BackLink from "../../components/BackLink"
|
||||
import PageContainer from "../../components/PageContainer"
|
||||
import ResourceState from "../../components/ResourceState"
|
||||
@@ -9,25 +9,9 @@ import useMinLoading from "../../components/useMinLoading"
|
||||
export default function AdminTenantDetail() {
|
||||
const params = useParams()
|
||||
const tenantId = () => params.id ?? ""
|
||||
const [detail, { refetch }] = createResource(tenantId, adminGetTenant)
|
||||
const [busy, setBusy] = createSignal(false)
|
||||
const [error, setError] = createSignal("")
|
||||
const [detail] = createResource(tenantId, adminGetTenant)
|
||||
const loading = useMinLoading(() => detail.loading)
|
||||
|
||||
async function setStatus(status: string) {
|
||||
if (busy()) return
|
||||
setBusy(true)
|
||||
setError("")
|
||||
try {
|
||||
await adminUpdateTenantStatus(tenantId(), status)
|
||||
await refetch()
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "Failed to update tenant")
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<BackLink href="/admin/tenants" label="Tenants" />
|
||||
@@ -49,24 +33,8 @@ export default function AdminTenantDetail() {
|
||||
{(d) => (
|
||||
<div class="space-y-3">
|
||||
<p class="text-sm text-gray-700">
|
||||
Current: <span class="font-medium uppercase tracking-wide">{d().tenant.status}</span>
|
||||
Current: <span class="font-medium uppercase tracking-wide">tenant</span>
|
||||
</p>
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
class="py-2 px-4 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 disabled:opacity-50"
|
||||
onClick={() => void setStatus("active")}
|
||||
disabled={busy()}
|
||||
>
|
||||
Activate
|
||||
</button>
|
||||
<button
|
||||
class="py-2 px-4 border border-red-300 text-red-600 rounded-lg hover:bg-red-50 disabled:opacity-50"
|
||||
onClick={() => void setStatus("deactivated")}
|
||||
disabled={busy()}
|
||||
>
|
||||
Deactivate
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
@@ -82,7 +50,7 @@ export default function AdminTenantDetail() {
|
||||
<A href={`/admin/relays/${relay.id}`} class="block rounded-lg border border-gray-200 p-3 hover:border-gray-300">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<div>
|
||||
<p class="font-medium text-gray-900">{relay.name}</p>
|
||||
<p class="font-medium text-gray-900">{relay.info_name || relay.subdomain}</p>
|
||||
<p class="text-xs text-gray-500">{relay.subdomain}.spaces.coracle.social</p>
|
||||
</div>
|
||||
<span class="text-xs uppercase tracking-wide text-gray-500">{relay.status}</span>
|
||||
@@ -94,9 +62,6 @@ export default function AdminTenantDetail() {
|
||||
</ul>
|
||||
</Show>
|
||||
</section>
|
||||
<Show when={error()}>
|
||||
<p class="text-sm text-red-600">{error()}</p>
|
||||
</Show>
|
||||
</div>
|
||||
</Show>
|
||||
</PageContainer>
|
||||
|
||||
@@ -115,7 +115,7 @@ export default function AdminTenantList() {
|
||||
<p class="mt-1 text-xs text-gray-500 break-all">{tenant.pubkey}</p>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-xs uppercase tracking-wide text-gray-500">{tenant.status}</p>
|
||||
<p class="text-xs uppercase tracking-wide text-gray-500">tenant</p>
|
||||
</div>
|
||||
</A>
|
||||
</li>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useParams } from "@solidjs/router"
|
||||
import { createMemo, createResource, createSignal, Show } from "solid-js"
|
||||
import { deactivateTenantRelay, getRelayMemberCount, getTenantRelay, updateTenantRelay, updateTenantRelayPlan, type RelayConfig } from "../../lib/api"
|
||||
import { deactivateTenantRelay, getRelayMemberCount, getTenantRelay, updateTenantRelay, updateTenantRelayPlan, type Relay } from "../../lib/api"
|
||||
import type { RelayPlanId } from "../../lib/relayPlans"
|
||||
import BackLink from "../../components/BackLink"
|
||||
import PageContainer from "../../components/PageContainer"
|
||||
@@ -35,114 +35,100 @@ export default function RelayDetail() {
|
||||
}
|
||||
}
|
||||
|
||||
function withDefaults(config?: RelayConfig): RelayConfig {
|
||||
return {
|
||||
policy: {
|
||||
public_join: config?.policy.public_join ?? false,
|
||||
strip_signatures: config?.policy.strip_signatures ?? false,
|
||||
},
|
||||
groups: {
|
||||
enabled: config?.groups.enabled ?? true,
|
||||
auto_join: config?.groups.auto_join ?? true,
|
||||
},
|
||||
management: {
|
||||
enabled: config?.management.enabled ?? true,
|
||||
},
|
||||
blossom: {
|
||||
enabled: config?.blossom.enabled ?? (relay()?.plan !== "free"),
|
||||
},
|
||||
livekit: {
|
||||
enabled: config?.livekit.enabled ?? (relay()?.plan !== "free"),
|
||||
},
|
||||
push: {
|
||||
enabled: config?.push.enabled ?? true,
|
||||
},
|
||||
}
|
||||
function toBool(value: number | undefined, fallback: boolean): boolean {
|
||||
if (value === 0) return false
|
||||
if (value === 1) return true
|
||||
return fallback
|
||||
}
|
||||
|
||||
async function updateFlags(nextConfig: RelayConfig, previousConfig: RelayConfig) {
|
||||
function toInt(value: boolean): number {
|
||||
return value ? 1 : 0
|
||||
}
|
||||
|
||||
async function updateRelay(next: Relay, previous: Relay) {
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
|
||||
setError("")
|
||||
mutate({ ...current, config: nextConfig })
|
||||
mutate(next)
|
||||
|
||||
try {
|
||||
await updateTenantRelay(relayId(), {
|
||||
name: current.name,
|
||||
subdomain: current.subdomain,
|
||||
icon: current.icon,
|
||||
description: current.description,
|
||||
config: nextConfig,
|
||||
})
|
||||
await updateTenantRelay(relayId(), next)
|
||||
await refetch()
|
||||
} catch (e) {
|
||||
mutate({ ...current, config: previousConfig })
|
||||
mutate(previous)
|
||||
setError(e instanceof Error ? e.message : "Failed to update relay settings")
|
||||
}
|
||||
}
|
||||
|
||||
function togglePublicJoin() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
policy: { ...config.policy, public_join: !config.policy.public_join },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
policy_public_join: toInt(!toBool(current.policy_public_join, false)),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
function toggleStripSignatures() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
policy: { ...config.policy, strip_signatures: !config.policy.strip_signatures },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
policy_strip_signatures: toInt(!toBool(current.policy_strip_signatures, false)),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
function toggleGroups() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
groups: { ...config.groups, enabled: !config.groups.enabled },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
groups_enabled: toInt(!toBool(current.groups_enabled, true)),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
function toggleManagement() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
management: { enabled: !config.management.enabled },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
management_enabled: toInt(!toBool(current.management_enabled, true)),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
function toggleMediaStorage() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
blossom: { enabled: !config.blossom.enabled },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
blossom_enabled: toInt(!toBool(current.blossom_enabled, current.plan !== "free")),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
function togglePushNotifications() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
push: { enabled: !config.push.enabled },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
push_enabled: toInt(!toBool(current.push_enabled, true)),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
function toggleLivekitSupport() {
|
||||
const config = withDefaults(relay()?.config)
|
||||
const nextConfig = {
|
||||
...config,
|
||||
livekit: { enabled: !config.livekit.enabled },
|
||||
const current = relay()
|
||||
if (!current) return
|
||||
const next = {
|
||||
...current,
|
||||
livekit_enabled: toInt(!toBool(current.livekit_enabled, current.plan !== "free")),
|
||||
}
|
||||
void updateFlags(nextConfig, config)
|
||||
void updateRelay(next, current)
|
||||
}
|
||||
|
||||
async function handleUpdatePlan(plan: RelayPlanId) {
|
||||
@@ -152,13 +138,14 @@ export default function RelayDetail() {
|
||||
const previous = current
|
||||
setError("")
|
||||
|
||||
const nextConfig = withDefaults(current.config)
|
||||
const next = { ...current }
|
||||
if (plan === "free") {
|
||||
nextConfig.blossom = { enabled: false }
|
||||
nextConfig.livekit = { enabled: false }
|
||||
next.blossom_enabled = 0
|
||||
next.livekit_enabled = 0
|
||||
}
|
||||
|
||||
mutate({ ...current, plan, config: nextConfig })
|
||||
next.plan = plan
|
||||
mutate(next)
|
||||
|
||||
try {
|
||||
await updateTenantRelayPlan(relayId(), plan)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useNavigate, useParams } from "@solidjs/router"
|
||||
import { Show, createEffect, createResource, createSignal } from "solid-js"
|
||||
import { getTenantRelay, updateTenantRelay, type RelayConfig } from "../../lib/api"
|
||||
import { getTenantRelay, updateTenantRelay } from "../../lib/api"
|
||||
import RelayForm from "../../components/RelayForm"
|
||||
import { slugify } from "../../lib/slugify"
|
||||
import BackLink from "../../components/BackLink"
|
||||
@@ -8,15 +8,6 @@ import PageContainer from "../../components/PageContainer"
|
||||
import ResourceState from "../../components/ResourceState"
|
||||
import useMinLoading from "../../components/useMinLoading"
|
||||
|
||||
const DEFAULT_CONFIG: RelayConfig = {
|
||||
policy: { public_join: false, strip_signatures: false },
|
||||
groups: { enabled: false, auto_join: false },
|
||||
management: { enabled: false },
|
||||
blossom: { enabled: false },
|
||||
livekit: { enabled: false },
|
||||
push: { enabled: false },
|
||||
}
|
||||
|
||||
export default function RelayEdit() {
|
||||
const navigate = useNavigate()
|
||||
const params = useParams()
|
||||
@@ -34,10 +25,10 @@ export default function RelayEdit() {
|
||||
createEffect(() => {
|
||||
const data = relay()
|
||||
if (!data) return
|
||||
setName(data.name)
|
||||
setName(data.info_name)
|
||||
setSubdomain(data.subdomain)
|
||||
setIcon(data.icon)
|
||||
setDescription(data.description)
|
||||
setIcon(data.info_icon)
|
||||
setDescription(data.info_description)
|
||||
})
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
@@ -46,11 +37,10 @@ export default function RelayEdit() {
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await updateTenantRelay(relayId(), {
|
||||
name: name().trim(),
|
||||
subdomain: slugify(subdomain()),
|
||||
icon: icon().trim(),
|
||||
description: description().trim(),
|
||||
config: relay()?.config ?? DEFAULT_CONFIG,
|
||||
info_name: name().trim(),
|
||||
info_icon: icon().trim(),
|
||||
info_description: description().trim(),
|
||||
})
|
||||
navigate(`/relays/${relayId()}`)
|
||||
} catch (e) {
|
||||
|
||||
@@ -17,7 +17,7 @@ export default function RelayList() {
|
||||
const q = query().trim()
|
||||
const searched = q
|
||||
? new Fuse(list, {
|
||||
keys: ["name", "subdomain"],
|
||||
keys: ["info_name", "subdomain"],
|
||||
threshold: 0.35,
|
||||
ignoreLocation: true,
|
||||
}).search(q).map((result) => result.item)
|
||||
@@ -90,7 +90,7 @@ export default function RelayList() {
|
||||
>
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<p class="font-medium text-gray-900">{relay.name}</p>
|
||||
<p class="font-medium text-gray-900">{relay.info_name || relay.subdomain}</p>
|
||||
<p class="text-sm text-gray-500">https://{relay.subdomain}.spaces.coracle.social</p>
|
||||
</div>
|
||||
<p class="text-xs uppercase tracking-wide text-gray-500">{relay.status}</p>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Show, createSignal } from "solid-js"
|
||||
import { useNavigate } from "@solidjs/router"
|
||||
import { createTenantRelay, type RelayConfig } from "../../lib/api"
|
||||
import { createTenantRelay } from "../../lib/api"
|
||||
import { slugify } from "../../lib/slugify"
|
||||
|
||||
const PLANS = [
|
||||
@@ -11,15 +11,6 @@ const PLANS = [
|
||||
|
||||
type PlanId = (typeof PLANS)[number]["id"]
|
||||
|
||||
const DEFAULT_CONFIG: RelayConfig = {
|
||||
policy: { public_join: false, strip_signatures: false },
|
||||
groups: { enabled: true, auto_join: true },
|
||||
management: { enabled: true },
|
||||
blossom: { enabled: false },
|
||||
livekit: { enabled: false },
|
||||
push: { enabled: true },
|
||||
}
|
||||
|
||||
export default function RelayNew() {
|
||||
const navigate = useNavigate()
|
||||
const [name, setName] = createSignal("")
|
||||
@@ -44,16 +35,18 @@ export default function RelayNew() {
|
||||
|
||||
try {
|
||||
const relay = await createTenantRelay({
|
||||
name: name().trim(),
|
||||
subdomain: slugify(subdomain()),
|
||||
icon: icon().trim(),
|
||||
description: description().trim(),
|
||||
plan: plan(),
|
||||
config: {
|
||||
...DEFAULT_CONFIG,
|
||||
blossom: { enabled: plan() !== "free" },
|
||||
livekit: { enabled: plan() !== "free" },
|
||||
},
|
||||
info_name: name().trim(),
|
||||
info_icon: icon().trim(),
|
||||
info_description: description().trim(),
|
||||
policy_public_join: 0,
|
||||
policy_strip_signatures: 0,
|
||||
groups_enabled: 1,
|
||||
management_enabled: 1,
|
||||
blossom_enabled: plan() === "free" ? 0 : 1,
|
||||
livekit_enabled: plan() === "free" ? 0 : 1,
|
||||
push_enabled: 1,
|
||||
})
|
||||
navigate(`/relays/${relay.id}`)
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user