Add frontend check for file size before starting to upload
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -23,10 +23,11 @@
|
|||||||
import app from '../app/App.js';
|
import app from '../app/App.js';
|
||||||
|
|
||||||
/** global: OC */
|
/** global: OC */
|
||||||
app.controller('AppController', function ($scope, $location, $http, $log, $rootScope) {
|
app.controller('AppController', function ($scope, $location, $http, $log, $rootScope, $attrs) {
|
||||||
$rootScope.sidebar = {
|
$rootScope.sidebar = {
|
||||||
show: false
|
show: false
|
||||||
};
|
};
|
||||||
$scope.sidebar = $rootScope.sidebar;
|
$scope.sidebar = $rootScope.sidebar;
|
||||||
$scope.user = oc_current_user;
|
$scope.user = oc_current_user;
|
||||||
|
$rootScope.config = JSON.parse($attrs.config);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,17 +25,18 @@ import app from '../app/App.js';
|
|||||||
/* global OC oc_requesttoken */
|
/* global OC oc_requesttoken */
|
||||||
export default class FileService {
|
export default class FileService {
|
||||||
|
|
||||||
constructor ($http, FileUploader, CardService) {
|
constructor (FileUploader, CardService, $rootScope, $filter) {
|
||||||
|
this.$filter = $filter;
|
||||||
this.uploader = new FileUploader();
|
this.uploader = new FileUploader();
|
||||||
this.cardservice = CardService;
|
this.cardservice = CardService;
|
||||||
this.uploader.onAfterAddingFile = this.onAfterAddingFile.bind(this);
|
this.uploader.onAfterAddingFile = this.onAfterAddingFile.bind(this);
|
||||||
this.uploader.onSuccessItem = this.onSuccessItem.bind(this);
|
this.uploader.onSuccessItem = this.onSuccessItem.bind(this);
|
||||||
this.uploader.onErrorItem = this.onErrorItem.bind(this);
|
this.uploader.onErrorItem = this.onErrorItem.bind(this);
|
||||||
|
|
||||||
|
this.maxUploadSize = $rootScope.config.maxUploadSize;
|
||||||
this.status = null;
|
this.status = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
runUpload (fileItem, attachmentId) {
|
runUpload (fileItem, attachmentId) {
|
||||||
this.status = null;
|
this.status = null;
|
||||||
fileItem.url = OC.generateUrl('/apps/deck/cards/' + fileItem.cardId + '/attachment?type=deck_file');
|
fileItem.url = OC.generateUrl('/apps/deck/cards/' + fileItem.cardId + '/attachment?type=deck_file');
|
||||||
@@ -55,6 +56,14 @@ export default class FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onAfterAddingFile (fileItem) {
|
onAfterAddingFile (fileItem) {
|
||||||
|
if (this.maxUploadSize > 0 && fileItem.file.size > this.maxUploadSize) {
|
||||||
|
this.status = {
|
||||||
|
error: t('deck', `Failed to upload {name}`, {name: fileItem.file.name}),
|
||||||
|
message: t('deck', 'Maximum file size of {size} exceeded', {size: this.$filter('bytes')(this.maxUploadSize)})
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch card details before trying to upload so we can detect filename collisions properly
|
// Fetch card details before trying to upload so we can detect filename collisions properly
|
||||||
let self = this;
|
let self = this;
|
||||||
this.cardservice.fetchOne(fileItem.cardId).then(function (data) {
|
this.cardservice.fetchOne(fileItem.cardId).then(function (data) {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class PageController extends Controller {
|
|||||||
public function index() {
|
public function index() {
|
||||||
$params = [
|
$params = [
|
||||||
'user' => $this->userId,
|
'user' => $this->userId,
|
||||||
|
'maxUploadSize' => \OCP\Util::uploadLimit(),
|
||||||
];
|
];
|
||||||
return new TemplateResponse('deck', 'main', $params);
|
return new TemplateResponse('deck', 'main', $params);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ Util::addStyle('deck', 'style');
|
|||||||
Util::addScript('deck', 'build/deck');
|
Util::addScript('deck', 'build/deck');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div id="app" class="app-deck" data-ng-app="Deck" ng-controller="AppController" ng-cloak>
|
<div id="app" class="app-deck" data-ng-app="Deck" ng-controller="AppController" ng-cloak config="<?php p(json_encode($_)); ?>">
|
||||||
|
|
||||||
<div id="app-navigation" data-ng-controller="ListController" ng-init="initSidebar()">
|
<div id="app-navigation" data-ng-controller="ListController" ng-init="initSidebar()">
|
||||||
<?php print_unescaped($this->inc('part.navigation')); ?>
|
<?php print_unescaped($this->inc('part.navigation')); ?>
|
||||||
|
|||||||
Reference in New Issue
Block a user