plugin-ai-chat-file-preview 1.0.11 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -44
- package/client.d.ts +2 -2
- package/client.js +1 -1
- package/dist/client/ChatFilePreviewProvider.d.ts +44 -0
- package/dist/client/index.d.ts +13 -0
- package/dist/client/index.js +1 -1
- package/dist/client/locale.d.ts +11 -0
- package/dist/externalVersion.js +3 -4
- package/dist/index.d.ts +10 -0
- package/dist/locale/en-US.json +10 -10
- package/dist/locale/vi-VN.json +10 -10
- package/dist/locale/zh-CN.json +10 -10
- package/dist/server/index.d.ts +9 -0
- package/dist/server/plugin.d.ts +13 -0
- package/package.json +33 -30
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/client/ChatFilePreviewProvider.tsx +615 -418
- package/src/client/index.tsx +19 -19
- package/src/client/locale.ts +17 -17
- package/src/index.ts +11 -11
- package/src/locale/en-US.json +10 -10
- package/src/locale/vi-VN.json +10 -10
- package/src/locale/zh-CN.json +10 -10
- package/src/server/index.ts +10 -10
- package/src/server/plugin.ts +18 -18
- package/dist/client/0ef9cbd6bccd7aff.js +0 -30
- package/dist/client/7e04271656f34237.js +0 -10
- package/src/client/PreviewModal.tsx +0 -642
- package/src/client/SessionBlobCache.ts +0 -123
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const DB_NAME = 'nb-ai-chat-file-preview';
|
|
11
|
-
const DB_VERSION = 1;
|
|
12
|
-
const STORE_NAME = 'blobs';
|
|
13
|
-
|
|
14
|
-
function openDB(): Promise<IDBDatabase> {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
|
17
|
-
request.onupgradeneeded = () => {
|
|
18
|
-
const db = request.result;
|
|
19
|
-
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
|
20
|
-
db.createObjectStore(STORE_NAME);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
request.onsuccess = () => resolve(request.result);
|
|
24
|
-
request.onerror = () => reject(request.error);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function makeKey(sessionId: string, fileId: string): string {
|
|
29
|
-
return `${sessionId}:${fileId}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const SessionBlobCache = {
|
|
33
|
-
async get(sessionId: string, fileId: string): Promise<Blob | null> {
|
|
34
|
-
const db = await openDB();
|
|
35
|
-
return new Promise((resolve, reject) => {
|
|
36
|
-
const tx = db.transaction(STORE_NAME, 'readonly');
|
|
37
|
-
const store = tx.objectStore(STORE_NAME);
|
|
38
|
-
const req = store.get(makeKey(sessionId, fileId));
|
|
39
|
-
req.onsuccess = () => resolve(req.result || null);
|
|
40
|
-
req.onerror = () => reject(req.error);
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
async has(sessionId: string, fileId: string): Promise<boolean> {
|
|
45
|
-
const db = await openDB();
|
|
46
|
-
return new Promise((resolve, reject) => {
|
|
47
|
-
const tx = db.transaction(STORE_NAME, 'readonly');
|
|
48
|
-
const store = tx.objectStore(STORE_NAME);
|
|
49
|
-
const req = store.count(makeKey(sessionId, fileId));
|
|
50
|
-
req.onsuccess = () => resolve(req.result > 0);
|
|
51
|
-
req.onerror = () => reject(req.error);
|
|
52
|
-
});
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
async listLocalUploads(): Promise<string[]> {
|
|
56
|
-
const db = await openDB();
|
|
57
|
-
return new Promise((resolve, reject) => {
|
|
58
|
-
const tx = db.transaction(STORE_NAME, 'readonly');
|
|
59
|
-
const store = tx.objectStore(STORE_NAME);
|
|
60
|
-
const req = store.getAllKeys();
|
|
61
|
-
req.onsuccess = () => {
|
|
62
|
-
const keys = (req.result as string[])
|
|
63
|
-
.filter((k) => k.startsWith('local_uploads:'))
|
|
64
|
-
.map((k) => k.replace('local_uploads:', ''));
|
|
65
|
-
resolve(keys);
|
|
66
|
-
};
|
|
67
|
-
req.onerror = () => reject(req.error);
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
async put(sessionId: string, fileId: string, blob: Blob): Promise<void> {
|
|
72
|
-
const db = await openDB();
|
|
73
|
-
return new Promise((resolve, reject) => {
|
|
74
|
-
const tx = db.transaction(STORE_NAME, 'readwrite');
|
|
75
|
-
const store = tx.objectStore(STORE_NAME);
|
|
76
|
-
store.put(blob, makeKey(sessionId, fileId));
|
|
77
|
-
tx.oncomplete = () => resolve();
|
|
78
|
-
tx.onerror = () => reject(tx.error);
|
|
79
|
-
});
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
async delete(sessionId: string, fileId: string): Promise<void> {
|
|
83
|
-
const db = await openDB();
|
|
84
|
-
return new Promise((resolve, reject) => {
|
|
85
|
-
const tx = db.transaction(STORE_NAME, 'readwrite');
|
|
86
|
-
const store = tx.objectStore(STORE_NAME);
|
|
87
|
-
store.delete(makeKey(sessionId, fileId));
|
|
88
|
-
tx.oncomplete = () => resolve();
|
|
89
|
-
tx.onerror = () => reject(tx.error);
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
async clearSession(sessionId: string): Promise<void> {
|
|
94
|
-
const db = await openDB();
|
|
95
|
-
return new Promise((resolve, reject) => {
|
|
96
|
-
const tx = db.transaction(STORE_NAME, 'readwrite');
|
|
97
|
-
const store = tx.objectStore(STORE_NAME);
|
|
98
|
-
const req = store.openCursor();
|
|
99
|
-
req.onsuccess = () => {
|
|
100
|
-
const cursor = req.result;
|
|
101
|
-
if (cursor) {
|
|
102
|
-
if (typeof cursor.key === 'string' && cursor.key.startsWith(`${sessionId}:`)) {
|
|
103
|
-
cursor.delete();
|
|
104
|
-
}
|
|
105
|
-
cursor.continue();
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
tx.oncomplete = () => resolve();
|
|
109
|
-
tx.onerror = () => reject(tx.error);
|
|
110
|
-
});
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
async clearAll(): Promise<void> {
|
|
114
|
-
const db = await openDB();
|
|
115
|
-
return new Promise((resolve, reject) => {
|
|
116
|
-
const tx = db.transaction(STORE_NAME, 'readwrite');
|
|
117
|
-
const store = tx.objectStore(STORE_NAME);
|
|
118
|
-
store.clear();
|
|
119
|
-
tx.oncomplete = () => resolve();
|
|
120
|
-
tx.onerror = () => reject(tx.error);
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
};
|