Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add journal storage loader #732

Merged
merged 16 commits into from
Jan 16, 2024
Merged
13 changes: 10 additions & 3 deletions standalone_app/src/components/StorageLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import React, {
useRef,
useState,
} from "react"
import { loadStorage } from "../sqlite3"
import { loadSQLite3Storage } from "../sqlite3"
import { loadJournalStorage } from "../journalStorage"
import { useSetRecoilState } from "recoil"
import { studiesState } from "../state"
import {
Expand All @@ -30,7 +31,13 @@ export const StorageLoader: FC = () => {
r.addEventListener("load", () => {
const arrayBuffer = r.result as ArrayBuffer | null
if (arrayBuffer !== null) {
loadStorage(arrayBuffer, setStudies)
const header = new Uint8Array(arrayBuffer, 0, 16)
const headerString = new TextDecoder().decode(header)
if (headerString === "SQLite format 3\u0000") {
loadSQLite3Storage(arrayBuffer, setStudies)
} else {
loadJournalStorage(arrayBuffer, setStudies)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] Do you have any way to check that the file is compatible with JournalStorage? If yes, we can add "else if" to check it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, there is no "header" or special "flag" in the JournalStorage log. The only requirement for JournalStorage is a JSON line file. We can detect the format by parsing the first line of the log, but I believe this should be handled in the JournalStorage class.

}
}
})
r.readAsArrayBuffer(file)
Expand Down Expand Up @@ -108,7 +115,7 @@ export const StorageLoader: FC = () => {
<Typography
sx={{ textAlign: "center", color: theme.palette.grey.A400 }}
>
Drag your SQLite3 file here or click to browse.
Drag your SQLite3/JournalStorage file here or click to browse.
</Typography>
</CardContent>
</CardActionArea>
Expand Down
Loading
Loading