|
76 | 76 | @click="showSidebar"> |
77 | 77 | {{ t('viewer', 'Open sidebar') }} |
78 | 78 | </NcActionButton> |
79 | | - <NcActionLink v-if="canDownload" |
80 | | - :download="currentFile.basename" |
| 79 | + <NcActionButton v-if="canDownload" |
81 | 80 | :close-after-click="true" |
82 | | - :href="downloadPath"> |
| 81 | + @click="onDownload"> |
83 | 82 | <template #icon> |
84 | 83 | <Download :size="20" /> |
85 | 84 | </template> |
86 | 85 | {{ t('viewer', 'Download') }} |
87 | | - </NcActionLink> |
| 86 | + </NcActionButton> |
88 | 87 | <NcActionButton v-if="canDelete" |
89 | 88 | :close-after-click="true" |
90 | 89 | @click="onDelete"> |
@@ -1006,12 +1005,7 @@ export default defineComponent({ |
1006 | 1005 | if (event.key === 's' && event.ctrlKey === true) { |
1007 | 1006 | event.preventDefault() |
1008 | 1007 | if (this.canDownload) { |
1009 | | - const a = document.createElement('a') |
1010 | | - a.href = this.currentFile.source ?? this.currentFile.davPath |
1011 | | - a.download = this.currentFile.basename |
1012 | | - document.body.appendChild(a) |
1013 | | - a.click() |
1014 | | - document.body.removeChild(a) |
| 1008 | + this.onDownload() |
1015 | 1009 | } |
1016 | 1010 | } |
1017 | 1011 | }, |
@@ -1196,6 +1190,43 @@ export default defineComponent({ |
1196 | 1190 | this.toggleEditor(true) |
1197 | 1191 | }, |
1198 | 1192 |
|
| 1193 | + /** |
| 1194 | + * Call handler's downloadCallback before downloading |
| 1195 | + */ |
| 1196 | + async onDownload() { |
| 1197 | + if (!this.canDownload) { |
| 1198 | + return |
| 1199 | + } |
| 1200 | +
|
| 1201 | + // Get the current handler for this file |
| 1202 | + const mime = this.currentFile.mime |
| 1203 | + const alias = mime?.split('/')[0] |
| 1204 | + const handler = this.registeredHandlers[mime] ?? this.registeredHandlers[alias] |
| 1205 | +
|
| 1206 | + if (handler?.downloadCallback && typeof handler.downloadCallback === 'function') { |
| 1207 | + try { |
| 1208 | + logger.debug('Calling handler downloadCallback before download') |
| 1209 | + await handler.downloadCallback(this.currentFile) |
| 1210 | + } catch (error) { |
| 1211 | + logger.error('Failed to execute downloadCallback', { error }) |
| 1212 | + showError(t('viewer', 'Failed to save file before download')) |
| 1213 | + return |
| 1214 | + } |
| 1215 | + } |
| 1216 | +
|
| 1217 | + this.performDownload() |
| 1218 | + }, |
| 1219 | +
|
| 1220 | + performDownload() { |
| 1221 | + logger.debug('Performing download', { file: this.currentFile }) |
| 1222 | + const a = document.createElement('a') |
| 1223 | + a.href = this.currentFile.source ?? this.currentFile.davPath |
| 1224 | + a.download = this.currentFile.basename |
| 1225 | + document.body.appendChild(a) |
| 1226 | + a.click() |
| 1227 | + document.body.removeChild(a) |
| 1228 | + }, |
| 1229 | +
|
1199 | 1230 | handleTrapElementsChange(element) { |
1200 | 1231 | this.trapElements.push(element) |
1201 | 1232 | }, |
|
0 commit comments