refactor: migrate src/cli/cmd/import.ts from Bun.file() to Filesystem module (#14143)
This commit is contained in:
@@ -8,6 +8,7 @@ import { SessionTable, MessageTable, PartTable } from "../../session/session.sql
|
|||||||
import { Instance } from "../../project/instance"
|
import { Instance } from "../../project/instance"
|
||||||
import { ShareNext } from "../../share/share-next"
|
import { ShareNext } from "../../share/share-next"
|
||||||
import { EOL } from "os"
|
import { EOL } from "os"
|
||||||
|
import { Filesystem } from "../../util/filesystem"
|
||||||
|
|
||||||
/** Discriminated union returned by the ShareNext API (GET /api/share/:id/data) */
|
/** Discriminated union returned by the ShareNext API (GET /api/share/:id/data) */
|
||||||
export type ShareData =
|
export type ShareData =
|
||||||
@@ -116,8 +117,7 @@ export const ImportCommand = cmd({
|
|||||||
|
|
||||||
exportData = transformed
|
exportData = transformed
|
||||||
} else {
|
} else {
|
||||||
const file = Bun.file(args.file)
|
exportData = await Filesystem.readJson<NonNullable<typeof exportData>>(args.file).catch(() => undefined)
|
||||||
exportData = await file.json().catch(() => {})
|
|
||||||
if (!exportData) {
|
if (!exportData) {
|
||||||
process.stdout.write(`File not found: ${args.file}`)
|
process.stdout.write(`File not found: ${args.file}`)
|
||||||
process.stdout.write(EOL)
|
process.stdout.write(EOL)
|
||||||
|
|||||||
Reference in New Issue
Block a user