Ability to rename a file before uploading it to the server

pull/1/head
yflory 7 years ago
parent 2813b7219e
commit 25d3d321da

@ -523,6 +523,9 @@ define(function () {
out.settings_codeUseTabs = "Utiliser des tabulations au lieu d'espaces"; out.settings_codeUseTabs = "Utiliser des tabulations au lieu d'espaces";
out.upload_title = "Hébergement de fichiers"; out.upload_title = "Hébergement de fichiers";
out.upload_rename = "Souhaitez-vous renommer <b>{0}</b> avant son stockage en ligne ?<br>" +
"<em>L'extension du fichier ({1}) sera ajoutée automatiquement. "+
"Ce nom sera permanent et visible par les autres utilisateurs</em>.";
out.upload_serverError = "Erreur interne: impossible d'importer le fichier pour l'instant."; out.upload_serverError = "Erreur interne: impossible d'importer le fichier pour l'instant.";
out.upload_uploadPending = "Vous avez déjà un fichier en cours d'importation. Souhaitez-vous l'annuler et importer ce nouveau fichier ?"; out.upload_uploadPending = "Vous avez déjà un fichier en cours d'importation. Souhaitez-vous l'annuler et importer ce nouveau fichier ?";
out.upload_success = "Votre fichier ({0}) a été importé avec succès et ajouté à votre CryptDrive."; out.upload_success = "Votre fichier ({0}) a été importé avec succès et ajouté à votre CryptDrive.";

@ -528,6 +528,9 @@ define(function () {
out.settings_codeUseTabs = "Indent using tabs (instead of spaces)"; out.settings_codeUseTabs = "Indent using tabs (instead of spaces)";
out.upload_title = "File upload"; out.upload_title = "File upload";
out.upload_rename = "Do you want to rename <b>{0}</b> before uploading it to the server?<br>" +
"<em>The file extension ({1}) will be added automatically. "+
"This name will be permanent and visible to other users.</em>";
out.upload_serverError = "Server Error: unable to upload your file at this time."; out.upload_serverError = "Server Error: unable to upload your file at this time.";
out.upload_uploadPending = "You already have an upload in progress. Cancel it and upload your new file?"; out.upload_uploadPending = "You already have an upload in progress. Cancel it and upload your new file?";
out.upload_success = "Your file ({0}) has been successfully uploaded and added to your drive."; out.upload_success = "Your file ({0}) has been successfully uploaded and added to your drive.";

@ -105,6 +105,7 @@ define([
var ctx = c2.getContext('2d'); var ctx = c2.getContext('2d');
ctx.drawImage(canvas, D.x, D.y, D.w, D.h); ctx.drawImage(canvas, D.x, D.y, D.w, D.h);
cb(void 0, c2.toDataURL()); cb(void 0, c2.toDataURL());
}; };
@ -124,19 +125,18 @@ define([
Thumb.fromVideoBlob = function (blob, cb) { Thumb.fromVideoBlob = function (blob, cb) {
var url = URL.createObjectURL(blob); var url = URL.createObjectURL(blob);
var video = document.createElement("VIDEO"); var video = document.createElement("VIDEO");
video.src = url;
video.addEventListener('loadedmetadata', function() { video.addEventListener('loadedmetadata', function() {
video.currentTime = Number(Math.floor(Math.min(video.duration/10, 5)));
video.addEventListener('loadeddata', function() { video.addEventListener('loadeddata', function() {
var D = getResizedDimensions(video, 'video'); var D = getResizedDimensions(video, 'video');
Thumb.fromCanvas(video, D, cb); Thumb.fromCanvas(video, D, cb);
}); });
video.currentTime = Number(Math.floor(Math.min(video.duration/10, 5)));
}); });
video.addEventListener('error', function (e) { video.addEventListener('error', function (e) {
console.error(e); console.error(e);
cb('ERROR'); cb('ERROR');
}); });
video.src = url;
}; };
Thumb.fromPdfBlob = function (blob, cb) { Thumb.fromPdfBlob = function (blob, cb) {
require.config({paths: {'pdfjs-dist': '/common/pdfjs'}}); require.config({paths: {'pdfjs-dist': '/common/pdfjs'}});

@ -95,7 +95,7 @@ define([
var id = file.id; var id = file.id;
var dropEvent = file.dropEvent; var dropEvent = file.dropEvent;
delete file.dropEvent; delete file.dropEvent;
if (dropEvent.path) { file.path = dropEvent.path; } if (dropEvent && dropEvent.path) { file.path = dropEvent.path; }
if (queue.inProgress) { return; } if (queue.inProgress) { return; }
queue.inProgress = true; queue.inProgress = true;
@ -221,12 +221,41 @@ define([
queue.next(); queue.next();
}; };
var handleFile = File.handleFile = function (file, e, thumbnail) { var showNamePrompt = true;
var promptName = function (file, cb) {
var extIdx = file.name.lastIndexOf('.');
var name = extIdx !== -1 ? file.name.slice(0,extIdx) : file.name;
var ext = extIdx !== -1 ? file.name.slice(extIdx) : "";
var msg = Messages._getKey('upload_rename', [
Util.fixHTML(file.name),
Util.fixHTML(ext)
]);
UI.prompt(msg, name, function (newName) {
if (newName === null) {
showNamePrompt = false;
return void cb (file.name);
}
if (!newName || !newName.trim()) { return void cb (file.name); }
var newExtIdx = newName.lastIndexOf('.');
var newExt = newExtIdx !== -1 ? newName.slice(newExtIdx) : "";
if (newExt !== ext) { newName += ext; }
cb(newName);
}, null, true);
};
var handleFileState = {
queue: [],
inProgress: false
};
var handleFile = File.handleFile = function (file, e) {
//if (handleFileState.inProgress) { return void handleFileState.queue.push(file); }
handleFileState.inProgress = true;
var thumb; var thumb;
var file_arraybuffer; var file_arraybuffer;
var name = file.name;
var finish = function () { var finish = function () {
var metadata = { var metadata = {
name: file.name, name: name,
type: file.type, type: file.type,
}; };
if (thumb) { metadata.thumbnail = thumb; } if (thumb) { metadata.thumbnail = thumb; }
@ -235,26 +264,26 @@ define([
metadata: metadata, metadata: metadata,
dropEvent: e dropEvent: e
}); });
handleFileState.inProgress = false;
if (handleFileState.queue.length) { handleFile(handleFileState.queue.shift()); }
};
var getName = function () {
promptName(file, function (newName) {
name = newName;
finish();
});
}; };
blobToArrayBuffer(file, function (e, buffer) { blobToArrayBuffer(file, function (e, buffer) {
if (e) { console.error(e); } if (e) { console.error(e); }
file_arraybuffer = buffer; file_arraybuffer = buffer;
if (thumbnail) { // there is already a thumbnail if (!Thumb.isSupportedType(file.type)) { return getName(); }
return blobToArrayBuffer(thumbnail, function (e, buffer) {
if (e) { console.error(e); }
thumb = arrayBufferToString(buffer);
finish();
});
}
if (!Thumb.isSupportedType(file.type)) { return finish(); }
// make a resized thumbnail from the image.. // make a resized thumbnail from the image..
Thumb.fromBlob(file, function (e, thumb64) { Thumb.fromBlob(file, function (e, thumb64) {
if (e) { console.error(e); } if (e) { console.error(e); }
if (!thumb64) { return finish(); } if (!thumb64) { return getName(); }
thumb = thumb64; thumb = thumb64;
finish(); getName();
}); });
}); });
}; };

Loading…
Cancel
Save