|
|
|
@ -9,11 +9,12 @@ define([
|
|
|
|
|
'/common/outer/local-store.js',
|
|
|
|
|
'/common/outer/worker-channel.js',
|
|
|
|
|
'/common/outer/login-block.js',
|
|
|
|
|
'/file/file-crypto.js',
|
|
|
|
|
|
|
|
|
|
'/customize/application_config.js',
|
|
|
|
|
'/bower_components/nthen/index.js',
|
|
|
|
|
], function (Config, Messages, Util, Hash,
|
|
|
|
|
Messaging, Constants, Feedback, LocalStore, Channel, Block,
|
|
|
|
|
Messaging, Constants, Feedback, LocalStore, Channel, Block, FileCrypto,
|
|
|
|
|
AppConfig, Nthen) {
|
|
|
|
|
|
|
|
|
|
/* This file exposes functionality which is specific to Cryptpad, but not to
|
|
|
|
@ -567,6 +568,64 @@ define([
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
common.useFile = function (Crypt, cb, optsPut) {
|
|
|
|
|
var data = common.fromFileData;
|
|
|
|
|
var parsed = Hash.parsePadUrl(data.href);
|
|
|
|
|
var parsed2 = Hash.parsePadUrl(window.location.href);
|
|
|
|
|
var hash = parsed.hash;
|
|
|
|
|
var name = data.title;
|
|
|
|
|
var secret = Hash.getSecrets('file', hash, data.password);
|
|
|
|
|
var src = Hash.getBlobPathFromHex(secret.channel);
|
|
|
|
|
var key = secret.keys && secret.keys.cryptKey;
|
|
|
|
|
|
|
|
|
|
var u8;
|
|
|
|
|
var res;
|
|
|
|
|
var mode;
|
|
|
|
|
var val;
|
|
|
|
|
Nthen(function(waitFor) {
|
|
|
|
|
Util.fetch(src, waitFor(function (err, _u8) {
|
|
|
|
|
if (err) { return void waitFor.abort(); }
|
|
|
|
|
u8 = _u8;
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
FileCrypto.decrypt(u8, key, waitFor(function (err, _res) {
|
|
|
|
|
if (err || !_res.content) { return void waitFor.abort(); }
|
|
|
|
|
res = _res;
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
var ext = Util.parseFilename(data.title).ext;
|
|
|
|
|
if (!ext) {
|
|
|
|
|
mode = "text";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
require(["/common/modes.js"], waitFor(function (Modes) {
|
|
|
|
|
var fileType = Modes.list.some(function (fType) {
|
|
|
|
|
if (fType.ext === ext) {
|
|
|
|
|
mode = fType.mode;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
reader.addEventListener('loadend', waitFor(function (e) {
|
|
|
|
|
val = {
|
|
|
|
|
content: e.srcElement.result,
|
|
|
|
|
highlightMode: mode,
|
|
|
|
|
metadata: {
|
|
|
|
|
defaultTitle: name,
|
|
|
|
|
title: name,
|
|
|
|
|
type: "code",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}));
|
|
|
|
|
reader.readAsText(res.content);
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
Crypt.put(parsed2.hash, JSON.stringify(val), cb, optsPut);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Forget button
|
|
|
|
|
common.moveToTrash = function (cb, href) {
|
|
|
|
|
href = href || window.location.href;
|
|
|
|
@ -1263,6 +1322,12 @@ define([
|
|
|
|
|
messenger: rdyCfg.messenger, // Boolean
|
|
|
|
|
driveEvents: rdyCfg.driveEvents // Boolean
|
|
|
|
|
};
|
|
|
|
|
// if a pad is created from a file
|
|
|
|
|
if (sessionStorage[Constants.newPadFileData]) {
|
|
|
|
|
common.fromFileData = JSON.parse(sessionStorage[Constants.newPadFileData]);
|
|
|
|
|
delete sessionStorage[Constants.newPadFileData];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sessionStorage[Constants.newPadPathKey]) {
|
|
|
|
|
common.initialPath = sessionStorage[Constants.newPadPathKey];
|
|
|
|
|
delete sessionStorage[Constants.newPadPathKey];
|
|
|
|
|