38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
/*
|
|
This is not a server file, but a command system to migrate user IDs to MongoDB IDs.
|
|
|
|
Usage (in the root of the folder): node ./scripts/migrate-account-ids.js
|
|
This is not needed if you made your server past Apr 8, 2022 at 7pm.
|
|
|
|
After making your first admin user, you can kill users by going to their profile and clicking the button.
|
|
*/
|
|
|
|
const config = require("../config.json")
|
|
const {MongoClient} = require("mongodb");
|
|
const client = new MongoClient(config["db-url"], {useUnifiedTopology: true});
|
|
|
|
(async function() {
|
|
await client.connect();
|
|
let db = await client.db("mediahost");
|
|
let acdb = await db.collection("accounts")
|
|
let accs = await acdb.find({}).toArray();
|
|
let ups = db.collection("uploads");
|
|
|
|
for (let a in accs) {
|
|
if (!accs[a].id) return;
|
|
let id = accs[a].id;
|
|
let up = await ups.find({uploader: id}).toArray();
|
|
let nid = accs[a]._id;
|
|
|
|
for (let b in up) {
|
|
up[b].uploader = nid;
|
|
await ups.findOneAndReplace({id: up[b].id}, up[b]);
|
|
}
|
|
|
|
accs[a].id = undefined;
|
|
await acdb.findOneAndReplace({_id: accs[a]._id}, accs[a]);
|
|
}
|
|
|
|
console.log("Complete.");
|
|
process.exit();
|
|
})(); |