119 lines
4.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { getRequestOrigin } from "@/lib/request-origin";
import { buildSubscriptionUrl, getDefaultClashTemplate } from "@/lib/subscription";
import {
getAdminMirrorUser,
getSubscriptionSettings,
listSubscriptionNodes,
} from "@/lib/store";
import { saveSubscriptionSettingsAction } from "./actions";
import { ProxyGroupEditor } from "./proxy-group-editor";
export default async function AdminSubscriptionsPage() {
const [settings, adminUser, nodes, origin] = await Promise.all([
getSubscriptionSettings(),
getAdminMirrorUser(),
listSubscriptionNodes(),
getRequestOrigin(),
]);
const proxyGroupNodes = nodes.map((node) => ({
slug: node.slug,
label: node.client_name || node.name,
meta:
node.client_name && node.client_name !== node.name
? `${node.name} / ${node.slug}`
: node.slug,
}));
return (
<main className="page-stack">
<section className="hero-panel">
<div className="hero-copy">
<span className="eyebrow">SUBSCRIPTIONS</span>
<h2></h2>
<p className="page-lede">
Clash
</p>
<div className="badge-row">
<span className="status-pill status-pill--ok"> proxies</span>
<span className="status-pill status-pill--ink"> {settings.proxyGroups.length}</span>
</div>
</div>
<div className="hero-aside">
<div className="stat-tile">
<span></span>
<strong>{nodes.length}</strong>
</div>
<div className="stat-tile">
<span></span>
<strong>{settings.profileName}</strong>
</div>
</div>
</section>
<section className="panel-card">
<div className="section-title">
<h3></h3>
</div>
{adminUser?.subscription_token ? (
<div className="instruction-block no-margin">
<p className="muted mono break-all">
{buildSubscriptionUrl(adminUser.subscription_token, origin)}
</p>
</div>
) : (
<p className="muted"></p>
)}
</section>
<section className="panel-card">
<div className="section-title section-title--top">
<div className="stack-tight">
<h3>Proxy Groups</h3>
<p className="muted"> Clash </p>
</div>
</div>
<div className="stack-lg">
{settings.proxyGroups.map((group) => (
<ProxyGroupEditor key={group.id} group={group} nodes={proxyGroupNodes} />
))}
<ProxyGroupEditor key={`new-${settings.proxyGroups.length}`} nodes={proxyGroupNodes} />
</div>
</section>
<section className="panel-card">
<div className="section-title">
<h3>Clash </h3>
</div>
<form action={saveSubscriptionSettingsAction} className="stack-lg">
<label className="field">
<span> / </span>
<input name="profile_name" defaultValue={settings.profileName} required />
</label>
<label className="field">
<span></span>
<textarea
name="template"
rows={18}
defaultValue={settings.template || getDefaultClashTemplate()}
/>
</label>
<label className="field">
<span> proxy-groups YAML</span>
<textarea
name="extra_proxy_groups"
rows={12}
defaultValue={settings.extraProxyGroups}
placeholder={` - name: ChatGPT\n type: select\n proxies: ["US 01 - hy2", "JP 01 - hy2"]`}
/>
</label>
<button className="primary-button" type="submit">
</button>
</form>
</section>
</main>
);
}