More fixes to file upload
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
f72ffa2f11
commit
f374eb5f1d
|
@ -204,6 +204,14 @@ OC.FileUpload.prototype = {
|
|||
this.data.headers['X-OC-Mtime'] = file.lastModified / 1000;
|
||||
}
|
||||
|
||||
var userName = this.uploader.filesClient.getUserName();
|
||||
var password = this.uploader.filesClient.getPassword();
|
||||
if (userName) {
|
||||
// copy username/password from DAV client
|
||||
this.data.headers['Authorization'] =
|
||||
'Basic ' + btoa(userName + ':' + (password || ''));
|
||||
}
|
||||
|
||||
if (!this.uploader.isXHRUpload()) {
|
||||
data.formData = [];
|
||||
|
||||
|
@ -222,7 +230,7 @@ OC.FileUpload.prototype = {
|
|||
&& this.getFile().size > this.uploader.fileUploadParam.maxChunkSize
|
||||
) {
|
||||
data.isChunked = true;
|
||||
chunkFolderPromise = this.uploader.davClient.createDirectory(
|
||||
chunkFolderPromise = this.uploader.filesClient.createDirectory(
|
||||
'uploads/' + encodeURIComponent(OC.getCurrentUser().uid) + '/' + encodeURIComponent(this.getId())
|
||||
);
|
||||
// TODO: if fails, it means same id already existed, need to retry
|
||||
|
@ -248,7 +256,7 @@ OC.FileUpload.prototype = {
|
|||
}
|
||||
|
||||
var uid = OC.getCurrentUser().uid;
|
||||
return this.uploader.davClient.move(
|
||||
return this.uploader.filesClient.move(
|
||||
'uploads/' + encodeURIComponent(uid) + '/' + encodeURIComponent(this.getId()) + '/.file',
|
||||
'files/' + encodeURIComponent(uid) + '/' + OC.joinPaths(this.getFullPath(), this.getFileName())
|
||||
);
|
||||
|
@ -260,7 +268,7 @@ OC.FileUpload.prototype = {
|
|||
abort: function() {
|
||||
if (this.data.isChunked) {
|
||||
// delete transfer directory for this upload
|
||||
this.uploader.davClient.remove(
|
||||
this.uploader.filesClient.remove(
|
||||
'uploads/' + encodeURIComponent(OC.getCurrentUser().uid) + '/' + encodeURIComponent(this.getId())
|
||||
);
|
||||
}
|
||||
|
@ -343,7 +351,7 @@ OC.Uploader.prototype = _.extend({
|
|||
/**
|
||||
* @type Array<OC.FileUpload>
|
||||
*/
|
||||
_uploads: [],
|
||||
_uploads: {},
|
||||
|
||||
/**
|
||||
* List of directories known to exist.
|
||||
|
@ -586,7 +594,7 @@ OC.Uploader.prototype = _.extend({
|
|||
onReplace:function(upload) {
|
||||
this.log('replace', null, upload);
|
||||
upload.setConflictMode(OC.FileUpload.CONFLICT_MODE_OVERWRITE);
|
||||
upload.submit();
|
||||
this.submitUploads([upload]);
|
||||
},
|
||||
/**
|
||||
* handle uploading a file and letting the server decide a new name
|
||||
|
@ -595,7 +603,7 @@ OC.Uploader.prototype = _.extend({
|
|||
onAutorename:function(upload) {
|
||||
this.log('autorename', null, upload);
|
||||
upload.setConflictMode(OC.FileUpload.CONFLICT_MODE_AUTORENAME);
|
||||
upload.submit();
|
||||
this.submitUploads([upload]);
|
||||
},
|
||||
_trace:false, //TODO implement log handler for JS per class?
|
||||
log:function(caption, e, data) {
|
||||
|
@ -707,19 +715,13 @@ OC.Uploader.prototype = _.extend({
|
|||
|
||||
this.fileList = options.fileList;
|
||||
this.filesClient = options.filesClient || OC.Files.getClient();
|
||||
this.davClient = new OC.Files.Client({
|
||||
host: OC.getHost(),
|
||||
port: OC.getPort(),
|
||||
root: OC.getRootPath() + '/remote.php/dav/',
|
||||
useHTTPS: OC.getProtocol() === 'https'
|
||||
});
|
||||
|
||||
$uploadEl = $($uploadEl);
|
||||
this.$uploadEl = $uploadEl;
|
||||
|
||||
if ($uploadEl.exists()) {
|
||||
$('#uploadprogresswrapper .stop').on('click', function() {
|
||||
this.cancelUploads();
|
||||
self.cancelUploads();
|
||||
});
|
||||
|
||||
this.fileUploadParam = {
|
||||
|
|
|
@ -2786,8 +2786,13 @@
|
|||
if (OC.isSamePath(OC.dirname(upload.getFullPath() + '/'), self.getCurrentDirectory())) {
|
||||
self._uploads[fileName] = fetchInfoPromise;
|
||||
}
|
||||
|
||||
var uploadText = self.$fileList.find('tr .uploadtext');
|
||||
self.showFileBusyState(uploadText.closest('tr'), false);
|
||||
uploadText.fadeOut();
|
||||
uploadText.attr('currentUploads', 0);
|
||||
});
|
||||
uploader.on('createdfolder', function(e, fullPath) {
|
||||
uploader.on('createdfolder', function(fullPath) {
|
||||
self.addAndFetchFileInfo(OC.basename(fullPath), OC.dirname(fullPath));
|
||||
});
|
||||
uploader.on('stop', function() {
|
||||
|
@ -2805,6 +2810,11 @@
|
|||
self.highlightFiles(fileNames);
|
||||
});
|
||||
self.updateStorageStatistics();
|
||||
|
||||
var uploadText = self.$fileList.find('tr .uploadtext');
|
||||
self.showFileBusyState(uploadText.closest('tr'), false);
|
||||
uploadText.fadeOut();
|
||||
uploadText.attr('currentUploads', 0);
|
||||
});
|
||||
uploader.on('fail', function(e, data) {
|
||||
self._uploader.log('filelist handle fileuploadfail', e, data);
|
||||
|
@ -2812,13 +2822,11 @@
|
|||
self._uploads = [];
|
||||
|
||||
//if user pressed cancel hide upload chrome
|
||||
if (data.errorThrown === 'abort') {
|
||||
//cleanup uploading to a dir
|
||||
var uploadText = self.$fileList.find('tr .uploadtext');
|
||||
self.showFileBusyState(uploadText.closest('tr'), false);
|
||||
uploadText.fadeOut();
|
||||
uploadText.attr('currentUploads', 0);
|
||||
}
|
||||
self.updateStorageStatistics();
|
||||
});
|
||||
|
||||
|
|
|
@ -2721,7 +2721,7 @@ describe('OCA.Files.FileList tests', function() {
|
|||
it('fetches folder info', function() {
|
||||
var fetchInfoStub = sinon.stub(fileList, 'addAndFetchFileInfo');
|
||||
|
||||
uploader.trigger('createdfolder', {}, '/subdir/newfolder');
|
||||
uploader.trigger('createdfolder', '/subdir/newfolder');
|
||||
|
||||
expect(fetchInfoStub.calledOnce).toEqual(true);
|
||||
expect(fetchInfoStub.getCall(0).args[0]).toEqual('newfolder');
|
||||
|
|
|
@ -722,8 +722,47 @@
|
|||
*/
|
||||
addFileInfoParser: function(parserFunction) {
|
||||
this._fileInfoParsers.push(parserFunction);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the dav.Client instance used internally
|
||||
*
|
||||
* @since 9.2
|
||||
* @return {dav.Client}
|
||||
*/
|
||||
getClient: function() {
|
||||
return this._client;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the user name
|
||||
*
|
||||
* @since 9.2
|
||||
* @return {String} userName
|
||||
*/
|
||||
getUserName: function() {
|
||||
return this._client.userName;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the password
|
||||
*
|
||||
* @since 9.2
|
||||
* @return {String} password
|
||||
*/
|
||||
getPassword: function() {
|
||||
return this._client.password;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the base URL
|
||||
*
|
||||
* @since 9.2
|
||||
* @return {String} base URL
|
||||
*/
|
||||
getBaseUrl: function() {
|
||||
return this._client.baseUrl;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue