auto delete accounts after set time

This commit is contained in:
jusax23 2023-04-06 13:55:21 +02:00
parent 10760e77f2
commit 76d314ec00
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
6 changed files with 36 additions and 4 deletions

View file

@ -18,6 +18,7 @@ export const deleteAccount: Act = {
client.state = STATE.no;
await update(accounts)
.set(accounts.deleted, 1)
.set(accounts.deletedTime, uts())
.where(eq(accounts.accID, client.accID))
.query(db);
aws("ok", "");

View file

@ -20,6 +20,7 @@ import { activatePost, addPostMethods } from "./api/post.js";
import { activateWS, closeWebSocket, wsOnConnection } from "./api/ws.js";
import { startUpdateCert } from "./server/serverCerts.js";
import { wait } from "./sys/tools.js";
import { startChecks } from "./server/checks.js";
global.provideLog = 10;
@ -70,6 +71,8 @@ nman.addShutdownTask(() => new Promise(async (res, rej) => {
if (serverclose != null) {
serverclose.keepAliveTimeout = 100;
serverclose.close(() => res());
} else {
res();
}
}), 10000);
@ -125,5 +128,6 @@ async function complete_loaded() {
}
activatePost();
activateWS();
startChecks();
log("Server", 'Listening...');
}

17
src/server/checks.ts Normal file
View file

@ -0,0 +1,17 @@
import { and, le, remove } from "dblang";
import { addShutdownTask } from "nman";
import { accounts, db } from "../sys/db.js"
import { uts } from "../sys/tools.js";
import { oConf } from "../sys/config.js";
export function startChecks() {
let i1 = setInterval(async () => {
await remove(accounts)
.where(and(
accounts.deleted,
le(accounts.deletedTime, uts() - oConf.get("Settings", "deletedAccountKeepSec"))
)).query(db);
}, 60000);
addShutdownTask(() => clearInterval(i1), 500);
}

View file

@ -256,8 +256,12 @@ const outbag = async () => {
name: "defaultViewable",
message: "Should outbag accounts be viewable by default?",
initial: oConf.get("Settings", "defaultViewable"),
},
}, {
type: "number",
name: "deletedAccountKeepSec",
message: "Please enter the number of days a deleted Account is being save until final deletion!",
initial: oConf.get("Settings", "deletedAccountKeepSec") / 60 / 60 / 24
}
]);
if (
resp.maxUsers == null
@ -265,6 +269,7 @@ const outbag = async () => {
|| resp.defaultMaxRoomSize == null
|| resp.defaultMaxUsersPerRoom == null
|| resp.defaultViewable == null
|| resp.deletedAccountKeepSec == null
) {
warn("Setup", "You have to provide all informations!");
return false;
@ -285,6 +290,7 @@ const outbag = async () => {
oConf.set("Settings", "defaultMaxRoomSize", resp.defaultMaxRoomSize);
oConf.set("Settings", "defaultMaxUsersPerRoom", resp.defaultMaxUsersPerRoom);
oConf.set("Settings", "defaultViewable", resp.defaultViewable);
oConf.set("Settings", "deletedAccountKeepSec", Math.round(resp.deletedAccountKeepSec * 60 * 60 * 24));
oConf.save();
return true;

View file

@ -26,7 +26,8 @@ const conf_struct = {
defaultMaxRooms: { type: "number", default: 3, env: "OUTBAG_DEFAULT_MAX_ROOMS" },//Infinity = -1
defaultMaxRoomSize: { type: "number", default: 10000, env: "OUTBAG_DEFAULT_MAX_ROOMS_SIZE" },//Infinity = -1
defaultMaxUsersPerRoom: { type: "number", default: 5, env: "OUTBAG_DEFAULT_MAX_USERS_PER_ROOM" },//Infinity = -1
defaultViewable: { type: "boolean", default: false, env: "OUTBAG_DEFAULT_VIEWABLE" }
defaultViewable: { type: "boolean", default: false, env: "OUTBAG_DEFAULT_VIEWABLE" },
deletedAccountKeepSec: { type: "number", default: 60 * 60 * 24 * 20, env: "OUTBAG_DEL_ACCOUNT_KEEP_SEC" },
}
};

View file

@ -58,6 +58,7 @@ accounts.addAttributes({
viewable: { type: BOOL, default: false },
deleted: { type: BOOL, default: false },
deletedTime: { type: BIGINT, default: 0 },
maxRooms: { type: INT },
maxRoomSize: { type: INT },
@ -117,7 +118,9 @@ rooms.addAttributes({
owner: {
type: INT,
foreignKey: {
link: accounts.accID
link: accounts.accID,
onDelete: onAction.cascade,
onUpdate: onAction.cascade
}
},
rights: { type: INT, default: 0b11111 },