Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/Controller/MessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ public function saveAttachment(int $id,
);
}

$lastFile = null;
foreach ($attachments as $attachment) {
$fileName = $attachment->getName() ?? $this->l10n->t('Embedded message %s', [
$attachment->getId(),
Expand All @@ -874,8 +875,17 @@ public function saveAttachment(int $id,

$newFile = $this->userFolder->newFile($fullPath);
$newFile->putContent($attachment->getContent());
$lastFile = $newFile;
}
return new JSONResponse();

if ($lastFile === null) {
return new JSONResponse(['fileId' => null, 'path' => null]);
}

return new JSONResponse([
'fileId' => $lastFile->getId(),
'path' => $targetPath,
]);
}

/**
Expand Down
17 changes: 15 additions & 2 deletions src/components/MessageAttachment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ import { showError, showSuccess } from '@nextcloud/dialogs'
import { FilePickerVue as FilePicker } from '@nextcloud/dialogs/filepicker.js'
import { formatFileSize } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import { NcActionButton as ActionButton, NcActions as Actions, NcLoadingIcon as IconLoading } from '@nextcloud/vue'
import escapeHtml from 'escape-html'
import IconArrow from 'vue-material-design-icons/ArrowLeft.vue'
import IconSave from 'vue-material-design-icons/FolderOutline.vue'
import IconAdd from 'vue-material-design-icons/Plus.vue'
Expand Down Expand Up @@ -231,9 +233,20 @@ export default {
const id = this.$route.params.threadId

try {
await saveAttachmentToFiles(id, this.id, path)
const saved = await saveAttachmentToFiles(id, this.id, path)
Logger.info('saved')
showSuccess(t('mail', 'Attachment saved to Files'))

const fileLocationUrl = generateUrl('/apps/files/files/{fileId}?dir={dir}&openfile=true', {
fileId: saved?.fileId,
dir: saved?.path,
})

const savedText = t('mail', 'Attachment saved to Files')
const goToFilesText = t('mail', 'Go to Files')

showSuccess(`<div><p>${escapeHtml(savedText)}</p><p><a href="${fileLocationUrl}" target="_blank" rel="noopener noreferrer"><strong><u>${escapeHtml(goToFilesText)}</u></strong></a></p></div>`, {
isHTML: true,
})
} catch (e) {
Logger.error('not saved', { error: e })
showError(t('mail', 'Attachment could not be saved'))
Expand Down
4 changes: 3 additions & 1 deletion src/service/AttachmentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ export async function saveAttachmentToFiles(id, attachmentId, directory) {
},
)

return await Axios.post(url, {
const res = await Axios.post(url, {
targetPath: directory,
})

return res.data
}

export async function saveAttachmentsToFiles(id, directory) {
Expand Down
5 changes: 4 additions & 1 deletion tests/Unit/Controller/MessagesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,10 @@ public function testSaveSingleAttachment() {
->method('getContent')
->will($this->returnValue('abcdefg'));

$expected = new JSONResponse();
$expected = new JSONResponse([
'fileId' => $file->getId(),
'path' => $targetPath,
]);
$response = $this->controller->saveAttachment(
$id,
$attachmentId,
Expand Down
Loading