Skip to content

Commit cfc26f4

Browse files
feat: browser-only tar.gz extraction, removed server API
1 parent a24ed3b commit cfc26f4

2 files changed

Lines changed: 31 additions & 250 deletions

File tree

api/extract.ts

Lines changed: 0 additions & 189 deletions
This file was deleted.

src/App.tsx

Lines changed: 31 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -299,70 +299,40 @@ const App: React.FC<{ router?: boolean }> = ({ router = true }) => {
299299

300300
// Reusable function to fetch and extract archive
301301
const fetchAndExtractArchive = async (url: string): Promise<UploadContent | null> => {
302-
try {
303-
// Try browser-side extraction first (works for same-origin or CORS-enabled URLs)
304-
try {
305-
console.log('Trying browser-side extraction for:', url);
306-
const response = await fetch(url);
307-
if (response.ok) {
308-
const arrayBuffer = await response.arrayBuffer();
309-
const gzippedData = new Uint8Array(arrayBuffer);
310-
311-
let decompressed: Uint8Array;
312-
try {
313-
decompressed = pako.ungzip(gzippedData);
314-
} catch {
315-
decompressed = pako.inflate(gzippedData);
316-
}
317-
318-
const { jsonlContent, reportContent } = extractFromTar(decompressed);
319-
320-
if (jsonlContent) {
321-
console.log('Successfully extracted in browser');
322-
return {
323-
content: {
324-
fileType: 'full_archive' as const,
325-
jsonlContent,
326-
reportContent
327-
}
328-
};
329-
}
330-
}
331-
} catch (e) {
332-
console.log('Browser extraction failed, falling back to API:', e);
333-
}
334-
335-
// Fall back to serverless API (bypasses CORS)
336-
const apiUrl = `/api/extract?url=${encodeURIComponent(url)}`;
337-
console.log('Fetching archive via API:', apiUrl);
338-
339-
const response = await fetch(apiUrl);
340-
341-
if (!response.ok) {
342-
const errorData = await response.json().catch(() => ({}));
343-
throw new Error(errorData.error || `Failed to extract archive: ${response.status}`);
344-
}
302+
// Extract tar.gz entirely in browser
303+
console.log('Fetching and extracting archive in browser:', url);
304+
305+
const response = await fetch(url);
306+
if (!response.ok) {
307+
throw new Error(`Failed to fetch archive: ${response.status} ${response.statusText}`);
308+
}
345309

346-
const data = await response.json();
347-
console.log('API response:', data);
310+
const arrayBuffer = await response.arrayBuffer();
311+
const gzippedData = new Uint8Array(arrayBuffer);
312+
313+
console.log('Decompressing gzip...');
314+
let decompressed: Uint8Array;
315+
try {
316+
decompressed = pako.ungzip(gzippedData);
317+
} catch {
318+
decompressed = pako.inflate(gzippedData);
319+
}
320+
321+
console.log('Extracting from tar...');
322+
const { jsonlContent, reportContent } = extractFromTar(decompressed);
323+
324+
if (!jsonlContent) {
325+
throw new Error('No JSONL content found in archive');
326+
}
348327

349-
if (!data.jsonlContent) {
350-
throw new Error('No JSONL content found in archive');
328+
console.log('Successfully extracted archive');
329+
return {
330+
content: {
331+
fileType: 'full_archive' as const,
332+
jsonlContent,
333+
reportContent
351334
}
352-
353-
console.log('Successfully extracted archive via serverless API');
354-
355-
// Create upload content from extracted data
356-
return {
357-
content: {
358-
fileType: 'full_archive' as const,
359-
jsonlContent: data.jsonlContent,
360-
reportContent: data.reportContent
361-
}
362-
};
363-
} catch (error) {
364-
throw error;
365-
}
335+
};
366336
};
367337

368338
// Function to process trajectory data based on its format

0 commit comments

Comments
 (0)