ChatGPT-Next-Web/app/utils/file.tsx
2024-07-15 20:09:21 +08:00

32 lines
720 B
TypeScript

"use client";
import { initDB } from "react-indexed-db-hook";
import { StoreKey } from "@/app/constant";
import { useIndexedDB } from "react-indexed-db-hook";
export const FileDbConfig = {
name: "@chatgpt-next-web/file",
version: 1,
objectStoresMeta: [
{
store: StoreKey.File,
storeConfig: { keyPath: "id", autoIncrement: true },
storeSchema: [
{ name: "data", keypath: "data", options: { unique: false } },
{
name: "created_at",
keypath: "created_at",
options: { unique: false },
},
],
},
],
};
export function FileDbInit() {
initDB(FileDbConfig);
}
export function useFileDB() {
return useIndexedDB(StoreKey.File);
}