You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
980 B
35 lines
980 B
import Dexie, { type Table } from "dexie";
|
|
import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon";
|
|
|
|
import { AppString } from "@/constants/app";
|
|
import { AppTable } from "../constants/table";
|
|
import { Field } from "@/constants/model";
|
|
import { IDBAccount } from "@/models/Account";
|
|
|
|
export class DexieWrapper extends Dexie {
|
|
[AppTable.ACCOUNTS]!: Table<IDBAccount>;
|
|
|
|
constructor(name: string, secret: string) {
|
|
super(name, { autoOpen: true });
|
|
encrypted(this, { secretKey: secret });
|
|
this.version(1).stores({
|
|
[AppTable.ACCOUNTS]: `#&${Field.ID}, $${Field.IDENTITY}`,
|
|
});
|
|
}
|
|
}
|
|
|
|
const secret =
|
|
localStorage.getItem("secret") || Encryption.createRandomEncryptionKey();
|
|
|
|
if (localStorage.getItem("secret") == null) {
|
|
localStorage.setItem("secret", secret);
|
|
}
|
|
|
|
console.log("secret", secret);
|
|
/**
|
|
* Preconfigured DexieWrapper
|
|
*/
|
|
export const dexieWrapper = new DexieWrapper(
|
|
`${AppString.APP_NAME} v${AppString.VERSION}`,
|
|
secret
|
|
);
|
|
|