Started server-wide legacy cytube/fore.st toke count ingestion.
This commit is contained in:
parent
bb2a1369a3
commit
a231c8fc4c
|
|
@ -10,6 +10,7 @@
|
||||||
"altchaSecret": "CHANGE_ME",
|
"altchaSecret": "CHANGE_ME",
|
||||||
"ipSecret": "CHANGE_ME",
|
"ipSecret": "CHANGE_ME",
|
||||||
"migrate": false,
|
"migrate": false,
|
||||||
|
"dropLegacyTokes": false,
|
||||||
"ssl":{
|
"ssl":{
|
||||||
"cert": "./server.cert",
|
"cert": "./server.cert",
|
||||||
"key": "./server.key"
|
"key": "./server.key"
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,10 @@
|
||||||
//WARNING: The migration folder is cleared after server boot, whether or not a migration took place or this option is enabled.
|
//WARNING: The migration folder is cleared after server boot, whether or not a migration took place or this option is enabled.
|
||||||
//Keep your backups in a safe place, preferably a machine that DOESN'T have open inbound ports exposed to the internet/a publically accessible reverse proxy!
|
//Keep your backups in a safe place, preferably a machine that DOESN'T have open inbound ports exposed to the internet/a publically accessible reverse proxy!
|
||||||
"migrate": false,
|
"migrate": false,
|
||||||
|
//Drops all legacy tokes out of the statistics file since doing so manually from mongosh is a lot of typing out obnoxious parentha-glyphics.
|
||||||
|
//Requires migration to be disabled before it takes effect.
|
||||||
|
//WARNING: this does NOT affect user toke counts, migrated or otherwise. Use carefully!
|
||||||
|
"dropLegacyTokes": false,
|
||||||
//SSL cert and key locations
|
//SSL cert and key locations
|
||||||
"ssl":{
|
"ssl":{
|
||||||
"cert": "./server.cert",
|
"cert": "./server.cert",
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ statSchema.statics.getTokeCommandCounts = async function(){
|
||||||
count.set(command, 1);
|
count.set(command, 1);
|
||||||
}else{
|
}else{
|
||||||
//Set it to ++curCount
|
//Set it to ++curCount
|
||||||
count.set(command, ++curCount);
|
count.set(command, curCount + 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -196,4 +196,100 @@ statSchema.statics.getTokeCommandCounts = async function(){
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ingests legacy tokes handed over by the migration model
|
||||||
|
* @param {Array} rawLegacyTokes - List of strings containing contents of legacy cytube/fore.st toke logs
|
||||||
|
*/
|
||||||
|
statSchema.statics.ingestLegacyTokes = async function(rawLegacyTokes){
|
||||||
|
//If migration is disabled
|
||||||
|
if(!config.migrate){
|
||||||
|
//BAIL!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
const statDB = await this.getStats();
|
||||||
|
|
||||||
|
//For each toke log
|
||||||
|
for(const tokeLog of rawLegacyTokes){
|
||||||
|
//Split and iterate toke log by new line
|
||||||
|
for(const tokeLine of tokeLog.split('\n')){
|
||||||
|
//Ensure line is a valid toke log line (this will break if your tokes take place after 12:46:40PM on Nov 20th 2286... Or before 21:46:40 Sep 08 2001)
|
||||||
|
//You'll probably want to have migrated from cytube/fore.st to canopy by then :)
|
||||||
|
//Also splits tokers array off for easier processing
|
||||||
|
const splitToke = tokeLine.match(/^\[.+\]|,[0-9]{1,4},|[0-9]{13}$/g)
|
||||||
|
if(splitToke != null){
|
||||||
|
|
||||||
|
//Create empty tokers map
|
||||||
|
const toke = new Map();
|
||||||
|
|
||||||
|
//Add qoutes around strings in the tokers line
|
||||||
|
let tokersLine = splitToke[0].replaceAll('[', '["');
|
||||||
|
tokersLine = tokersLine.replaceAll(']','"]');
|
||||||
|
tokersLine = tokersLine.replaceAll(',','","');
|
||||||
|
|
||||||
|
//Force feed doctored line into the JSON parser, and iterate by the array it shits out
|
||||||
|
for(const toker of JSON.parse(tokersLine)){
|
||||||
|
toke.set(toker,"Legacy Tokes");
|
||||||
|
}
|
||||||
|
|
||||||
|
const date = new Date(Number(splitToke[2]));
|
||||||
|
|
||||||
|
//Push toke on to statDB
|
||||||
|
statDB.tokes.push({
|
||||||
|
toke,
|
||||||
|
date
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Adding legacy toke: ${tokersLine} from: ${date.toLocaleString()}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Save toke to file
|
||||||
|
await statDB.save();
|
||||||
|
|
||||||
|
console.log("Legacy tokes commited to server-wide database statistics file!");
|
||||||
|
}catch(err){
|
||||||
|
return loggerutils.localexceptionhandler(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
statSchema.statics.dropLegacyTokes = async function(){
|
||||||
|
try{
|
||||||
|
//If legacy toke dropping is disabled or migration is enabled
|
||||||
|
if(!config.dropLegacyTokes || config.migrate){
|
||||||
|
//return
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//pull stat doc
|
||||||
|
const statDB = await this.getStats();
|
||||||
|
|
||||||
|
//Create temporary toke array
|
||||||
|
const tokes = [];
|
||||||
|
|
||||||
|
//Iterate through server toke history
|
||||||
|
for(const toke of statDB.tokes){
|
||||||
|
//If it's not a legacy toke
|
||||||
|
if(Array.from(toke.toke)[0][1] != "Legacy Tokes"){
|
||||||
|
//Add it to the temp array
|
||||||
|
tokes.push(toke);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Replace the server-wide toke log with our newly doctored one
|
||||||
|
statDB.tokes = tokes;
|
||||||
|
|
||||||
|
//Save the stat document
|
||||||
|
statDB.save();
|
||||||
|
|
||||||
|
//Tell of our success
|
||||||
|
console.log("Removed migration tokes!");
|
||||||
|
}catch(err){
|
||||||
|
return loggerutils.localexceptionhandler(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = mongoose.model("statistics", statSchema);
|
module.exports = mongoose.model("statistics", statSchema);
|
||||||
|
|
@ -24,6 +24,7 @@ const {mongoose} = require('mongoose');
|
||||||
const config = require('../../../config.json');
|
const config = require('../../../config.json');
|
||||||
const {userModel} = require('../user/userSchema');
|
const {userModel} = require('../user/userSchema');
|
||||||
const permissionModel = require('../permissionSchema');
|
const permissionModel = require('../permissionSchema');
|
||||||
|
const statModel = require('../statSchema');
|
||||||
const loggerUtils = require('../../utils/loggerUtils');
|
const loggerUtils = require('../../utils/loggerUtils');
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -77,6 +78,7 @@ migrationSchema.statics.ingestLegacyDump = async function(){
|
||||||
try{
|
try{
|
||||||
//If migration is disabled
|
//If migration is disabled
|
||||||
if(!config.migrate){
|
if(!config.migrate){
|
||||||
|
statModel.dropLegacyTokes();
|
||||||
//BAIL!
|
//BAIL!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +142,10 @@ migrationSchema.statics.ingestLegacyDump = async function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
//Ingest toke maps
|
//Ingest toke maps
|
||||||
this.ingestTokeMaps(tokeMaps);
|
await this.ingestTokeMaps(tokeMaps);
|
||||||
|
|
||||||
|
//Pass toke logs over to the stat model for further ingestion
|
||||||
|
await statModel.ingestLegacyTokes(tokeLogs);
|
||||||
}catch(err){
|
}catch(err){
|
||||||
return loggerUtils.localExceptionHandler(err);
|
return loggerUtils.localExceptionHandler(err);
|
||||||
}
|
}
|
||||||
|
|
@ -281,7 +286,7 @@ migrationSchema.statics.ingestTokeMaps = async function(rawTokeMaps){
|
||||||
console.log(`${toker[1]} tokes injected into user profile ${toker[0]}!`);
|
console.log(`${toker[1]} tokes injected into user profile ${toker[0]}!`);
|
||||||
}
|
}
|
||||||
}catch(err){
|
}catch(err){
|
||||||
return loggerUtils.localExceptionHandler(err);
|
return loggerutils.localexceptionhandler(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. %>
|
||||||
</span>
|
</span>
|
||||||
<div class="profile-item nested-dynamic-container" id="profile-tokes">
|
<div class="profile-item nested-dynamic-container" id="profile-tokes">
|
||||||
<% profile.tokes.forEach((count, toke) => { %>
|
<% profile.tokes.forEach((count, toke) => { %>
|
||||||
<p class="profile-item profile-toke" id='profile-tokes<%-toke%>'>!<%- toke %>: <%- count %></p>
|
<p class="profile-item profile-toke" id='profile-tokes<%-toke%>'><%- toke == "Legacy Tokes" ? '<br>' : '!' %><%- toke %>: <%- count %></p>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
</div>
|
</div>
|
||||||
Loading…
Reference in a new issue