@christianriedl/media 1.0.267 → 1.0.269

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@christianriedl/media",
3
- "version": "1.0.267",
3
+ "version": "1.0.269",
4
4
  "description": "RIC media interfaces",
5
5
 
6
6
  "main": "dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "author": "Christian Riedl",
19
19
  "license": "ISC",
20
20
  "dependencies": {
21
- "@christianriedl/utils": "^1.0.119",
21
+ "@christianriedl/utils": "^1.0.120",
22
22
  "@christianriedl/rest": "^1.0.84",
23
23
  "@christianriedl/epg": "^1.0.43"
24
24
  },
@@ -1,11 +1,16 @@
1
1
  <script setup lang="ts">
2
2
  import { inject, ref, reactive, watch, computed, onMounted, StyleValue } from 'vue';
3
3
  import { useRouter, useRoute } from 'vue-router';
4
- import { IAppState, appStateSymbol, appConfigSymbol, EScope, Helper } from '@christianriedl/utils';
4
+ import { IAppState, Dictionary, appStateSymbol, appConfigSymbol, EScope, Helper } from '@christianriedl/utils';
5
5
  import { getOpenAISymbol, IOpenAIServiceWithVectorStore } from '@christianriedl/utils';
6
6
  import { getMediaBinSymbol, getMediaInstanceSymbol, IDocumentInfo, IMediaAppConfig } from '@christianriedl/media';
7
7
  import FileUpload from '../components/FileUpload.vue';
8
8
 
9
+ interface IID {
10
+ fileId: string;
11
+ vectorStore: string;
12
+ }
13
+
9
14
  const route = useRoute();
10
15
  const router = useRouter();
11
16
  const appState = inject(appStateSymbol)!;
@@ -30,7 +35,6 @@
30
35
  const directoryInfos = reactive<IDocumentInfo[]>([]);
31
36
  const fileInfos = reactive<IDocumentInfo[]>([]);
32
37
  const heightStyle = computed<StyleValue>(() => { return { height: appState.bodyHeight.value + 'px', overflowY: 'auto' } });
33
- const inVectorStore = reactive<Dictionary<string>>({});
34
38
 
35
39
  onMounted(() => {
36
40
  mediaService.log.trace('Documents created');
@@ -43,15 +47,6 @@
43
47
  else {
44
48
  path.value = "";
45
49
  }
46
- aiService.initializeVectorStore()
47
- .then(() => {
48
- for (const key in aiService.vectorStore) {
49
- const store = aiService.vectorStore[key];
50
- for (const file in store.files) {
51
- inVectorStore[store.files[file]] = key;
52
- }
53
- }
54
- });
55
50
  getItems(path.value);
56
51
  }
57
52
  watch(() => route.query, () => start());
@@ -84,7 +79,9 @@
84
79
  mediaService.log.trace(`At ${path.value} : search ${files.length} files`);
85
80
  }
86
81
  function download(name: string, folder?: string) {
87
- cccccctefcfkhjggitufgrlhcebiccnlcctfrkghrkrd
82
+ if (!folder)
83
+ folder = path.value;
84
+ let url = mediaService.getFileUrl(folder.length > 0 ? (folder + '/' + name) : name);
88
85
  const i = name.lastIndexOf('.');
89
86
  if (i > 0) {
90
87
  const ext = name.substring(i + 1);
@@ -149,23 +146,31 @@
149
146
  }
150
147
  return false;
151
148
  }
152
- function vectorColor(file: string): string | undefined {
153
- if (inVectorStore[file]) {
154
- return 'warning';
149
+ function getFileId(file: string): IID | undefined {
150
+ if (aiService.vectorStore) {
151
+ for (const key in aiService.vectorStore) {
152
+ const store = aiService.vectorStore[key];
153
+ for (const id in store.files) {
154
+ if (store.files[id] == file) {
155
+ return { fileId: id, vectorStore: key };
156
+ }
157
+ }
158
+ }
155
159
  }
156
160
  return undefined;
157
161
  }
158
- async function vectorStore(file: string) {
159
- if (inVectorStore[file]) {
160
- if (window.confirm(`File is in vectorstore ${inVectorStore[file]}, delete ?`)) {
161
- const store = aiService.vectorStore[inVectorStore[file]]
162
- for (const vsf in store.files) {
163
- if (store.files[vsf] == file) {
164
- if (await aiService.deleteFile(vsf))
165
- delete inVectorStore[file];
166
- break;
167
- }
168
- }
162
+ function vectorStoreClass(file: string): Dictionary<boolean> {
163
+ const cls: Dictionary<boolean> = { 'bg-office': true };
164
+ if (getFileId(file)) {
165
+ cls['text-warning'] = true;
166
+ }
167
+ return cls;
168
+ }
169
+ async function vectorStore(file: string, folder?: string) {
170
+ const iid = getFileId(file);
171
+ if (iid) {
172
+ if (window.confirm(`File is in vectorstore ${iid.vectorStore}, delete ?`)) {
173
+ const rc = await aiService.deleteFile(iid.fileId);
169
174
  }
170
175
  }
171
176
  else {
@@ -173,10 +178,8 @@
173
178
  if (name != null) {
174
179
  if (!folder)
175
180
  folder = path.value;
176
- let url = mediaService.getFileUrl(folder.length > 0 ? (folder + '/' + name) : name);
177
- if (await aiService.addFile(url, name) {
178
- inVectorStore[file] = name;
179
- }
181
+ let url = mediaService.getFileUrl(folder.length > 0 ? (folder + '/' + file) : file);
182
+ const rc = await aiService.addFile(url, name);
180
183
  }
181
184
  }
182
185
  }
@@ -205,8 +208,7 @@
205
208
  <v-divider />
206
209
  </v-row>
207
210
  <v-row v-for="file in fileNames" :key="file" class="text-decoration-underline text-primary">
208
- <v-col cols="9"><p class="font-weight-medium text-decoration-underline text-primary" @click.stop="download(file)">{{file}}</p></v-col>
209
- <v-col cols="1"><v-btn v-if="isAdmin" icon="$brain" class="bg-office" density="compact" variant="flat" :color="vectorColor(file)" @click.stop="vectorStore(file)"></v-btn></v-col>
211
+ <v-col cols="10"><p class="font-weight-medium text-decoration-underline text-primary" @click.stop="download(file)">{{file}}</p></v-col>
210
212
  <v-col cols="1"><v-btn v-if="isAdmin" icon="$share" class="bg-office" density="compact" variant="flat" @click.stop="shareFile(file)"></v-btn></v-col>
211
213
  <v-col cols="1"><v-btn v-if="isAdmin" icon="$delete" class="bg-office" density="compact" variant="flat" @click.stop="deleteDirOrFile(file)"></v-btn></v-col>
212
214
  <v-divider />
@@ -237,12 +239,13 @@
237
239
  <v-col cols="1"><v-btn v-if="isAdmin" icon="$delete" class="bg-office" density="compact" variant="flat" @click.stop="deleteDirOrFile(dir.name)"></v-btn></v-col>
238
240
  <v-divider />
239
241
  </v-row>
240
- <v-row v-for="file in fileInfos" :key="file.name" class="text-decoration-underline text-primary">
241
- <v-col cols="10"><p class="font-weight-medium text-decoration-underline text-primary" @click.stop="download(file.name, file.folder)">{{file.name}}<span>{{info(file)}}</span></p></v-col>
242
- <v-col cols="1"><v-btn v-if="isAdmin" icon="$share" class="bg-office" density="compact" variant="flat" @click.stop="shareFile(file.name, file.folder)"></v-btn></v-col>
243
- <v-col cols="1"><v-btn v-if="isAdmin" icon="$delete" class="bg-office" density="compact" variant="flat" @click.stop="deleteDirOrFile(file.name, file.folder)"></v-btn></v-col>
244
- <v-divider />
245
- </v-row>
242
+ <v-row v-for="file in fileInfos" :key="file.name" class="text-decoration-underline text-primary">
243
+ <v-col cols="9"><p class="font-weight-medium text-decoration-underline text-primary" @click.stop="download(file.name, file.folder)">{{file.name}}<span>{{info(file)}}</span></p></v-col>
244
+ <v-col cols="1"><v-btn v-if="isAdmin" icon="$brain" :class="vectorStoreClass(file.name)" density="compact" variant="flat" @click.stop="vectorStore(file.name)"></v-btn></v-col>
245
+ <v-col cols="1"><v-btn v-if="isAdmin" icon="$share" class="bg-office" density="compact" variant="flat" @click.stop="shareFile(file.name, file.folder)"></v-btn></v-col>
246
+ <v-col cols="1"><v-btn v-if="isAdmin" icon="$delete" class="bg-office" density="compact" variant="flat" @click.stop="deleteDirOrFile(file.name, file.folder)"></v-btn></v-col>
247
+ <v-divider />
248
+ </v-row>
246
249
  </v-container>
247
250
  <v-card-actions>
248
251
  <v-btn v-if="backVisible" @click="listBack">