Archived
2

changelog delete

This commit is contained in:
VLE2FE 2020-08-31 16:20:22 +02:00
parent 8f88023da2
commit d28e9a1cc9
3 changed files with 32 additions and 13 deletions

32
package-lock.json generated
View File

@ -385,14 +385,6 @@
"integrity": "sha1-n7OjzzEyMoFR81PeRjLgHlIQK+o=", "integrity": "sha1-n7OjzzEyMoFR81PeRjLgHlIQK+o=",
"dev": true "dev": true
}, },
"@szmarczak/http-timer": {
"version": "4.0.5",
"resolved": "https://r.cnpmjs.org/@szmarczak/http-timer/download/@szmarczak/http-timer-4.0.5.tgz",
"integrity": "sha1-v71QIR6d+lG6B9pYoUzf0zMgUVI=",
"requires": {
"defer-to-connect": "^2.0.0"
}
},
"@types/bcrypt": { "@types/bcrypt": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://r.cnpmjs.org/@types/bcrypt/download/@types/bcrypt-3.0.0.tgz", "resolved": "https://r.cnpmjs.org/@types/bcrypt/download/@types/bcrypt-3.0.0.tgz",
@ -1297,11 +1289,6 @@
"strip-bom": "^4.0.0" "strip-bom": "^4.0.0"
} }
}, },
"defer-to-connect": {
"version": "2.0.0",
"resolved": "https://r.cnpmjs.org/defer-to-connect/download/defer-to-connect-2.0.0.tgz",
"integrity": "sha1-g9axmdsEFZOshNeBtSIjCMz0wsE="
},
"define-properties": { "define-properties": {
"version": "1.1.3", "version": "1.1.3",
"resolved": "https://r.cnpmjs.org/define-properties/download/define-properties-1.1.3.tgz", "resolved": "https://r.cnpmjs.org/define-properties/download/define-properties-1.1.3.tgz",
@ -2603,6 +2590,15 @@
"resolved": "https://r.cnpmjs.org/nocache/download/nocache-2.1.0.tgz", "resolved": "https://r.cnpmjs.org/nocache/download/nocache-2.1.0.tgz",
"integrity": "sha1-Egyf/sQ7Vymx1d6IzXGqdaC6SR8=" "integrity": "sha1-Egyf/sQ7Vymx1d6IzXGqdaC6SR8="
}, },
"node-cron": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/node-cron/-/node-cron-2.0.3.tgz",
"integrity": "sha512-eJI+QitXlwcgiZwNNSRbqsjeZMp5shyajMR81RZCqeW0ZDEj4zU9tpd4nTh/1JsBiKbF8d08FCewiipDmVIYjg==",
"requires": {
"opencollective-postinstall": "^2.0.0",
"tz-offset": "0.0.1"
}
},
"node-environment-flags": { "node-environment-flags": {
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://r.cnpmjs.org/node-environment-flags/download/node-environment-flags-1.0.6.tgz", "resolved": "https://r.cnpmjs.org/node-environment-flags/download/node-environment-flags-1.0.6.tgz",
@ -2958,6 +2954,11 @@
"resolved": "https://r.cnpmjs.org/openapi-types/download/openapi-types-1.3.5.tgz", "resolved": "https://r.cnpmjs.org/openapi-types/download/openapi-types-1.3.5.tgz",
"integrity": "sha1-ZxjPvIV/5sbxRx9lsyveu5wQzkA=" "integrity": "sha1-ZxjPvIV/5sbxRx9lsyveu5wQzkA="
}, },
"opencollective-postinstall": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz",
"integrity": "sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q=="
},
"os-tmpdir": { "os-tmpdir": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://r.cnpmjs.org/os-tmpdir/download/os-tmpdir-1.0.2.tgz", "resolved": "https://r.cnpmjs.org/os-tmpdir/download/os-tmpdir-1.0.2.tgz",
@ -3936,6 +3937,11 @@
"integrity": "sha1-mNYApevcOPQMsndSLxLcgA6eJfo=", "integrity": "sha1-mNYApevcOPQMsndSLxLcgA6eJfo=",
"dev": true "dev": true
}, },
"tz-offset": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/tz-offset/-/tz-offset-0.0.1.tgz",
"integrity": "sha512-kMBmblijHJXyOpKzgDhKx9INYU4u4E1RPMB0HqmKSgWG8vEcf3exEfLh4FFfzd3xdQOw9EuIy/cP0akY6rHopQ=="
},
"undefsafe": { "undefsafe": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://r.cnpmjs.org/undefsafe/download/undefsafe-2.0.3.tgz", "resolved": "https://r.cnpmjs.org/undefsafe/download/undefsafe-2.0.3.tgz",

View File

@ -38,6 +38,7 @@
"json2csv": "^5.0.1", "json2csv": "^5.0.1",
"lodash": "^4.17.15", "lodash": "^4.17.15",
"mongoose": "^5.8.7", "mongoose": "^5.8.7",
"node-cron": "^2.0.3",
"swagger-ui-dist": "^3.30.2" "swagger-ui-dist": "^3.30.2"
}, },
"devDependencies": { "devDependencies": {

View File

@ -2,12 +2,14 @@ import mongoose from 'mongoose';
import cfenv from 'cfenv'; import cfenv from 'cfenv';
import _ from 'lodash'; import _ from 'lodash';
import ChangelogModel from './models/changelog'; import ChangelogModel from './models/changelog';
import cron from 'node-cron';
// database urls, prod db url is retrieved automatically // database urls, prod db url is retrieved automatically
const TESTING_URL = 'mongodb://localhost/dfopdb_test'; const TESTING_URL = 'mongodb://localhost/dfopdb_test';
const DEV_URL = 'mongodb://localhost/dfopdb'; const DEV_URL = 'mongodb://localhost/dfopdb';
const debugging = true; const debugging = true;
const changelogKeepDays = 30; // days to keep the changelog
if (process.env.NODE_ENV !== 'production' && debugging) { if (process.env.NODE_ENV !== 'production' && debugging) {
mongoose.set('debug', true); // enable mongoose debug mongoose.set('debug', true); // enable mongoose debug
@ -78,6 +80,16 @@ export default class db {
this.state.db = mongoose.connection; this.state.db = mongoose.connection;
done(); done();
}); });
if (mode !== 'test') { // clear old changelog regularly
cron.schedule('0 0 * * *', () => {
ChangelogModel.deleteMany({_id: {$lt: // id from time
Math.floor(new Date().getTime() / 1000 - changelogKeepDays * 24 * 60 * 60).toString(16) + '0000000000000000'
}}).log({method: 'scheduled changelog delete', url: '', authDetails: {}}).lean().exec(err => {
if (err) console.error(err);
});
});
}
} }
static disconnect (done) { static disconnect (done) {