feat: add fission package download
This commit is contained in:
@@ -56,6 +56,7 @@ export default function FissionNotesPage() {
|
||||
const fissionId = Number(params?.id);
|
||||
const [data, setData] = useState<NotesResponse | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [downloading, setDownloading] = useState(false);
|
||||
|
||||
const fetchNotes = useCallback(async () => {
|
||||
setError(null);
|
||||
@@ -86,6 +87,27 @@ export default function FissionNotesPage() {
|
||||
setTimeout(tick, 8000);
|
||||
}, [fissionId, fetchNotes]);
|
||||
|
||||
const downloadPackage = useCallback(async () => {
|
||||
if (!fissionId || downloading) return;
|
||||
setDownloading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const blob = await api.getBlob(`/api/v1/fission/${fissionId}/download`);
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `fission-${fissionId}.zip`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} catch {
|
||||
setError('下载裂变包失败,请稍后重试');
|
||||
} finally {
|
||||
setDownloading(false);
|
||||
}
|
||||
}, [fissionId, downloading]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6 p-6 max-w-4xl">
|
||||
<div className="flex items-center justify-between">
|
||||
@@ -97,9 +119,19 @@ export default function FissionNotesPage() {
|
||||
一个爆款裂变出的多套差异化完整笔记,可分发给不同达人。
|
||||
</p>
|
||||
</div>
|
||||
<Link href="/fission" className="text-sm text-text-secondary underline">
|
||||
返回裂变
|
||||
</Link>
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={downloadPackage}
|
||||
disabled={!data || data.notes.length === 0 || downloading}
|
||||
className="rounded-lg bg-brand-orange px-4 py-2 text-sm font-medium text-white disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
{downloading ? '下载中…' : '下载裂变包'}
|
||||
</button>
|
||||
<Link href="/fission" className="text-sm text-text-secondary underline">
|
||||
返回裂变
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
|
||||
Reference in New Issue
Block a user