new exception

Signed-off-by: Jakob Röhrl <jakob.roehrl@web.de>
This commit is contained in:
Jakob Röhrl
2020-02-21 11:12:24 +01:00
committed by Julius Härtl
parent 7750621917
commit 1e3ff41cb2
4 changed files with 48 additions and 13 deletions

View File

@@ -0,0 +1,36 @@
<?php
/**
* @copyright Copyright (c) 2020 Jakob Röhrl <jakob.roehrl@web.de>
*
* @author Jakob Röhrl <jakob.roehrl@web.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck;
class ConflictException extends \Exception {
public function __construct($message) {
parent::__construct($message);
}
public function getStatus() {
return 409;
}
}

View File

@@ -42,6 +42,7 @@ use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\Deck\ConflictException;
class FileService implements IAttachmentService {
@@ -146,13 +147,14 @@ class FileService implements IAttachmentService {
* @param Attachment $attachment
* @throws NotPermittedException
* @throws StatusException
* @throws ConflictException
*/
public function create(Attachment $attachment) {
$file = $this->getUploadedFile();
$folder = $this->getFolder($attachment);
$fileName = $file['name'];
if ($folder->fileExists($fileName)) {
throw new StatusException('File already exists.');
throw new ConflictException('File already exists.');
}
$target = $folder->newFile($fileName);

View File

@@ -80,14 +80,15 @@ export default {
clickAddNewAttachmment() {
this.$refs.localAttachments.click()
},
onLocalAttachmentSelected(e) {
async onLocalAttachmentSelected(e) {
const bodyFormData = new FormData()
bodyFormData.append('cardId', this.card.id)
bodyFormData.append('type', 'deck_file')
bodyFormData.append('file', e.target.files[0])
try {
this.$store.dispatch('createAttachment', { cardId: this.card.id, formData: bodyFormData })
await this.$store.dispatch('createAttachment', { cardId: this.card.id, formData: bodyFormData })
} catch (e) {
console.log("doppelt")
console.log(e)
}
},

View File

@@ -38,16 +38,12 @@ export class AttachmentApi {
}
async createAttachment({ cardId, formData }) {
try {
const response = await axios({
method: 'POST',
url: this.url(`/cards/${cardId}/attachment`),
data: formData,
})
return response.data
} catch (e) {
throw e
}
const response = await axios({
method: 'POST',
url: this.url(`/cards/${cardId}/attachment`),
data: formData,
})
return response.data
}
async deleteAttachment(attachment) {