Permalink
Browse files

Fix upload after core changes

+ minor fixes

Signed-off-by: Olivier Paroz (oparoz) <github@oparoz.com>

(cherry picked from commit 2068e12)
Signed-off-by: Olivier Paroz (oparoz) <github@oparoz.com>
  • Loading branch information...
PVince81 authored and oparoz committed Apr 16, 2017
1 parent 54b52fb commit b4ac4429841cfe2b7ea260dfb37fcde25580143c
Showing with 62 additions and 42 deletions.
  1. +32 −10 js/galleryview.js
  2. +30 −32 js/upload-helper.js
View
@@ -1,4 +1,4 @@
/* global Handlebars, Gallery */
/* global Handlebars, Gallery, Thumbnails */
(function ($, _, OC, t, Gallery) {
"use strict";
@@ -291,28 +291,50 @@
/**
* Sets up our custom handlers for folder uploading operations
*
* We only want it to be called for that specific case as all other file uploading
* operations will call Files.highlightFiles
*
* @see OC.Upload.init/file_upload_param.done()
*
* @private
*/
_setupUploader: function () {
$('#file_upload_start').on('fileuploaddone', function (e, data) {
if (data.files[0] === data.originalFiles[data.originalFiles.length - 1]
&& data.files[0].relativePath) {
var $uploadEl = $('#file_upload_start');
if (!$uploadEl.exists()) {
return;
}
this._uploader = new OC.Uploader($uploadEl, {
fileList: FileList,
dropZone: $('#content')
});
this._uploader.on('add', function (e, data) {
data.targetDir = '/' + Gallery.currentAlbum;
});
this._uploader.on('done', function (e, upload) {
var data = upload.data;
// is that the last upload ?
if (data.files[0] === data.originalFiles[data.originalFiles.length - 1]) {
var fileList = data.originalFiles;
//Ask for a refresh of the photowall
Gallery.getFiles(Gallery.currentAlbum).done(function () {
var fileId, path;
// Removes the cached thumbnails of files which have been re-uploaded
_(fileList).each(function (fileName) {
path = Gallery.currentAlbum + '/' + fileName;
if (Gallery.imageMap[path]) {
fileId = Gallery.imageMap[path].fileId;
if (Thumbnails.map[fileId]) {
delete Thumbnails.map[fileId];
}
}
});
Gallery.view.init(Gallery.currentAlbum);
});
}
});
// Since 9.0
if (OC.Upload) {
OC.Upload._isReceivedSharedFile = function (file) {
// Since Nextcloud 9.0
if (OC.Uploader) {
OC.Uploader.prototype._isReceivedSharedFile = function (file) {
var path = file.name;
var sharedWith = false;
View
@@ -1,4 +1,4 @@
/* global Gallery, Thumbnails */
/* global _, Gallery, Thumbnails */
/**
* OCA.FileList methods needed for file uploading
*
@@ -7,9 +7,9 @@
*
* Empty methods are for the "new" button, if we want to implement that one day
*
* @type {{inList: FileList.inList, lastAction: FileList.lastAction, getUniqueName:
* FileList.getUniqueName, getCurrentDirectory: FileList.getCurrentDirectory, add:
* FileList.add, checkName: FileList.checkName}}
* @type {{findFile: FileList.findFile, createFile: FileList.createFile,
* getCurrentDirectory: FileList.getCurrentDirectory, getUploadUrl:
* FileList.getUploadUrl}}
*/
var FileList = {
/**
@@ -41,34 +41,6 @@ var FileList = {
}
},
/**
* Refreshes the photowall
*
* Called at the end of the uploading process when 1 or multiple files are sent
* Never called with folders on Chrome, unless files are uploaded at the same time as folders
*
* @param fileList
*/
highlightFiles: function (fileList) {
"use strict";
//Ask for a refresh of the photowall
Gallery.getFiles(Gallery.currentAlbum).done(function () {
var fileId, path;
// Removes the cached thumbnails of files which have been re-uploaded
_(fileList).each(function (fileName) {
path = Gallery.currentAlbum + '/' + fileName;
if (Gallery.imageMap[path]) {
fileId = Gallery.imageMap[path].fileId;
if (Thumbnails.map[fileId]) {
delete Thumbnails.map[fileId];
}
}
});
Gallery.view.init(Gallery.currentAlbum);
});
},
/**
* Create an empty file inside the current album.
*
@@ -144,6 +116,32 @@ var FileList = {
// In Files, dirs start with a /
return '/' + Gallery.currentAlbum;
},
/**
* Retrieves the WebDAV upload URL
*
* @param {string} fileName
* @param {string} dir
*
* @returns {string}
*/
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);
}
});
return OC.linkToRemoteBase('webdav') + encodedPath;
}
};

0 comments on commit b4ac442

Please sign in to comment.