Skip to content

Commit 1323312

Browse files
juliusknorrbackportbot[bot]
authored andcommitted
Check for target folder available quota when uploading
Signed-off-by: Julius Härtl <jus@bitgrid.net> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent 4530877 commit 1323312

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

apps/files/js/file-upload.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ OC.Uploader.prototype = _.extend({
918918
*/
919919
add: function(e, data) {
920920
self.log('add', e, data);
921-
var that = $(this), freeSpace;
921+
var that = $(this), freeSpace = 0;
922922

923923
var upload = new OC.FileUpload(self, data);
924924
// can't link directly due to jQuery not liking cyclic deps on its ajax object
@@ -989,13 +989,20 @@ OC.Uploader.prototype = _.extend({
989989
}
990990

991991
// check free space
992-
freeSpace = $('#free_space').val();
992+
if (!self.fileList || upload.getTargetFolder() === self.fileList.getCurrentDirectory()) {
993+
// Use global free space if there is no file list to check or the current directory is the target
994+
freeSpace = $('#free_space').val()
995+
} else if (upload.getTargetFolder().indexOf(self.fileList.getCurrentDirectory()) === 0) {
996+
// Check subdirectory free space if file is uploaded there
997+
var targetSubdir = upload._targetFolder.replace(self.fileList.getCurrentDirectory(), '')
998+
freeSpace = parseInt(upload.uploader.fileList.getModelForFile(targetSubdir).get('quotaAvailableBytes'))
999+
}
9931000
if (freeSpace >= 0 && selection.totalBytes > freeSpace) {
9941001
data.textStatus = 'notenoughspace';
9951002
data.errorThrown = t('files',
9961003
'Not enough free space, you are uploading {size1} but only {size2} is left', {
9971004
'size1': OC.Util.humanFileSize(selection.totalBytes),
998-
'size2': OC.Util.humanFileSize($('#free_space').val())
1005+
'size2': OC.Util.humanFileSize(freeSpace)
9991006
});
10001007
}
10011008

apps/files/js/filelist.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,7 @@
12361236
mtime: parseInt($el.attr('data-mtime'), 10),
12371237
type: $el.attr('data-type'),
12381238
etag: $el.attr('data-etag'),
1239+
quotaAvailableBytes: $el.attr('data-quota'),
12391240
permissions: parseInt($el.attr('data-permissions'), 10),
12401241
hasPreview: $el.attr('data-has-preview') === 'true',
12411242
isEncrypted: $el.attr('data-e2eencrypted') === 'true'
@@ -1495,6 +1496,7 @@
14951496
"data-mime": mime,
14961497
"data-mtime": mtime,
14971498
"data-etag": fileData.etag,
1499+
"data-quota": fileData.quotaAvailableBytes,
14981500
"data-permissions": permissions,
14991501
"data-has-preview": fileData.hasPreview !== false,
15001502
"data-e2eencrypted": fileData.isEncrypted === true

apps/files/tests/js/filelistSpec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,6 +2232,7 @@ describe('OCA.Files.FileList tests', function() {
22322232
type: 'file',
22332233
size: 12,
22342234
etag: 'abc',
2235+
quotaAvailableBytes: '-1',
22352236
permissions: OC.PERMISSION_ALL,
22362237
hasPreview: true,
22372238
isEncrypted: false
@@ -2243,6 +2244,7 @@ describe('OCA.Files.FileList tests', function() {
22432244
mimetype: 'application/pdf',
22442245
mtime: 234560000,
22452246
size: 58009,
2247+
quotaAvailableBytes: '-1',
22462248
etag: '123',
22472249
permissions: OC.PERMISSION_ALL,
22482250
hasPreview: true,
@@ -2255,6 +2257,7 @@ describe('OCA.Files.FileList tests', function() {
22552257
mimetype: 'httpd/unix-directory',
22562258
mtime: 134560000,
22572259
size: 250,
2260+
quotaAvailableBytes: '-1',
22582261
etag: '456',
22592262
permissions: OC.PERMISSION_ALL,
22602263
hasPreview: true,
@@ -2278,6 +2281,7 @@ describe('OCA.Files.FileList tests', function() {
22782281
mtime: 123456789,
22792282
type: 'file',
22802283
size: 12,
2284+
quotaAvailableBytes: '-1',
22812285
etag: 'abc',
22822286
permissions: OC.PERMISSION_ALL,
22832287
hasPreview: true,
@@ -2290,6 +2294,7 @@ describe('OCA.Files.FileList tests', function() {
22902294
mimetype: 'httpd/unix-directory',
22912295
mtime: 134560000,
22922296
size: 250,
2297+
quotaAvailableBytes: '-1',
22932298
etag: '456',
22942299
permissions: OC.PERMISSION_ALL,
22952300
hasPreview: true,

0 commit comments

Comments
 (0)