Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/files/js/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ OC.FileUpload.prototype = {
) {
data.isChunked = true;
chunkFolderPromise = this.uploader.davClient.createDirectory(
'uploads/' + encodeURIComponent(OC.getCurrentUser().uid) + '/' + encodeURIComponent(this.getId())
'uploads/' + OC.getCurrentUser().uid + '/' + this.getId()
);
// TODO: if fails, it means same id already existed, need to retry
} else {
Expand Down Expand Up @@ -296,8 +296,8 @@ OC.FileUpload.prototype = {
}

return this.uploader.davClient.move(
'uploads/' + encodeURIComponent(uid) + '/' + encodeURIComponent(this.getId()) + '/.file',
'files/' + encodeURIComponent(uid) + '/' + OC.joinPaths(this.getFullPath(), this.getFileName()),
'uploads/' + uid + '/' + this.getId() + '/.file',
'files/' + uid + '/' + OC.joinPaths(this.getFullPath(), this.getFileName()),
true,
headers
);
Expand All @@ -306,7 +306,7 @@ OC.FileUpload.prototype = {
_deleteChunkFolder: function() {
// delete transfer directory for this upload
this.uploader.davClient.remove(
'uploads/' + encodeURIComponent(OC.getCurrentUser().uid) + '/' + encodeURIComponent(this.getId())
'uploads/' + OC.getCurrentUser().uid + '/' + this.getId()
);
},

Expand Down
56 changes: 43 additions & 13 deletions core/js/files/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
};
this._baseUrl = url;

this._rootSections = _.filter(this._root.split('/'), function(section) { return section !== '';});
this._rootSections = _.map(this._rootSections, window.decodeURIComponent);

var clientOptions = {
baseUrl: this._baseUrl,
xmlNamespaces: {
Expand Down Expand Up @@ -240,6 +243,33 @@
return etag;
},

/**
* Parse sub-path from href
*
* @param {String} path href path
* @return {String} sub-path section
*/
_extractPath: function(path) {
var pathSections = path.split('/');
pathSections = _.filter(pathSections, function(section) { return section !== '';});

var i = 0;
for (i = 0; i < this._rootSections.length; i++) {
if (this._rootSections[i] !== decodeURIComponent(pathSections[i])) {
// mismatch
return null;
}
}

// build the sub-path from the remaining sections
var subPath = '';
while (i < pathSections.length) {
subPath += '/' + decodeURIComponent(pathSections[i]);
i++;
}
return subPath;
},

/**
* Parse Webdav result
*
Expand All @@ -248,17 +278,12 @@
* @return {Array.<FileInfo>} array of file info
*/
_parseFileInfo: function(response) {
var path = response.href;
if (path.substr(0, this._root.length) === this._root) {
path = path.substr(this._root.length);
}

if (path.charAt(path.length - 1) === '/') {
path = path.substr(0, path.length - 1);
var path = this._extractPath(response.href);
// invalid subpath
if (path === null) {
return null;
}

path = decodeURIComponent(path);

if (response.propStat.length === 0 || response.propStat[0].status !== 'HTTP/1.1 200 OK') {
return null;
}
Expand Down Expand Up @@ -356,9 +381,14 @@
*/
_parseResult: function(responses) {
var self = this;
return _.map(responses, function(response) {
return self._parseFileInfo(response);
});
var fileInfos = [];
for (var i = 0; i < responses.length; i++) {
var fileInfo = self._parseFileInfo(responses[i]);
if (fileInfo !== null) {
fileInfos.push(fileInfo);
}
}
return fileInfos;
},

/**
Expand Down Expand Up @@ -837,7 +867,7 @@

var client = new OC.Files.Client({
host: OC.getHost(),
root: OC.linkToRemoteBase('webdav'),
root: OC.linkToRemoteBase('dav') + '/files/' + encodeURIComponent(OC.getCurrentUser().uid) + '/',
useHTTPS: OC.getProtocol() === 'https'
});
OC.Files._defaultClient = client;
Expand Down
Loading