feat: uuid for sub link

This commit is contained in:
2026-03-31 14:25:24 +08:00
parent 21c91fc213
commit ec2c5bab80
4 changed files with 68 additions and 22 deletions

View File

@@ -5,8 +5,25 @@ export default function Output() {
const [preview, setPreview] = useState('');
const [loading, setLoading] = useState(false);
const [copied, setCopied] = useState(false);
const [surgeToken, setSurgeToken] = useState('');
const surgeUrl = `${window.location.origin}/surge`;
const surgeUrl = surgeToken ? `${window.location.origin}/surge/${surgeToken}` : '';
const loadToken = async () => {
try {
const data = await configApi.getSurgeToken();
setSurgeToken(data.token || '');
} catch {}
};
const handleRegenerate = async () => {
if (!confirm('重新生成后旧的订阅链接将失效Surge 客户端需要更新订阅地址。确定继续?')) return;
try {
const data = await configApi.regenerateSurgeToken();
setSurgeToken(data.token);
loadPreview();
} catch {}
};
const loadPreview = async () => {
setLoading(true);
@@ -20,7 +37,10 @@ export default function Output() {
}
};
useEffect(() => { loadPreview(); }, []);
useEffect(() => {
loadToken();
loadPreview();
}, []);
const handleCopy = () => {
navigator.clipboard.writeText(surgeUrl);
@@ -58,12 +78,18 @@ export default function Output() {
fontSize: 13,
color: 'var(--accent)',
userSelect: 'all',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}>
{surgeUrl}
{surgeUrl || '加载中...'}
</code>
<button className="small" onClick={handleCopy}>
<button className="small" onClick={handleCopy} disabled={!surgeUrl}>
{copied ? '已复制' : '复制'}
</button>
<button className="small" onClick={handleRegenerate} disabled={!surgeUrl}>
</button>
</div>
</div>