@@ -11,6 +11,7 @@ import { useSidebarRecents } from "@/features/recent/context/sidebar-recents-con
1111import { useSettingsChatPreferences } from "@/features/settings/hooks/use-settings-chat-preferences" ;
1212import { resolveAccessToken } from "@/shared/auth/resolve-access-token" ;
1313import { runBulkActionInChunks } from "@/shared/lib/bulk-action" ;
14+ import { downloadBlob , readExportManifest } from "@/shared/lib/export-download" ;
1415import {
1516 exportConversation ,
1617 exportAllConversations ,
@@ -318,36 +319,15 @@ export function useRecentPage() {
318319 const token = await resolveAccessToken ( ) ;
319320 if ( ! token ) return ;
320321 const blob = await exportAllConversations ( token ) ;
321- const text = await blob . text ( ) ;
322- const lines = text . trimEnd ( ) . split ( "\n" ) ;
323- const lastLine = lines [ lines . length - 1 ] ;
324- let manifest : { _type ?: string ; complete ?: boolean ; exported ?: number ; failed ?: number } | null = null ;
325- try {
326- const parsed = JSON . parse ( lastLine ) as Record < string , unknown > ;
327- if ( parsed . _type === "export_manifest" ) {
328- manifest = parsed as typeof manifest ;
329- }
330- } catch {
331- // not valid JSON — treat as no manifest
332- }
322+ const manifest = await readExportManifest ( blob ) ;
323+ downloadBlob ( blob , `my-conversations-${ new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) } .jsonl` ) ;
333324
334- const downloadBlob = new Blob ( [ text ] , { type : "application/x-ndjson" } ) ;
335- const url = URL . createObjectURL ( downloadBlob ) ;
336- const link = document . createElement ( "a" ) ;
337- link . href = url ;
338- link . download = `my-conversations-${ new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) } .jsonl` ;
339- link . rel = "noopener" ;
340- document . body . appendChild ( link ) ;
341- link . click ( ) ;
342- link . remove ( ) ;
343- URL . revokeObjectURL ( url ) ;
344-
345- if ( manifest && ! manifest . complete ) {
346- toast . warning ( t ( "toast.exportAllPartial" , { exported : manifest . exported ?? 0 , failed : manifest . failed ?? 0 } ) ) ;
347- } else if ( manifest && ( manifest . failed ?? 0 ) > 0 ) {
325+ if ( manifest && ( ! manifest . complete || ( manifest . failed ?? 0 ) > 0 ) ) {
348326 toast . warning ( t ( "toast.exportAllPartial" , { exported : manifest . exported ?? 0 , failed : manifest . failed ?? 0 } ) ) ;
327+ } else if ( ! manifest ) {
328+ toast . success ( t ( "toast.exportAllDownloaded" ) ) ;
349329 } else {
350- toast . success ( t ( "toast.exportAllSuccess" , { count : manifest ? .exported ?? lines . length } ) ) ;
330+ toast . success ( t ( "toast.exportAllSuccess" , { count : manifest . exported ?? 0 } ) ) ;
351331 }
352332 } catch {
353333 toast . error ( t ( "toast.exportAllFailed" ) ) ;
0 commit comments