2023-10-20 22:35:26 +08:00
|
|
|
// SPDX-FileCopyrightText: 2023 XWiki CryptPad Team <contact@cryptpad.org> and contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2020-09-29 20:34:51 +08:00
|
|
|
var Eviction = require("../lib/eviction");
|
2019-06-12 22:18:58 +08:00
|
|
|
var nThen = require("nthen");
|
2020-02-15 05:29:30 +08:00
|
|
|
var Store = require("../lib/storage/file");
|
|
|
|
var BlobStore = require("../lib/storage/blob");
|
2020-09-24 21:32:22 +08:00
|
|
|
|
2020-09-29 21:18:23 +08:00
|
|
|
var Quota = require("../lib/commands/quota");
|
2020-10-12 21:48:12 +08:00
|
|
|
var Environment = require("../lib/env");
|
|
|
|
var Decrees = require("../lib/decrees");
|
2020-09-29 21:18:23 +08:00
|
|
|
|
2020-09-30 17:12:14 +08:00
|
|
|
var config = require("../lib/load-config");
|
2020-10-12 21:48:12 +08:00
|
|
|
|
|
|
|
var Env = Environment.create(config);
|
|
|
|
|
2024-01-08 21:08:26 +08:00
|
|
|
// Set DRY_RUN to true to run the script without deleting anything. A log file
|
|
|
|
// will be created.
|
|
|
|
Env.DRY_RUN = false;
|
|
|
|
|
2020-10-12 21:48:12 +08:00
|
|
|
var loadPremiumAccounts = function (Env, cb) {
|
|
|
|
nThen(function (w) {
|
|
|
|
// load premium accounts
|
|
|
|
Quota.updateCachedLimits(Env, w(function (err) {
|
|
|
|
if (err) {
|
|
|
|
Env.Log.error('EVICT_LOAD_PREMIUM_ACCOUNTS', {
|
|
|
|
error: err,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}).nThen(function (w) {
|
|
|
|
// load and apply decrees
|
|
|
|
Decrees.load(Env, w(function (err) {
|
|
|
|
if (err) {
|
|
|
|
Env.Log.error('EVICT_LOAD_DECREES', {
|
|
|
|
error: err.code || err,
|
|
|
|
message: err.message,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}).nThen(function () {
|
|
|
|
//console.log(Env.limits);
|
|
|
|
cb();
|
|
|
|
});
|
2020-09-24 21:32:22 +08:00
|
|
|
};
|
|
|
|
|
2020-09-29 20:34:51 +08:00
|
|
|
var prepareEnv = function (Env, cb) {
|
2020-10-12 21:48:12 +08:00
|
|
|
//Quota.applyCustomLimits(Env);
|
2020-09-29 21:18:23 +08:00
|
|
|
|
2020-09-29 20:34:51 +08:00
|
|
|
nThen(function (w) {
|
|
|
|
/* Database adaptors
|
|
|
|
*/
|
2019-06-12 22:18:58 +08:00
|
|
|
|
2020-09-29 20:34:51 +08:00
|
|
|
// load the store which will be used for iterating over channels
|
|
|
|
// and performing operations like archival and deletion
|
|
|
|
Store.create(config, w(function (err, _) {
|
2019-06-12 22:18:58 +08:00
|
|
|
if (err) {
|
2020-09-29 20:34:51 +08:00
|
|
|
w.abort();
|
|
|
|
throw err;
|
2019-06-12 22:18:58 +08:00
|
|
|
}
|
2020-09-29 20:34:51 +08:00
|
|
|
Env.store = _;
|
2019-06-12 22:18:58 +08:00
|
|
|
}));
|
|
|
|
|
2020-09-29 20:34:51 +08:00
|
|
|
Store.create({
|
|
|
|
filePath: config.pinPath,
|
2021-06-25 22:52:16 +08:00
|
|
|
// archive pin logs to their own subpath
|
|
|
|
volumeId: 'pins',
|
2020-09-29 20:34:51 +08:00
|
|
|
}, w(function (err, _) {
|
2019-09-23 16:56:38 +08:00
|
|
|
if (err) {
|
2020-09-29 20:34:51 +08:00
|
|
|
w.abort();
|
|
|
|
throw err;
|
2019-09-23 16:56:38 +08:00
|
|
|
}
|
2020-09-29 20:34:51 +08:00
|
|
|
Env.pinStore = _;
|
2019-09-23 16:56:38 +08:00
|
|
|
}));
|
2020-09-24 21:32:22 +08:00
|
|
|
|
2020-09-29 20:34:51 +08:00
|
|
|
// load the logging module so that you have a record of which
|
|
|
|
// files were archived or deleted at what time
|
|
|
|
var Logger = require("../lib/log");
|
|
|
|
Logger.create(config, w(function (_) {
|
|
|
|
Env.Log = _;
|
|
|
|
}));
|
2020-09-28 20:18:58 +08:00
|
|
|
|
2020-09-29 20:34:51 +08:00
|
|
|
config.getSession = function () {};
|
|
|
|
BlobStore.create(config, w(function (err, _) {
|
2020-09-28 20:18:58 +08:00
|
|
|
if (err) {
|
2020-09-29 20:34:51 +08:00
|
|
|
w.abort();
|
|
|
|
return console.error(err);
|
2020-09-24 21:32:22 +08:00
|
|
|
}
|
2020-09-29 20:34:51 +08:00
|
|
|
Env.blobStore = _;
|
|
|
|
}));
|
2020-10-12 21:48:12 +08:00
|
|
|
}).nThen(function (w) {
|
|
|
|
loadPremiumAccounts(Env, w(function (/* err */) {
|
|
|
|
//if (err) { }
|
|
|
|
}));
|
2020-09-29 20:34:51 +08:00
|
|
|
}).nThen(function () {
|
|
|
|
cb();
|
2020-09-24 21:32:22 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-09-29 20:34:51 +08:00
|
|
|
nThen(function (w) {
|
|
|
|
// load database adaptors and configuration values into the environment
|
|
|
|
prepareEnv(Env, w(function () {
|
2020-09-24 21:32:22 +08:00
|
|
|
|
|
|
|
|
2020-09-29 20:34:51 +08:00
|
|
|
}));
|
|
|
|
}).nThen(function (w) {
|
2023-01-23 10:59:36 +08:00
|
|
|
Eviction(Env, w(function (err, report) {
|
|
|
|
if (!report) { return; }
|
|
|
|
Env.Log.info('EVICT_INACTIVE_FINAL_REPORT', report);
|
2020-09-29 20:34:51 +08:00
|
|
|
}));
|
2019-06-12 22:18:58 +08:00
|
|
|
});
|