diff options
author | Robin Appelman <robin@icewind.nl> | 2018-09-03 19:11:14 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2018-09-20 17:03:33 +0200 |
commit | b4e452ad6025ab677bda49608803de1d84a59d11 (patch) | |
tree | d4a2216a67e52b1f082643ecab327f8c2419e426 | |
parent | 91066954a84815d348e584dd7228c5489cd14d53 (diff) | |
download | nextcloud-server-b4e452ad6025ab677bda49608803de1d84a59d11.tar.gz nextcloud-server-b4e452ad6025ab677bda49608803de1d84a59d11.zip |
Use trashbin dav endpoint to list trash in webui
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | apps/files_trashbin/js/filelist.js | 82 |
1 files changed, 39 insertions, 43 deletions
diff --git a/apps/files_trashbin/js/filelist.js b/apps/files_trashbin/js/filelist.js index 324e4d8a7e0..543ff53f0bb 100644 --- a/apps/files_trashbin/js/filelist.js +++ b/apps/files_trashbin/js/filelist.js @@ -9,6 +9,8 @@ */ (function() { var DELETED_REGEXP = new RegExp(/^(.+)\.d[0-9]+$/); + var FILENAME_PROP = '{http://nextcloud.org/ns}trashbin-filename'; + var DELETION_TIME_PROP = '{http://nextcloud.org/ns}trashbin-deletion-time'; /** * Convert a file name in the format filename.d12345 to the real file name. @@ -42,11 +44,29 @@ /** @lends OCA.Trashbin.FileList.prototype */ { id: 'trashbin', appName: t('files_trashbin', 'Deleted files'), + /** @type {OC.Files.Client} */ + client: null, /** * @private */ initialize: function() { + this.client = new OC.Files.Client({ + host: OC.getHost(), + port: OC.getPort(), + root: OC.linkToRemoteBase('dav') + '/trashbin/' + OC.getCurrentUser().uid, + useHTTPS: OC.getProtocol() === 'https' + }); + this.client.addFileInfoParser(function(response, data) { + var props = response.propStat[0].properties; + return { + displayName: props[FILENAME_PROP], + mtime: parseInt(props[DELETION_TIME_PROP], 10) * 1000, + hasPreview: true, + path: data.path.substr(6), // remove leading /trash + } + }); + var result = OCA.Files.FileList.prototype.initialize.apply(this, arguments); this.$el.find('.undelete').click('click', _.bind(this._onClickRestoreSelected, this)); @@ -91,23 +111,6 @@ return tr; }, - _renderRow: function(fileData, options) { - options = options || {}; - // make a copy to avoid changing original object - fileData = _.extend({}, fileData); - var dir = this.getCurrentDirectory(); - var dirListing = dir !== '' && dir !== '/'; - // show deleted time as mtime - if (fileData.mtime) { - fileData.mtime = parseInt(fileData.mtime, 10); - } - if (!dirListing) { - fileData.displayName = fileData.name; - fileData.name = fileData.name + '.d' + Math.floor(fileData.mtime / 1000); - } - return OCA.Files.FileList.prototype._renderRow.call(this, fileData, options); - }, - getAjaxUrl: function(action, params) { var q = ''; if (params) { @@ -278,6 +281,13 @@ }, /** + * Returns list of webdav properties to request + */ + _getWebdavProperties: function() { + return [FILENAME_PROP, DELETION_TIME_PROP].concat(this.filesClient.getPropfindProperties()); + }, + + /** * Reloads the file list using ajax call * * @return ajax call object @@ -290,39 +300,25 @@ if (this._reloadCall) { this._reloadCall.abort(); } - this._reloadCall = $.ajax({ - url: this.getAjaxUrl('list'), - data: { - dir : this.getCurrentDirectory(), - sort: this._sort, - sortdirection: this._sortDirection + this._reloadCall = this.client.getFolderContents( + 'trash/' + this.getCurrentDirectory(), { + includeParent: false, + properties: this._getWebdavProperties() } - }); + ); var callBack = this.reloadCallback.bind(this); return this._reloadCall.then(callBack, callBack); }, - reloadCallback: function(result) { + reloadCallback: function(status, result) { delete this._reloadCall; this.hideMask(); - if (!result || result.status === 'error') { - // if the error is not related to folder we're trying to load, reload the page to handle logout etc - if (result.data.error === 'authentication_error' || - result.data.error === 'token_expired' || - result.data.error === 'application_not_enabled' - ) { - OC.redirect(OC.generateUrl('apps/files')); - } - OC.Notification.show(result.data.message); - return false; - } - - if (result.status === 401) { + if (status === 401) { return false; } // Firewall Blocked request? - if (result.status === 403) { + if (status === 403) { // Go home this.changeDirectory('/'); OC.Notification.show(t('files', 'This operation is forbidden')); @@ -330,24 +326,24 @@ } // Did share service die or something else fail? - if (result.status === 500) { + if (status === 500) { // Go home this.changeDirectory('/'); OC.Notification.show(t('files', 'This directory is unavailable, please check the logs or contact the administrator')); return false; } - if (result.status === 404) { + if (status === 404) { // go back home this.changeDirectory('/'); return false; } // aborted ? - if (result.status === 0){ + if (status === 0){ return true; } - this.setFiles(result.data.files); + this.setFiles(result); return true; }, |