Compare commits

...

4 commits
main ... main

Author SHA1 Message Date
2b7255feb0 Update README.md 2025-01-09 02:14:24 +01:00
dca5f2e31a Update main.js 2025-01-09 02:11:27 +01:00
156e2ec79e Update main.js 2025-01-09 02:06:41 +01:00
6bf356e135 Update main.js 2025-01-09 02:04:28 +01:00
2 changed files with 15 additions and 3 deletions

View file

@ -10,4 +10,12 @@ node main.js
``` ```
## ENV structure
```
USER_TOKEN=token
INSTANCE_URL=https://example.com
PERIOD=int // Time in days
```
License: MIT License: MIT

10
main.js
View file

@ -8,6 +8,8 @@ if (!USER_TOKEN) {
process.exit(1); process.exit(1);
} }
const PERIOD = process.env.PERIOD; // Time in days: int
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`;
@ -49,14 +51,16 @@ async function main() {
const users = response.data; const users = response.data;
const now = new Date(); const now = new Date();
const fiveDaysAgo = new Date(now - 5 * 24 * 60 * 60 * 1000); const timeAgo = new Date(now - PERIOD * 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 5 days)`); console.log(`Found ${usersToDelete.length} users matching criteria (no posts, not updated, and older than 5 days)`);