aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/js')
-rw-r--r--apps/files_sharing/js/files_drop.js64
-rw-r--r--apps/files_sharing/js/public.js43
2 files changed, 72 insertions, 35 deletions
diff --git a/apps/files_sharing/js/files_drop.js b/apps/files_sharing/js/files_drop.js
index 984eb06b9e3..64051844d03 100644
--- a/apps/files_sharing/js/files_drop.js
+++ b/apps/files_sharing/js/files_drop.js
@@ -22,50 +22,70 @@
_template: undefined,
initialize: function () {
+
+ var filesClient = new OC.Files.Client({
+ host: OC.getHost(),
+ port: OC.getPort(),
+ userName: $('#sharingToken').val(),
+ // note: password not be required, the endpoint
+ // will recognize previous validation from the session
+ root: OC.getRootPath() + '/public.php/webdav',
+ useHTTPS: OC.getProtocol() === 'https'
+ });
+
$(document).bind('drop dragover', function (e) {
// Prevent the default browser drop action:
e.preventDefault();
});
var output = this.template();
$('#public-upload').fileupload({
- url: OC.linkTo('files', 'ajax/upload.php'),
- dataType: 'json',
+ type: 'PUT',
dropZone: $('#public-upload'),
- formData: {
- dirToken: $('#sharingToken').val()
- },
+ sequentialUploads: true,
add: function(e, data) {
var errors = [];
- if(data.files[0]['size'] && data.files[0]['size'] > $('#maxFilesizeUpload').val()) {
- errors.push('File is too big');
+
+ var name = data.files[0].name;
+
+ var base = OC.getProtocol() + '://' + OC.getHost();
+ data.url = base + OC.getRootPath() + '/public.php/webdav/' + encodeURI(name);
+
+ data.multipart = false;
+
+ if (!data.headers) {
+ data.headers = {};
+ }
+
+ var userName = filesClient.getUserName();
+ var password = filesClient.getPassword();
+ if (userName) {
+ // copy username/password from DAV client
+ data.headers['Authorization'] =
+ 'Basic ' + btoa(userName + ':' + (password || ''));
}
$('#drop-upload-done-indicator').addClass('hidden');
$('#drop-upload-progress-indicator').removeClass('hidden');
_.each(data['files'], function(file) {
- if(errors.length === 0) {
- $('#public-upload ul').append(output({isUploading: true, name: escapeHTML(file.name)}));
- $('[data-toggle="tooltip"]').tooltip();
- data.submit();
- } else {
- OC.Notification.showTemporary(OC.L10N.translate('files_sharing', 'Could not upload "{filename}"', {filename: file.name}));
- $('#public-upload ul').append(output({isUploading: false, name: escapeHTML(file.name)}));
- $('[data-toggle="tooltip"]').tooltip();
- }
+ $('#public-upload ul').append(output({isUploading: true, name: escapeHTML(file.name)}));
+ $('[data-toggle="tooltip"]').tooltip();
+ data.submit();
});
+
+ return true;
},
- success: function (response) {
- if(response.status !== 'error') {
- var mimeTypeUrl = OC.MimeType.getIconUrl(response['mimetype']);
- $('#public-upload ul li[data-name="' + escapeHTML(response['filename']) + '"]').html('<img src="' + escapeHTML(mimeTypeUrl) + '"/> ' + escapeHTML(response['filename']));
+ done: function(e, data) {
+ // Created
+ if (data.jqXHR.status === 201) {
+ var mimeTypeUrl = OC.MimeType.getIconUrl(data.files[0].type);
+ $('#public-upload ul li[data-name="' + escapeHTML(data.files[0].name) + '"]').html('<img src="' + escapeHTML(mimeTypeUrl) + '"/> ' + escapeHTML(data.files[0].name));
$('[data-toggle="tooltip"]').tooltip();
} else {
- var name = response[0]['data']['filename'];
+ var name = data.files[0].name;
OC.Notification.showTemporary(OC.L10N.translate('files_sharing', 'Could not upload "{filename}"', {filename: name}));
$('#public-upload ul li[data-name="' + escapeHTML(name) + '"]').html(output({isUploading: false, name: escapeHTML(name)}));
$('[data-toggle="tooltip"]').tooltip();
}
-
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js
index 0dfff235998..0045c7156d2 100644
--- a/apps/files_sharing/js/public.js
+++ b/apps/files_sharing/js/public.js
@@ -72,7 +72,8 @@ OCA.Sharing.PublicApp = {
folderDropOptions: folderDropOptions,
fileActions: fileActions,
detailsViewEnabled: false,
- filesClient: filesClient
+ filesClient: filesClient,
+ enableUpload: true
}
);
this.files = OCA.Files.Files;
@@ -170,6 +171,30 @@ OCA.Sharing.PublicApp = {
return OC.generateUrl('/s/' + token + '/download') + '?' + OC.buildQueryString(params);
};
+ this.fileList.getUploadUrl = function(fileName, dir) {
+ if (_.isUndefined(dir)) {
+ dir = this.getCurrentDirectory();
+ }
+
+ var pathSections = dir.split('/');
+ if (!_.isUndefined(fileName)) {
+ pathSections.push(fileName);
+ }
+ var encodedPath = '';
+ _.each(pathSections, function(section) {
+ if (section !== '') {
+ encodedPath += '/' + encodeURIComponent(section);
+ }
+ });
+ var base = '';
+
+ if (!this._uploader.isXHRUpload()) {
+ // also add auth in URL due to POST workaround
+ base = OC.getProtocol() + '://' + token + '@' + OC.getHost() + (OC.getPort() ? ':' + OC.getPort() : '');
+ }
+ return base + OC.getRootPath() + '/public.php/webdav' + encodedPath;
+ };
+
this.fileList.getAjaxUrl = function (action, params) {
params = params || {};
params.t = token;
@@ -203,20 +228,12 @@ OCA.Sharing.PublicApp = {
OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments);
};
- var file_upload_start = $('#file_upload_start');
- file_upload_start.on('fileuploadadd', function (e, data) {
- var fileDirectory = '';
- if (typeof data.files[0].relativePath !== 'undefined') {
- fileDirectory = data.files[0].relativePath;
+ this.fileList._uploader.on('fileuploadadd', function(e, data) {
+ if (!data.headers) {
+ data.headers = {};
}
- // Add custom data to the upload handler
- data.formData = {
- requesttoken: $('#publicUploadRequestToken').val(),
- dirToken: $('#dirToken').val(),
- subdir: data.targetDir || self.fileList.getCurrentDirectory(),
- file_directory: fileDirectory
- };
+ data.headers.Authorization = 'Basic ' + btoa(token + ':');
});
// do not allow sharing from the public page