|
103 | 103 | :file-id="a.file_id" |
104 | 104 | :task-id="message.role === 'human' ? undefined : (a.ocp_task_id ?? message.ocp_task_id)" |
105 | 105 | :is-output="isOutput" /> |
106 | | - <FileDisplay v-for="f in fileAttachments" |
107 | | - :key="f.type + '-' + f.file_id" |
108 | | - class="message__content" |
109 | | - :file-id="f.file_id" |
110 | | - :task-id="message.role === 'human' ? undefined : (f.ocp_task_id ?? message.ocp_task_id)" |
111 | | - :is-output="isOutput" |
112 | | - :clickable="isOutput" |
113 | | - @click.native="onPreviewClick(f)" /> |
| 106 | + <div v-if="fileAttachments.length" class="message__content message__files"> |
| 107 | + <FileDisplay v-for="f in fileAttachments" |
| 108 | + :key="f.type + '-' + f.file_id" |
| 109 | + :file-id="f.file_id" |
| 110 | + :task-id="message.role === 'human' ? undefined : (f.ocp_task_id ?? message.ocp_task_id)" |
| 111 | + :is-output="isOutput" |
| 112 | + :clickable="true" |
| 113 | + @click.native="onPreviewClick(f)" /> |
| 114 | + </div> |
114 | 115 | </div> |
115 | 116 | </template> |
116 | 117 |
|
@@ -289,20 +290,35 @@ export default { |
289 | 290 | } |
290 | 291 | return this.informationSourceNames[source] ? this.informationSourceNames[source] : source |
291 | 292 | }, |
| 293 | + toViewerPath(path) { |
| 294 | + // `/userId/files/foo` -> `/foo` (Viewer expects a user-files-relative path) |
| 295 | + const match = /^\/[^/]+\/files(\/.*)$/.exec(path) |
| 296 | + return match ? match[1] : path |
| 297 | + }, |
292 | 298 | onPreviewClick(file) { |
293 | | - // do not open input media files in the viewer |
294 | | - if (file.file_id === null || !this.isOutput) { |
| 299 | + if (file.file_id === null) { |
295 | 300 | return |
296 | 301 | } |
297 | 302 |
|
298 | | - const url = generateOcsUrl('/apps/assistant/api/v1/task/{taskId}/file/{fileId}/save', { |
299 | | - taskId: file.ocp_task_id ?? this.message.ocp_task_id, |
300 | | - fileId: file.file_id, |
301 | | - }) |
302 | | - return axios.post(url).then(response => { |
303 | | - const savedPath = response.data.ocs.data.path |
304 | | - console.debug('[assistant] view output file', savedPath) |
305 | | - OCA.Viewer.open({ path: savedPath }) |
| 303 | + if (this.isOutput) { |
| 304 | + const url = generateOcsUrl('/apps/assistant/api/v1/task/{taskId}/file/{fileId}/save', { |
| 305 | + taskId: file.ocp_task_id ?? this.message.ocp_task_id, |
| 306 | + fileId: file.file_id, |
| 307 | + }) |
| 308 | + return axios.post(url).then(response => { |
| 309 | + const savedPath = response.data.ocs.data.path |
| 310 | + console.debug('[assistant] view output file', savedPath) |
| 311 | + OCA.Viewer.open({ path: savedPath }) |
| 312 | + }).catch(error => { |
| 313 | + console.error(error) |
| 314 | + }) |
| 315 | + } |
| 316 | +
|
| 317 | + const url = generateOcsUrl('/apps/assistant/api/v1/file/{fileId}/info', { fileId: file.file_id }) |
| 318 | + return axios.get(url).then(response => { |
| 319 | + const path = this.toViewerPath(response.data.ocs.data.path) |
| 320 | + console.debug('[assistant] view input file', path) |
| 321 | + OCA.Viewer.open({ path }) |
306 | 322 | }).catch(error => { |
307 | 323 | console.error(error) |
308 | 324 | }) |
@@ -365,6 +381,13 @@ export default { |
365 | 381 | width: auto !important; |
366 | 382 | } |
367 | 383 | } |
| 384 | +
|
| 385 | + &__files { |
| 386 | + display: flex; |
| 387 | + flex-direction: row; |
| 388 | + flex-wrap: wrap; |
| 389 | + gap: 0.5em; |
| 390 | + } |
368 | 391 | } |
369 | 392 | </style> |
370 | 393 |
|
|
0 commit comments