diff --git a/config.example.js b/config.example.js index 692a91c59..859c4b872 100644 --- a/config.example.js +++ b/config.example.js @@ -141,6 +141,23 @@ module.exports = { */ filePath: './datastore/', + /* CryptPad allows logged in users to request that particular documents be + * stored by the server indefinitely. This is called 'pinning'. + * Pin requests are stored in a pin-store. The location of this store is + * defined here. + */ + pinPath: './pins', + + /* CryptPad allows logged in users to upload encrypted files. Files/blobs + * are stored in a 'blob-store'. Set its location here. + */ + blobPath: './blob', + + /* CryptPad stores incomplete blobs in a 'staging' area until they are + * fully uploaded. Set its location here. + */ + blobStagingPath: './blobstage', + /* Cryptpad's file storage adaptor closes unused files after a configurale * number of milliseconds (default 30000 (30 seconds)) */ diff --git a/rpc.js b/rpc.js index 5670f1c7a..4c4afb10d 100644 --- a/rpc.js +++ b/rpc.js @@ -2,6 +2,8 @@ /* Use Nacl for checking signatures of messages */ var Nacl = require("tweetnacl"); +var Fs = require("fs"); + var RPC = module.exports; var Store = require("./storage/file"); @@ -380,18 +382,29 @@ var getLimit = function (cb) { }; -var createBlobStaging = function (cb) { - -}; - -var createBlobStore = function (cb) { +var safeMkdir = function (path, cb) { + Fs.mkdir(path, function (e) { + if (!e || e.code === 'EEXIST') { return void cb(); } + cb(e); + }); }; var upload = function (store, Sessions, publicKey, cb) { +/* + 1. check if there is an upload in progress + * if yes, return error + 2. -}; +*/ + console.log('UPLOAD_NOT_IMPLEMENTED'); + cb('NOT_IMPLEMENTED'); +}; +var cancelUpload = function (store, Sessions, publicKey, cb) { + console.log('CANCEL_UPLOAD_NOT_IMPLEMENTED'); + cb('NOT_IMPLEMENTED'); +}; /*::const ConfigType = require('./config.example.js');*/ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)=>void*/) { @@ -504,20 +517,43 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function) if (e) { return void Respond(e); } Respond(void 0, dict); }); + + case 'UPLOAD': + return void upload(null, null, null, function (e) { + Respond(e); + }); + case 'CANCEL_UPLOAD': + return void cancelUpload(null, null, null, function (e) { + Respond(e); + }); default: return void Respond('UNSUPPORTED_RPC_CALL', msg); } }; + var keyOrDefaultString = function (key, def) { + return typeof(config[key]) === 'string'? config[key]: def; + }; + + var pinPath = keyOrDefaultString('pinPath', './pins'); + var blobPath = keyOrDefaultString('blobPath', './blob'); + var blobStagingPath = keyOrDefaultString('blobStagingPath', './blobstage'); + Store.create({ - filePath: './pins' + filePath: pinPath, }, function (s) { store = s; - cb(void 0, rpc); - // expire old sessions once per minute - setInterval(function () { - expireSessions(Sessions); - }, 60000); + safeMkdir(blobPath, function (e) { + if (e) { throw e; } + safeMkdir(blobStagingPath, function (e) { + if (e) { throw e; } + cb(void 0, rpc); + // expire old sessions once per minute + setInterval(function () { + expireSessions(Sessions); + }, 60000); + }); + }); }); }; diff --git a/www/common/common-history.js b/www/common/common-history.js index 3d98a9797..702989508 100644 --- a/www/common/common-history.js +++ b/www/common/common-history.js @@ -155,7 +155,7 @@ define([ // stopPropagation because the event would be cancelled by the dropdown menus e.stopPropagation(); }); - var $label = $('