@@ -6,6 +6,7 @@ import * as arrowJSFFI from "arrow-js-ffi";
66import { DataArrays , DataRow , nullDataArrays , schema } from "./datatypes" ;
77import { Dispatch , RefObject , SetStateAction } from "react" ;
88import { RESPONSE_LIMIT_DEFAULT } from "next/dist/server/api-utils" ;
9+ import { Table } from "apache-arrow" ;
910
1011// TODO(jack): this setup is kinda bad cuz every time the function is called it
1112// tried all URLs, including bad ones, which cause Network Errors to be thrown
@@ -66,26 +67,36 @@ async function tryFetch(path: string, production: boolean) {
6667 }
6768}
6869
69- export async function availableRecordings ( production : boolean ) : Promise < string [ ] | null > {
70- // console.log(process.env.NODE_ENV);
71- return tryFetch ( "/api/available-recordings" , production ) . then ( ( response ) =>
72- response != null ? response . json ( ) : null
70+ export async function getDBCForRecording (
71+ filepath : string ,
72+ production : boolean ,
73+ ) : Promise < string [ ] | null > {
74+ return tryFetch ( `/api/get-dbc-for-recording/${ filepath } ` , production ) . then ( ( resp ) =>
75+ resp ?. json ( ) ,
7376 ) ;
7477}
7578
76- export async function getRecording ( filepath : string ) {
79+ export async function availableRecordings ( production : boolean ) : Promise < string [ ] | null > {
80+ return tryFetch ( "/api/available-recordings" , production ) . then ( ( resp ) => resp ?. json ( ) ) ;
81+ }
82+
83+ export async function getRecording ( filepath : string ) : Promise < Table < DataRow > | undefined > {
7784 // Initializes WebAssembly memory for parquet-wasm, and gets a reference to it
7885 await wasmInit ( ) ;
7986 const WASM_MEMORY = wasmMemory ( ) ;
8087
81- const parquet = await tryFetch ( `/api/get-recording/${ filepath } ` , true ) . then ( ( resp ) =>
82- resp ? resp . arrayBuffer ( ) : null
83- ) ;
84- const arrowTableWasm = readParquet ( new Uint8Array ( parquet ! ) ) . intoFFI ( ) ;
88+ const resp = await tryFetch ( `/api/get-recording/${ filepath } ` , false )
89+ const arrayBuffer = await resp ?. arrayBuffer ( ) ;
90+ if ( ! arrayBuffer ) {
91+ console . error ( "Response is not a valid ArrayBuffer!" ) ;
92+ return ;
93+ }
94+
95+ const arrowTableWasm = readParquet ( new Uint8Array ( arrayBuffer ) ) . intoFFI ( ) ;
8596 const arrowTable = arrowJSFFI . parseTable < DataRow > (
8697 WASM_MEMORY . buffer ,
8798 arrowTableWasm . arrayAddrs ( ) ,
88- arrowTableWasm . schemaAddr ( )
99+ arrowTableWasm . schemaAddr ( ) ,
89100 ) ;
90101
91102 // Free arrow table in wasm memory
@@ -105,7 +116,7 @@ export async function initRecordingSource(
105116 data : RefObject < DataArrays > ,
106117 dataTrimmed : RefObject < DataArrays > ,
107118 setNumRows : Dispatch < SetStateAction < number > > ,
108- viewLength : number
119+ viewLength : number ,
109120) {
110121 const arrowTable = ( await getRecording ( filepath ) ) ! ;
111122
0 commit comments