-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathvrmDataProvider.ts
More file actions
41 lines (32 loc) · 1.54 KB
/
vrmDataProvider.ts
File metadata and controls
41 lines (32 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { VrmDexie } from "./vrmDb";
import VrmDbModel from "./vrmDbModel";
import { db } from "./vrmDb";
import { Base64ToBlob } from "@/utils/blobDataUtils";
export class VrmDataProvider {
private db: VrmDexie;
constructor() {
this.db = db;
}
componentWillUnmount() {
this.db.close();
}
public addItem(hash: string, saveType: 'local' | 'web', vrmData: string = "", vrmUrl: string = "", thumbData: string = ""): Promise<void> {
return this.db.vrms.put(new VrmDbModel(hash, saveType, vrmData, vrmUrl, thumbData))
.then(() => { console.log("[VRM] IndexedDB: запись vrms.put успешна, hash =", hash); })
.catch((err) => { console.error("[VRM] IndexedDB: ошибка vrms.put", err); throw err; });
}
public async getItems(): Promise<VrmDbModel[]> {
return this.db.vrms.toArray();
}
public updateItemThumb(hash: string, vrmThumbData: string): void {
this.db.vrms.where("hash").equals(hash).modify({ thumbData: vrmThumbData });
}
public getItemAsBlob(hash: string): Promise<Blob | undefined> {
return this.db.vrms.where("hash").equals(hash).first()
.then(vrmDbModel => { console.log(`hash: ${hash}`); console.log(`vrmDbModel: ${vrmDbModel}`); return vrmDbModel ? Base64ToBlob(vrmDbModel?.vrmData) : undefined; });
}
public addItemUrl(hash: string, url: string) {
this.db.vrms.where("hash").equals(hash).modify({ vrmUrl: url, saveType: 'web' });
}
}
export const vrmDataProvider = new VrmDataProvider();