diff options
author | John Molakvoæ <skjnldsv@protonmail.com> | 2022-08-24 17:41:08 +0200 |
---|---|---|
committer | nextcloud-command <nextcloud-command@users.noreply.github.com> | 2022-09-01 17:13:04 +0000 |
commit | 96bbc1a7a1a2f7534ea13a3e1c850ae5236a90c3 (patch) | |
tree | c8c2671a1ee08c8c1b8406becbeadbd1d0255908 /core/src/OC | |
parent | af29b978078ffd9169a9bd9146feccbb7974c900 (diff) | |
download | nextcloud-server-96bbc1a7a1a2f7534ea13a3e1c850ae5236a90c3.tar.gz nextcloud-server-96bbc1a7a1a2f7534ea13a3e1c850ae5236a90c3.zip |
Fallback to root if the picker folder doesn't exists
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
Diffstat (limited to 'core/src/OC')
-rw-r--r-- | core/src/OC/dialogs.js | 221 |
1 files changed, 119 insertions, 102 deletions
diff --git a/core/src/OC/dialogs.js b/core/src/OC/dialogs.js index 83f391fc99c..55fd239cf22 100644 --- a/core/src/OC/dialogs.js +++ b/core/src/OC/dialogs.js @@ -1133,7 +1133,7 @@ const Dialogs = { /** * fills the filepicker with files */ - _fillFilePicker: function(dir) { + _fillFilePicker: async function(dir) { var self = this this.$filelist.empty() this.$filePicker.find('.emptycontent').hide() @@ -1151,126 +1151,143 @@ const Dialogs = { } else { self.$fileListHeader.find('[data-sort=' + self.filepicker.sortField + '] .sort-indicator').addClass('icon-triangle-s') } - self.filepicker.filesClient.getFolderContents(dir).then(function(status, files) { - self.filelist = files - if (filter && filter.length > 0 && filter.indexOf('*') === -1) { - files = files.filter(function(file) { - return file.type === 'dir' || filter.indexOf(file.mimetype) !== -1 + + // Wrap within a method because a promise cannot return multiple values + // But the client impleemntation still does it... + var getFolderContents = async function(dir) { + return self.filepicker.filesClient.getFolderContents(dir) + .then((status, files) => { + return files }) - } + } - if (advancedFilter) { - files = files.filter(advancedFilter) - } + try { + var files = await getFolderContents(dir) + } catch (error) { + // fallback to root if requested dir is non-existent + console.error('Requested path does not exists, falling back to root') + var files = await getFolderContents('/') + this.$filePicker.data('path', '/') + } + + self.filelist = files + if (filter && filter.length > 0 && filter.indexOf('*') === -1) { + files = files.filter(function(file) { + return file.type === 'dir' || filter.indexOf(file.mimetype) !== -1 + }) + } - // Check if the showHidden input field exist and if it exist follow it - // Otherwise just show the hidden files - const showHiddenInput = document.getElementById('showHiddenFiles') - const showHidden = showHiddenInput === null || showHiddenInput.value === "1" - if (!showHidden) { - files = files.filter(function(file) { - return !file.name.startsWith('.') - }) - } + if (advancedFilter) { + files = files.filter(advancedFilter) + } - var Comparators = { - name: function(fileInfo1, fileInfo2) { - if (fileInfo1.type === 'dir' && fileInfo2.type !== 'dir') { - return -1 - } - if (fileInfo1.type !== 'dir' && fileInfo2.type === 'dir') { - return 1 - } - return OC.Util.naturalSortCompare(fileInfo1.name, fileInfo2.name) - }, - size: function(fileInfo1, fileInfo2) { - return fileInfo1.size - fileInfo2.size - }, - mtime: function(fileInfo1, fileInfo2) { - return fileInfo1.mtime - fileInfo2.mtime - } - } - var comparator = Comparators[self.filepicker.sortField] || Comparators.name - files = files.sort(function(file1, file2) { - var isFavorite = function(fileInfo) { - return fileInfo.tags && fileInfo.tags.indexOf(OC.TAG_FAVORITE) >= 0 - } + // Check if the showHidden input field exist and if it exist follow it + // Otherwise just show the hidden files + const showHiddenInput = document.getElementById('showHiddenFiles') + const showHidden = showHiddenInput === null || showHiddenInput.value === "1" + if (!showHidden) { + files = files.filter(function(file) { + return !file.name.startsWith('.') + }) + } - if (isFavorite(file1) && !isFavorite(file2)) { + var Comparators = { + name: function(fileInfo1, fileInfo2) { + if (fileInfo1.type === 'dir' && fileInfo2.type !== 'dir') { return -1 - } else if (!isFavorite(file1) && isFavorite(file2)) { + } + if (fileInfo1.type !== 'dir' && fileInfo2.type === 'dir') { return 1 } + return OC.Util.naturalSortCompare(fileInfo1.name, fileInfo2.name) + }, + size: function(fileInfo1, fileInfo2) { + return fileInfo1.size - fileInfo2.size + }, + mtime: function(fileInfo1, fileInfo2) { + return fileInfo1.mtime - fileInfo2.mtime + } + } + var comparator = Comparators[self.filepicker.sortField] || Comparators.name + files = files.sort(function(file1, file2) { + var isFavorite = function(fileInfo) { + return fileInfo.tags && fileInfo.tags.indexOf(OC.TAG_FAVORITE) >= 0 + } - return self.filepicker.sortOrder === 'asc' ? comparator(file1, file2) : -comparator(file1, file2) - }) + if (isFavorite(file1) && !isFavorite(file2)) { + return -1 + } else if (!isFavorite(file1) && isFavorite(file2)) { + return 1 + } + + return self.filepicker.sortOrder === 'asc' ? comparator(file1, file2) : -comparator(file1, file2) + }) + + self._fillSlug() + + if (files.length === 0) { + self.$filePicker.find('.emptycontent').show() + self.$fileListHeader.hide() + } else { + self.$filePicker.find('.emptycontent').hide() + self.$fileListHeader.show() + } - self._fillSlug() + self.$filelist.empty(); - if (files.length === 0) { - self.$filePicker.find('.emptycontent').show() - self.$fileListHeader.hide() + $.each(files, function(idx, entry) { + entry.icon = OC.MimeType.getIconUrl(entry.mimetype) + var simpleSize, sizeColor + if (typeof (entry.size) !== 'undefined' && entry.size >= 0) { + simpleSize = OC.Util.humanFileSize(parseInt(entry.size, 10), true) + sizeColor = Math.round(160 - Math.pow((entry.size / (1024 * 1024)), 2)) } else { - self.$filePicker.find('.emptycontent').hide() - self.$fileListHeader.show() + simpleSize = t('files', 'Pending') + sizeColor = 80 } - self.$filelist.empty(); - - $.each(files, function(idx, entry) { - entry.icon = OC.MimeType.getIconUrl(entry.mimetype) - var simpleSize, sizeColor - if (typeof (entry.size) !== 'undefined' && entry.size >= 0) { - simpleSize = OC.Util.humanFileSize(parseInt(entry.size, 10), true) - sizeColor = Math.round(160 - Math.pow((entry.size / (1024 * 1024)), 2)) - } else { - simpleSize = t('files', 'Pending') - sizeColor = 80 - } + // split the filename in half if the size is bigger than 20 char + // for ellipsis + if (entry.name.length >= 10) { + // leave maximum 10 letters + var split = Math.min(Math.floor(entry.name.length / 2), 10) + var filename1 = entry.name.substr(0, entry.name.length - split) + var filename2 = entry.name.substr(entry.name.length - split) + } else { + var filename1 = entry.name + var filename2 = '' + } - // split the filename in half if the size is bigger than 20 char - // for ellipsis - if (entry.name.length >= 10) { - // leave maximum 10 letters - var split = Math.min(Math.floor(entry.name.length / 2), 10) - var filename1 = entry.name.substr(0, entry.name.length - split) - var filename2 = entry.name.substr(entry.name.length - split) - } else { - var filename1 = entry.name - var filename2 = '' + var $row = self.$listTmpl.octemplate({ + type: entry.type, + dir: dir, + filename: entry.name, + filename1: filename1, + filename2: filename2, + date: OC.Util.relativeModifiedDate(entry.mtime), + size: simpleSize, + sizeColor: sizeColor, + icon: entry.icon + }) + if (entry.type === 'file') { + var urlSpec = { + file: dir + '/' + entry.name, + x: 100, + y: 100 } - - var $row = self.$listTmpl.octemplate({ - type: entry.type, - dir: dir, - filename: entry.name, - filename1: filename1, - filename2: filename2, - date: OC.Util.relativeModifiedDate(entry.mtime), - size: simpleSize, - sizeColor: sizeColor, - icon: entry.icon - }) - if (entry.type === 'file') { - var urlSpec = { - file: dir + '/' + entry.name, - x: 100, - y: 100 + var img = new Image() + var previewUrl = OC.generateUrl('/core/preview.png?') + $.param(urlSpec) + img.onload = function() { + if (img.width > 5) { + $row.find('td.filename').attr('style', 'background-image:url(' + previewUrl + ')') } - var img = new Image() - var previewUrl = OC.generateUrl('/core/preview.png?') + $.param(urlSpec) - img.onload = function() { - if (img.width > 5) { - $row.find('td.filename').attr('style', 'background-image:url(' + previewUrl + ')') - } - } - img.src = previewUrl } - self.$filelist.append($row) - }) - - self.$filelistContainer.removeClass('icon-loading') + img.src = previewUrl + } + self.$filelist.append($row) }) + + self.$filelistContainer.removeClass('icon-loading') }, /** * fills the tree list with directories |