Skip to content

Commit

Permalink
feat: add OC.Files.Client.unlock() and add lock token to putFileConte…
Browse files Browse the repository at this point in the history
…nts (#40772)

* [tx] updated from transifex

* feat: add OC.Files.Client.unlock() and add lock token to putFileContents

* Include docs for the unlock function

---------

Co-authored-by: ownClouders <devops@owncloud.com>
Co-authored-by: Juan Pablo Villafáñez <jvillafanez@solidgeargroup.com>
  • Loading branch information
3 people authored Aug 16, 2023
1 parent 86a8ce2 commit c14b7a0
Showing 1 changed file with 53 additions and 30 deletions.
83 changes: 53 additions & 30 deletions core/js/files/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @param {String} [options.root] root path
* @param {String} [options.userName] user name
* @param {String} [options.password] password
* @param {String[]} [options.defaultHeaders] defaultHeaders
*
* @since 8.2
*/
Expand Down Expand Up @@ -200,35 +201,6 @@
return path;
},

/**
* Parse headers string into a map
*
* @param {string} headersString headers list as string
*
* @return {Object.<String,Array>} map of header name to header contents
*/
_parseHeaders: function(headersString) {
var headerRows = headersString.split('\n');
var headers = {};
for (var i = 0; i < headerRows.length; i++) {
var sepPos = headerRows[i].indexOf(':');
if (sepPos < 0) {
continue;
}

var headerName = headerRows[i].substr(0, sepPos);
var headerValue = headerRows[i].substr(sepPos + 2);

if (!headers[headerName]) {
// make it an array
headers[headerName] = [];
}

headers[headerName].push(headerValue);
}
return headers;
},

/**
* Parses the etag response which is in double quotes.
*
Expand Down Expand Up @@ -577,6 +549,7 @@
* Returns the file info of a given path.
*
* @param {String} path path
* @param options
* @param {Array} [options.properties] list of Webdav properties to retrieve
*
* @return {Promise} promise
Expand Down Expand Up @@ -653,6 +626,7 @@
* @param {Object} [options]
* @param {String} [options.contentType='text/plain'] content type
* @param {bool} [options.overwrite=true] whether to overwrite an existing file
* @param {String} [options.lockToken=opaquelocktoken:123-456] sends a lock token if the resource was locked before
*
* @return {Promise}
*/
Expand All @@ -676,6 +650,9 @@
// will trigger 412 precondition failed if a file already exists
headers['If-None-Match'] = '*';
}
if (options.lockToken) {
headers['If'] = '(<' + options.lockToken + '>)';
}

this._client.request(
'PUT',
Expand Down Expand Up @@ -800,6 +777,50 @@
return promise;
},

/**
* Unlocks a previously locked path
*
* @param {String} path the locked path that needs to be unlocked
* @param {String} token the opaque token needed to unlock the path
* @param {Object} [options]
* @param {bool} [options.pathIsUrl=false] whether the path is already an url or we need to build an url from it
*
* @return {Promise} the promise of the unlock request
*/
unlock: function(path, token, options) {
if (!path) {
throw 'Missing argument "path"';
}
if (!token) {
throw 'Missing argument "token"';
}
var self = this;
var deferred = $.Deferred();
var promise = deferred.promise();

options = _.extend({
'pathIsUrl' : false
}, options);

this._client.request(
'UNLOCK',
options.pathIsUrl ? path : this._buildUrl(path),
{
'Lock-Token': token
}
).then(
function(result) {
if (self._isSuccessStatus(result.status)) {
deferred.resolve(result.status, result);
} else {
result = _.extend(result, self._getSabreException(result));
deferred.reject(result.status, result);
}
}
);
return promise;
},

/**
* Creates a directory
*
Expand Down Expand Up @@ -831,6 +852,7 @@
* false otherwise
* @param {Object} [headers=null] additional headers
*
* @param options
* @return {Promise} promise
*/
move: function(path, destinationPath, allowOverwrite, headers, options) {
Expand All @@ -846,6 +868,7 @@
* false otherwise
* @param {Object} [headers=null] additional headers
*
* @param options
* @return {Promise} promise
* @since 10.0.5
*/
Expand All @@ -856,7 +879,7 @@
/**
* Add a file info parser function
*
* @param {OC.Files.Client~parseFileInfo>}
* @param {OC.Files.Client~parseFileInfo} parserFunction
*/
addFileInfoParser: function(parserFunction) {
this._fileInfoParsers.push(parserFunction);
Expand Down

0 comments on commit c14b7a0

Please sign in to comment.