Ref #418 add the abandoned boards handling

Fix small bug with incorrect schema for the setting
Set both schedules to immediate: false
merge-requests/341/head
Thomas Lynch 2 years ago
parent 4db2c9f6f5
commit 05413d72c6
  1. 4
      controllers/forms/globalsettings.js
  2. 29
      db/boards.js
  3. 3
      lib/misc/socketio.js
  4. 8
      lib/redis/redis.js
  5. 24
      schedules/tasks/abandonedboards.js
  6. 2
      schedules/tasks/inactiveaccounts.js

@ -69,8 +69,8 @@ module.exports = {
return false;
}, expected: true, error: 'Invalid reverse image search links URL format, must be a link containing %s where the url param belongs.' },
{ result: numberBody(req.body.inactive_account_time), expected: true, error: 'Invalid inactive account time' },
{ result: numberBody(req.body.inactive_account_action, 0, 3), expected: true, error: 'Inactive account action must be a number from 0-3' },
{ result: numberBody(req.body.abandoned_board_action, 0, 2), expected: true, error: 'Abandoned board action must be a number from 0-2' },
{ result: numberBody(req.body.inactive_account_action, 0, 2), expected: true, error: 'Inactive account action must be a number from 0-2' },
{ result: numberBody(req.body.abandoned_board_action, 0, 3), expected: true, error: 'Abandoned board action must be a number from 0-3' },
{ result: lengthBody(req.body.global_announcement, 0, 10000), expected: false, error: 'Global announcement must not exceed 10000 characters' },
{ result: lengthBody(req.body.filters, 0, 50000), expected: false, error: 'Filter text cannot exceed 50000 characters' },
{ result: numberBody(req.body.filter_mode, 0, 2), expected: true, error: 'Filter mode must be a number from 0-2' },

@ -4,7 +4,8 @@ const Mongo = require(__dirname+'/db.js')
, cache = require(__dirname+'/../lib/redis/redis.js')
, dynamicResponse = require(__dirname+'/../lib/misc/dynamic.js')
, escapeRegExp = require(__dirname+'/../lib/input/escaperegexp.js')
, db = Mongo.db.collection('boards');
, db = Mongo.db.collection('boards')
, config = require(__dirname+'/../lib/misc/config.js');
module.exports = {
@ -309,6 +310,32 @@ module.exports = {
}
}).toArray();
},
getAbandoned: () => {
return db.find({
'webring': false,
'owner': null,
}).toArray();
},
unlistMany: (boards) => {
const update = {
'settings.unlistedLocal': true,
'settings.unlistedWebring': true,
};
if (config.get.abandonedBoardAction === 2) {
update['settings.lockMode'] = 2;
}
cache.srem('boards:listed', boards);
cache.del(boards.map(b => `board:${b}`));
return db.updateMany({
'_id': {
'$in': boards,
},
}, {
'$set': update,
});
},
count: (filter, showSensitive=false, webringSites=false) => {
const addedFilter = {};

@ -80,6 +80,9 @@ module.exports = {
},
emitRoom: (room, event, message) => {
if (!module.exports.io) {
return; //not initialized or in process that doesnt emit these events
}
module.exports.io.to(room).emit(event, message);
},

@ -77,9 +77,9 @@ module.exports = {
return sharedClient.smembers(key);
},
//remove an item from a set
srem: (key, value) => {
return sharedClient.srem(key, value);
//remove item from a set
srem: (key, values) => {
return sharedClient.srem(key, values);
},
//get random item from set
@ -89,7 +89,7 @@ module.exports = {
//delete value with key
del: (keyOrKeys) => {
if (Array.isArray(keyOrKeys)) {
if (Array.isArray(keyOrKeys)) {
return sharedClient.del(...keyOrKeys);
} else {
return sharedClient.del(keyOrKeys);

@ -4,7 +4,8 @@ const { debugLogs } = require(__dirname+'/../../configs/secrets.js')
, config = require(__dirname+'/../../lib/misc/config.js')
, Redis = require(__dirname+'/../../lib/redis/redis.js')
, { Boards } = require(__dirname+'/../../db/')
, timeUtils = require(__dirname+'/../../lib/converter/timeutils.js');
, timeUtils = require(__dirname+'/../../lib/converter/timeutils.js')
, deleteBoard = require(__dirname+'/../../models/forms/deleteboard.js');
module.exports = {
@ -14,7 +15,26 @@ module.exports = {
return;
}
//TODO: handle abandoned boards. 1=unlist, 2=unlist+lock, 3=delete
const abandonedBoards = await Boards.getAbandoned();
if (abandonedBoards.length === 0) {
return;
}
if (config.get.abandonedBoardAction <= 2) {
debugLogs && console.log(`Unlisting${config.get.abandonedBoardAction === 2 ? '+Locking' : ''} ${abandonedBoards.length} abandoned boards.`);
const abandonedURIs = abandonedBoards.map(b => b._id);
Boards.unlistMany(abandonedURIs);
} else { //must be 2
//run delete board model for each
debugLogs && console.log(`Deleting ${abandonedBoards.length} abandoned boards.`);
for (let board of abandonedBoards) {
try {
await deleteBoard(board._id, board);
} catch (err) {
debugLogs && console.log('Error deleting abandoned board:', err);
}
}
}
},

@ -92,7 +92,7 @@ module.exports = {
},
interval: timeUtils.DAY,
immediate: true,
immediate: false,
condition: 'inactiveAccountAction'
};

Loading…
Cancel
Save