Compare commits

..

5 commits
main ... main

Author SHA1 Message Date
9dc4faa985 Update README.md 2025-01-05 16:32:08 +01:00
6846adc169 Update package.json 2025-01-05 16:31:24 +01:00
2b21f02c11 Update README.md 2025-01-05 16:30:49 +01:00
563d308c3c Update main.js 2025-01-05 16:30:29 +01:00
3075db223e Update README.md 2025-01-05 16:29:29 +01:00
3 changed files with 17 additions and 33 deletions

File diff suppressed because one or more lines are too long

17
main.js
View file

@ -8,8 +8,7 @@ if (!USER_TOKEN) {
process.exit(1); process.exit(1);
} }
const PERIOD = process.env.PERIOD; // Time in days: int console.log("Spierdalaj");
const INSTANCE_URL = process.env.INSTANCE_URL; const INSTANCE_URL = process.env.INSTANCE_URL;
const API_BASE = `${INSTANCE_URL}/api`; const API_BASE = `${INSTANCE_URL}/api`;
@ -51,19 +50,17 @@ async function main() {
const users = response.data; const users = response.data;
const now = new Date(); const now = new Date();
const timeAgo = new Date(now - PERIOD * 24 * 60 * 60 * 1000); const fiveDaysAgo = new Date(now - 5 * 24 * 60 * 60 * 1000);
const usersToDelete = users.filter(user => { const usersToDelete = users.filter(user => {
const createdAt = new Date(user.createdAt); const createdAt = new Date(user.createdAt);
const updatedAt = new Date(user.updatedAt); const updatedAt = new Date(user.updatedAt);
const excludedUsers = ['instance.actor', 'relay.actor']; return user.notesCount === 0 &&
return user.notesCount === 0 && createdAt < fiveDaysAgo &&
createdAt < timeAgo && updatedAt < fiveDaysAgo;
updatedAt < timeAgo &&
!excludedUsers.includes(user.username)
}); });
console.log(`Found ${usersToDelete.length} users matching criteria (no posts, not updated, and older than ${PERIOD} days)`); console.log(`Found ${usersToDelete.length} users matching criteria (no posts, not updated, and older than 5 days)`);
console.log('\nUsers to be deleted:'); console.log('\nUsers to be deleted:');
usersToDelete.forEach(user => { usersToDelete.forEach(user => {
@ -75,7 +72,7 @@ async function main() {
console.log(); console.log();
const confirmed = await askForConfirmation(`Are you sure you want to delete ${usersToDelete.length} users?`); const confirmed = await askForConfirmation(`Are you sure you want to delete ${usersToDelete.length} users?`);
if (!confirmed) { if (!confirmed) {
console.log('Operation cancelled by user'); console.log('Operation cancelled by user');
rl.close(); rl.close();

View file

@ -1,5 +1,5 @@
{ {
"dependencies": { "dependencies": { // Kus
"axios": "^1.7.8", "axios": "^1.7.8",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"readline": "^1.3.0" "readline": "^1.3.0"