Skip to content

Commit f89ef39

Browse files
committed
fix(files): better upload error handling
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
1 parent 431ac74 commit f89ef39

23 files changed

+88
-32
lines changed

apps/dav/lib/Connector/Sabre/QuotaPlugin.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public function checkQuota($path, $length = null) {
193193
$parentPath = '';
194194
}
195195
$req = $this->server->httpRequest;
196+
197+
// If chunked upload
196198
if ($req->getHeader('OC-Chunked')) {
197199
$info = \OC_FileChunking::decodeName($newName);
198200
$chunkHandler = $this->getFileChunking($info);
@@ -202,6 +204,10 @@ public function checkQuota($path, $length = null) {
202204
// use target file name for free space check in case of shared files
203205
$path = rtrim($parentPath, '/') . '/' . $info['name'];
204206
}
207+
208+
// Strip any duplicate slashes
209+
$path = str_replace('//', '/', $path);
210+
205211
$freeSpace = $this->getFreeSpace($path);
206212
if ($freeSpace >= 0 && $length > $freeSpace) {
207213
if (isset($chunkHandler)) {

apps/files/src/components/NavigationQuota.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default {
8989
9090
mounted() {
9191
// Warn the user if the available storage is 0 on page load
92-
if (this.storageStats?.free === 0) {
92+
if (this.storageStats?.free <= 0) {
9393
this.showStorageFullWarning()
9494
}
9595
},
@@ -123,7 +123,7 @@ export default {
123123
}
124124
125125
// Warn the user if the available storage changed from > 0 to 0
126-
if (this.storageStats?.free !== 0 && response.data.data?.free === 0) {
126+
if (this.storageStats?.free > 0 && response.data.data?.free <= 0) {
127127
this.showStorageFullWarning()
128128
}
129129

apps/files/src/views/FilesList.vue

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
:destination="currentFolder"
5959
:multiple="true"
6060
class="files-list__header-upload-button"
61+
@failed="onUploadFail"
6162
@uploaded="onUpload" />
6263
</template>
6364
</BreadCrumbs>
@@ -126,6 +127,8 @@ import { Folder, Node, Permission } from '@nextcloud/files'
126127
import { getCapabilities } from '@nextcloud/capabilities'
127128
import { join, dirname } from 'path'
128129
import { orderBy } from 'natural-orderby'
130+
import { Parser } from 'xml2js'
131+
import { showError } from '@nextcloud/dialogs'
129132
import { translate, translatePlural } from '@nextcloud/l10n'
130133
import { Type } from '@nextcloud/sharing'
131134
import { UploadPicker } from '@nextcloud/upload'
@@ -515,6 +518,39 @@ export default defineComponent({
515518
}
516519
},
517520
521+
async onUploadFail(upload: Upload) {
522+
const status = upload.response?.status || 0
523+
524+
// Check known status codes
525+
if (status === 507) {
526+
showError(this.t('files', 'Not enough free space'))
527+
return
528+
} else if (status === 404 || status === 409) {
529+
showError(this.t('files', 'Target folder does not exist any more'))
530+
return
531+
} else if (status === 403) {
532+
showError(this.t('files', 'Operation is blocked by access control'))
533+
return
534+
} else if (status !== 0) {
535+
showError(this.t('files', 'Error when assembling chunks, status code {status}', { status }))
536+
return
537+
}
538+
539+
// Else we try to parse the response error message
540+
try {
541+
const parser = new Parser({ trim: true, explicitRoot: false })
542+
const response = await parser.parseStringPromise(upload.response?.data)
543+
const message = response['s:message'][0] as string
544+
if (typeof message === 'string' && message.trim() !== '') {
545+
// Unfortunatly, the server message is not translated
546+
showError(this.t('files', 'Error during upload: {message}', { message }))
547+
return
548+
}
549+
} catch (error) {}
550+
551+
showError(this.t('files', 'Unknown error during upload'))
552+
},
553+
518554
openSharingSidebar() {
519555
if (window?.OCA?.Files?.Sidebar?.setActiveTab) {
520556
window.OCA.Files.Sidebar.setActiveTab('sharing')

dist/core-common.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-common.js.LICENSE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474

7575
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
7676

77+
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
78+
7779
/**
7880
* @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
7981
*

dist/core-common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-init.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-init.js.LICENSE.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
2-
31
/**
42
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
53
*

dist/files-init.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)