(
jsonFilePath: string,
sqliteFilePath: string,
preventNavigation?: boolean
)
| 285 | } |
| 286 | |
| 287 | function jsonParser( |
| 288 | jsonFilePath: string, |
| 289 | sqliteFilePath: string, |
| 290 | preventNavigation?: boolean |
| 291 | ) { |
| 292 | if (!sqliteFilePath || !jsonFilePath) { |
| 293 | console.error("Sqlite or json file path isn't valid:", sqliteFilePath); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | startImport(); |
| 298 | |
| 299 | // Create a new database when importing a json file (Delete any existing data in the sqlite file) |
| 300 | const newWorkbenchDB = new WorkbenchDB({ |
| 301 | dbName: "workbench_db", |
| 302 | dbStoragePath: sqliteFilePath, |
| 303 | deleteExisting: true, |
| 304 | }); |
| 305 | |
| 306 | newWorkbenchDB.sync |
| 307 | .then(() => |
| 308 | newWorkbenchDB.addFromJson(jsonFilePath, (progress: number) => { |
| 309 | updateLoadingStatus(progress); |
| 310 | }) |
| 311 | ) |
| 312 | .then(() => { |
| 313 | console.log("JSON parsing completed"); |
| 314 | |
| 315 | AddEntry({ |
| 316 | json_path: jsonFilePath, |
| 317 | sqlite_path: sqliteFilePath, |
| 318 | opened_at: moment().format(), |
| 319 | }); |
| 320 | |
| 321 | newWorkbenchDB.sync |
| 322 | .then((db) => db.File.findOne({ where: { parent: "#" } })) |
| 323 | .then(async (root) => { |
| 324 | if (!root) { |
| 325 | console.error("Root:", root); |
| 326 | throw new Error("Root path not found !!!!"); |
| 327 | } |
| 328 | |
| 329 | const defaultPath = root.getDataValue("path"); |
| 330 | |
| 331 | await updateWorkbenchDB(newWorkbenchDB, sqliteFilePath); |
| 332 | |
| 333 | if (defaultPath) { |
| 334 | updateCurrentPath( |
| 335 | defaultPath, |
| 336 | root.getDataValue("type") as PathType |
| 337 | ); |
| 338 | } |
| 339 | |
| 340 | // Update window title |
| 341 | const newlyImportedFileName = jsonFilePath |
| 342 | .split("\\") |
| 343 | .pop() |
| 344 | .split("/") |
no test coverage detected