create blob and blobstage stores if not exists

pull/1/head
ansuz 8 years ago
parent 69368def48
commit 4d48c88807

@ -2,6 +2,8 @@
/* Use Nacl for checking signatures of messages */ /* Use Nacl for checking signatures of messages */
var Nacl = require("tweetnacl"); var Nacl = require("tweetnacl");
var Fs = require("fs");
var RPC = module.exports; var RPC = module.exports;
var Store = require("./storage/file"); var Store = require("./storage/file");
@ -380,19 +382,17 @@ var getLimit = function (cb) {
}; };
var createBlobStaging = function (cb) { var safeMkdir = function (path, cb) {
Fs.mkdir(path, function (e) {
}; if (!e || e.code === 'EEXIST') { return void cb(); }
cb(e);
var createBlobStore = function (cb) { });
}; };
var upload = function (store, Sessions, publicKey, cb) { var upload = function (store, Sessions, publicKey, cb) {
}; };
/*::const ConfigType = require('./config.example.js');*/ /*::const ConfigType = require('./config.example.js');*/
RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)=>void*/) { RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)=>void*/) {
// load pin-store... // load pin-store...
@ -509,15 +509,29 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)
} }
}; };
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({ Store.create({
filePath: './pins' filePath: pinPath,
}, function (s) { }, function (s) {
store = s; store = s;
cb(void 0, rpc);
// expire old sessions once per minute safeMkdir(blobPath, function (e) {
setInterval(function () { if (e) { throw e; }
expireSessions(Sessions); safeMkdir(blobStagingPath, function (e) {
}, 60000); if (e) { throw e; }
cb(void 0, rpc);
// expire old sessions once per minute
setInterval(function () {
expireSessions(Sessions);
}, 60000);
})
});
}); });
}; };

Loading…
Cancel
Save