use configured paths in scripts instead of hardcoded strings

pull/1/head
ansuz 6 years ago
parent 36637c4a7f
commit c3d52e87b9

@ -3,6 +3,8 @@ const Fs = require('fs');
const nThen = require('nthen');
const Pinned = require('./pinned');
const Nacl = require('tweetnacl');
const Path = require('path');
const Config = require('./load-config');
const hashesFromPinFile = (pinFile, fileName) => {
var pins = {};
@ -54,7 +56,9 @@ let data = [];
let pinned = [];
nThen((waitFor) => {
let f = '../pins/' + edPublic.slice(0, 2) + '/' + edPublic + '.ndjson';
var pinPath = Config.pinPath || './pins';
let f = Path.join(pinPath, edPublic.slice(0, 2), edPublic + '.ndjson');
Fs.readFile(f, waitFor((err, content) => {
if (err) { throw err; }
pinned = hashesFromPinFile(content.toString('utf8'), f);

@ -5,9 +5,9 @@ const Saferphore = require("saferphore");
const PinnedData = require('./pinneddata');
let config;
try {
config = require('../config/config');
config = require('./config/config');
} catch (e) {
config = require('../config/config.example');
config = require('./config/config.example');
}
if (!config.inactiveTime || typeof(config.inactiveTime) !== "number") { return; }
@ -16,7 +16,11 @@ let inactiveTime = +new Date() - (config.inactiveTime * 24 * 3600 * 1000);
let inactiveConfig = {
unpinned: true,
olderthan: inactiveTime,
blobsolderthan: inactiveTime
blobsolderthan: inactiveTime,
filePath: config.filePath,
blobPath: config.blobPath,
pinPath: config.pinPath,
};
let toDelete;
nThen(function (waitFor) {

@ -3,12 +3,7 @@ var Path = require("path");
var nThen = require("nthen");
var config;
try {
config = require('../config/config');
} catch (e) {
config = require('../config/config.example');
}
var config = require("./load-config");
var FileStorage = require('../' + config.storage || './storage/file');
var root = Path.resolve('../' + config.taskPath || './tasks');
@ -52,10 +47,12 @@ var handleTask = function (str, path, cb) {
nThen(function (waitFor) {
switch (command) {
case 'EXPIRE':
// FIXME noisy!
console.log("expiring: %s", args[0]);
store.removeChannel(args[0], waitFor());
break;
default:
// FIXME noisy
console.log("unknown command", command);
}
}).nThen(function () {
@ -83,6 +80,7 @@ nt = nThen(function (w) {
}).nThen(function () {
dirs.forEach(function (dir, dIdx) {
queue(function (w) {
// FIXME noisy!
console.log('recursing into %s', dir);
Fs.readdir(Path.join(root, dir), w(function (e, list) {
list.forEach(function (fn) {
@ -90,6 +88,7 @@ nt = nThen(function (w) {
var filePath = Path.join(root, dir, fn);
var cb = w();
// FIXME noisy!
console.log("processing file at %s", filePath);
Fs.readFile(filePath, 'utf8', function (e, str) {
if (e) {

@ -0,0 +1,7 @@
var config;
try {
config = require("../config/config");
} catch (e) {
config = require("../config/config.example");
}
module.exports = config;

@ -11,6 +11,8 @@ let dirList;
const fileList = [];
const pinned = {};
// FIXME this seems to be duplicated in a few places.
// make it a library and put it in ./lib/
const checkPinStatus = (pinFile, fileName) => {
var pins = {};
pinFile.split('\n').filter((x)=>(x)).map((l) => JSON.parse(l)).forEach((l) => {

@ -2,6 +2,7 @@
const Fs = require('fs');
const Semaphore = require('saferphore');
const nThen = require('nthen');
const Path = require('path');
/*
takes contents of a pinFile (UTF8 string)
@ -63,9 +64,14 @@ const pinned = {}; // map of pinned files
// define a function: 'load' which takes a config
// and a callback
module.exports.load = function (config, cb) {
var filePath = config.filePath || './datastore';
var blobPath = config.blobPath || './blob';
var pinPath = config.pinPath || './pins';
nThen((waitFor) => {
// read the subdirectories in the datastore
Fs.readdir('../datastore', waitFor((err, list) => {
Fs.readdir(filePath, waitFor((err, list) => {
if (err) { throw err; }
dirList = list;
}));
@ -76,15 +82,15 @@ module.exports.load = function (config, cb) {
sema.take((returnAfter) => {
// get the list of files in every subdirectory
// and push them to 'fileList'
Fs.readdir('../datastore/' + f, waitFor(returnAfter((err, list2) => {
Fs.readdir(Path.join(filePath, f), waitFor(returnAfter((err, list2) => {
if (err) { throw err; }
list2.forEach((ff) => { fileList.push('../datastore/' + f + '/' + ff); });
list2.forEach((ff) => { fileList.push(Path.join(filePath, f, ff)); });
})));
});
});
}).nThen((waitFor) => {
// read the subdirectories in 'blob'
Fs.readdir('../blob', waitFor((err, list) => {
Fs.readdir(blobPath, waitFor((err, list) => {
if (err) { throw err; }
// overwrite dirList
dirList = list;
@ -96,9 +102,9 @@ module.exports.load = function (config, cb) {
sema.take((returnAfter) => {
// get the list of files in every subdirectory
// and push them to 'fileList'
Fs.readdir('../blob/' + f, waitFor(returnAfter((err, list2) => {
Fs.readdir(Path.join(blobPath, f), waitFor(returnAfter((err, list2) => {
if (err) { throw err; }
list2.forEach((ff) => { fileList.push('../blob/' + f + '/' + ff); });
list2.forEach((ff) => { fileList.push(Path.join(blobPath, f, ff)); });
})));
});
});
@ -118,7 +124,7 @@ module.exports.load = function (config, cb) {
});
}).nThen((waitFor) => {
// read the subdirectories in the pinstore
Fs.readdir('../pins', waitFor((err, list) => {
Fs.readdir(pinPath, waitFor((err, list) => {
if (err) { throw err; }
dirList = list;
}));
@ -131,9 +137,9 @@ module.exports.load = function (config, cb) {
sema.take((returnAfter) => {
// get the list of files in every subdirectory
// and push them to 'fileList' (which is empty because we keep reusing it)
Fs.readdir('../pins/' + f, waitFor(returnAfter((err, list2) => {
Fs.readdir(Path.join(pinPath, f), waitFor(returnAfter((err, list2) => {
if (err) { throw err; }
list2.forEach((ff) => { fileList.push('../pins/' + f + '/' + ff); });
list2.forEach((ff) => { fileList.push(Path.join(pinPath, f, ff)); });
})));
});
});

Loading…
Cancel
Save