create blob and blobstage stores if not exists
This commit is contained in:
32
rpc.js
32
rpc.js
@@ -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);
|
|
||||||
|
|
||||||
|
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
|
// expire old sessions once per minute
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
expireSessions(Sessions);
|
expireSessions(Sessions);
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
})
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user