import crypto from "crypto"; import { User, UNSUB_CODE_SIZE } from "../lib/models.js"; import { knex } from "../lib/ormish.js"; export const description = "Updates users with no unsubkey, which can happen sometimes when manually adding people."; export const main = async () => { for(let u of await User.all({unsubscribe: false, unsubkey: ""})) { const key = crypto.randomBytes(UNSUB_CODE_SIZE).toString("hex"); console.log(u.id, key, "length", key.length); await User.update({id: u.id}, {unsubkey: key}); } knex.destroy(); }