2024-08-29 16:59:25 +08:00
|
|
|
import path from "node:path";
|
|
|
|
import { JSONFilePreset } from "lowdb/node";
|
|
|
|
import { app } from "electron";
|
2024-09-02 14:18:06 +08:00
|
|
|
import { StructuredMetadata } from "./dicom";
|
2024-09-06 14:27:41 +08:00
|
|
|
import { merge } from "lodash";
|
2024-08-29 16:59:25 +08:00
|
|
|
|
2024-09-06 14:27:41 +08:00
|
|
|
export interface ICreateDatabase {
|
2024-09-02 14:18:06 +08:00
|
|
|
name: string;
|
|
|
|
}
|
|
|
|
|
2024-09-06 14:27:41 +08:00
|
|
|
export type SeriesTableType = StructuredMetadata & {
|
2024-09-02 14:18:06 +08:00
|
|
|
createTime?: number;
|
|
|
|
updateTime?: number;
|
|
|
|
};
|
2024-08-29 16:59:25 +08:00
|
|
|
|
2024-09-06 14:27:41 +08:00
|
|
|
export type SettingTableType = {
|
|
|
|
/**
|
|
|
|
* 推理硬件默认是GPU、可选CPU、NPU
|
|
|
|
* @default GPU
|
|
|
|
*/
|
|
|
|
inferDevice: string;
|
|
|
|
/**
|
|
|
|
* 用户文件位置
|
|
|
|
* @description 用于存储算法输出、应用生成的产物的路径
|
|
|
|
*/
|
|
|
|
outputPath: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export interface DbTable {
|
2024-09-02 14:18:06 +08:00
|
|
|
series: SeriesTableType[];
|
2024-09-06 14:27:41 +08:00
|
|
|
setting: SettingTableType;
|
2024-09-02 14:18:06 +08:00
|
|
|
}
|
2024-08-29 16:59:25 +08:00
|
|
|
|
2024-09-06 14:27:41 +08:00
|
|
|
const defaultTable: DbTable = {
|
|
|
|
series: [],
|
|
|
|
setting: {
|
|
|
|
inferDevice: "gpu",
|
|
|
|
outputPath: path.join(app.getPath("userData"), "output"),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-09-29 17:01:21 +08:00
|
|
|
export let db: any;
|
2024-08-29 16:59:25 +08:00
|
|
|
|
2024-09-02 14:18:06 +08:00
|
|
|
export const createDatabase = async (config: ICreateDatabase) => {
|
|
|
|
const { name } = config;
|
2024-09-06 14:27:41 +08:00
|
|
|
const dbJsonFilePath = path.join(app.getPath("userData"), name);
|
|
|
|
db = await JSONFilePreset(dbJsonFilePath, defaultTable);
|
|
|
|
// 表结构更新,增量合并
|
|
|
|
db.data = merge({}, defaultTable, db.data);
|
|
|
|
await db.write();
|
2024-08-29 16:59:25 +08:00
|
|
|
};
|