44
44
<component :is =" displayComponent"
45
45
:file-id =" fileId"
46
46
:is-output =" isOutput"
47
- @delete =" onDelete(fileId)" />
47
+ :clickable =" isOutput"
48
+ @delete =" onDelete(fileId)"
49
+ @click.native =" onPreviewClick(isOutput, fileId)" />
48
50
<div class =" buttons" >
49
51
<NcButton v-if =" !isOutput"
50
52
type =" tertiary"
63
65
</template >
64
66
</NcButton >
65
67
</a >
68
+ <NcButton v-if =" isOutput"
69
+ :title =" t('assistant', 'Save this media')"
70
+ @click =" onSave(fileId)" >
71
+ <template #icon >
72
+ <ContentSaveIcon />
73
+ </template >
74
+ </NcButton >
66
75
<NcButton v-if =" isOutput"
67
76
:title =" t('assistant', 'Share this media')"
68
77
@click =" onShare(fileId)" >
69
78
<template #icon >
70
79
<ShareVariantIcon />
71
80
</template >
72
- {{ t('assistant', 'Share') }}
73
81
</NcButton >
74
82
</div >
75
83
</div >
80
88
<script >
81
89
import DownloadIcon from ' vue-material-design-icons/Download.vue'
82
90
import ShareVariantIcon from ' vue-material-design-icons/ShareVariant.vue'
91
+ import ContentSaveIcon from ' vue-material-design-icons/ContentSave.vue'
83
92
84
93
import NcButton from ' @nextcloud/vue/dist/Components/NcButton.js'
85
94
@@ -117,6 +126,7 @@ export default {
117
126
DeleteIcon,
118
127
DownloadIcon,
119
128
ShareVariantIcon,
129
+ ContentSaveIcon,
120
130
NcButton,
121
131
},
122
132
@@ -244,21 +254,47 @@ export default {
244
254
})
245
255
},
246
256
onShare (fileId ) {
247
- if (this .value !== null ) {
248
- const url = generateOcsUrl (' /apps/assistant/api/v1/task/{taskId}/file/{fileId}/share' , {
249
- taskId: this .providedCurrentTaskId (),
250
- fileId,
251
- })
252
- axios .post (url).then (response => {
253
- const shareToken = response .data .ocs .data .shareToken
254
- const shareUrl = window .location .protocol + ' //' + window .location .host + generateUrl (' /s/{shareToken}' , { shareToken })
255
- console .debug (' [assistant] generated share link' , shareUrl)
256
- const message = t (' assistant' , ' Output file share link copied to clipboard' )
257
- this .copyString (shareUrl, message)
258
- }).catch (error => {
259
- console .error (error)
260
- })
257
+ if (this .value === null ) {
258
+ return
261
259
}
260
+
261
+ const url = generateOcsUrl (' /apps/assistant/api/v1/task/{taskId}/file/{fileId}/share' , {
262
+ taskId: this .providedCurrentTaskId (),
263
+ fileId,
264
+ })
265
+ axios .post (url).then (response => {
266
+ const shareToken = response .data .ocs .data .shareToken
267
+ const shareUrl = window .location .protocol + ' //' + window .location .host + generateUrl (' /s/{shareToken}' , { shareToken })
268
+ console .debug (' [assistant] generated share link' , shareUrl)
269
+ const message = t (' assistant' , ' Output file share link copied to clipboard' )
270
+ this .copyString (shareUrl, message)
271
+ }).catch (error => {
272
+ console .error (error)
273
+ })
274
+ },
275
+ onSave (fileId ) {
276
+ if (this .value === null ) {
277
+ return
278
+ }
279
+
280
+ const url = generateOcsUrl (' /apps/assistant/api/v1/task/{taskId}/file/{fileId}/save' , {
281
+ taskId: this .providedCurrentTaskId (),
282
+ fileId,
283
+ })
284
+ return axios .post (url).then (response => {
285
+ const savedPath = response .data .ocs .data .path
286
+ const savedFileId = response .data .ocs .data .fileId
287
+ console .debug (' [assistant] save output file' , savedPath)
288
+
289
+ const directUrl = window .location .protocol + ' //' + window .location .host + generateUrl (' /f/{savedFileId}' , { savedFileId })
290
+ const openMessage = ` <a href="${ directUrl} " target="_blank">${ t (' assistant' , ' Click this to open the file' )} </a>`
291
+ showSuccess (openMessage, { isHTML: true })
292
+
293
+ const afterCopyMessage = t (' assistant' , ' This output file has been saved in {path}' , { path: savedPath })
294
+ this .copyString (directUrl, afterCopyMessage)
295
+ }).catch (error => {
296
+ console .error (error)
297
+ })
262
298
},
263
299
async copyString (content , message ) {
264
300
try {
@@ -270,6 +306,24 @@ export default {
270
306
showError (t (' assistant' , ' Could not copy to clipboard' ))
271
307
}
272
308
},
309
+ onPreviewClick (isOutput , fileId ) {
310
+ // do not open input media files in the viewer
311
+ if (this .value === null || ! isOutput) {
312
+ return
313
+ }
314
+
315
+ const url = generateOcsUrl (' /apps/assistant/api/v1/task/{taskId}/file/{fileId}/save' , {
316
+ taskId: this .providedCurrentTaskId (),
317
+ fileId,
318
+ })
319
+ return axios .post (url).then (response => {
320
+ const savedPath = response .data .ocs .data .path
321
+ console .debug (' [assistant] view output file' , savedPath)
322
+ OCA .Viewer .open ({ path: savedPath })
323
+ }).catch (error => {
324
+ console .error (error)
325
+ })
326
+ },
273
327
},
274
328
}
275
329
</script >
0 commit comments