enable_writefull_without_autoCreatedAccount.mjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { db } from '../../app/src/infrastructure/mongodb.js'
  2. import mongodb from 'mongodb-legacy'
  3. import fs from 'node:fs'
  4. import { fileURLToPath } from 'node:url'
  5. import { scriptRunner } from '../lib/ScriptRunner.mjs'
  6. const { ObjectId } = mongodb
  7. async function main() {
  8. // search for file of users to force into auto load
  9. const userIdsPath = process.argv[2]
  10. const userIdsFile = fs.readFileSync(userIdsPath, 'utf8')
  11. let userIdsList = userIdsFile
  12. userIdsList = userIdsList
  13. .split('\n')
  14. .filter(id => id?.length)
  15. .map(id => new ObjectId(id))
  16. console.log(
  17. `enabling writefull with autoCreatedAccount:false for ${userIdsList.length} users`
  18. )
  19. // set them to writefull.enabled true, and autoCreatedAccount false which is the same state an auto-load account is placed in after their first load
  20. // not this does NOT call writefull's first load function for the user's account
  21. await db.users.updateMany(
  22. { _id: { $in: userIdsList } },
  23. {
  24. $set: {
  25. 'writefull.enabled': true,
  26. 'writefull.autoCreatedAccount': false,
  27. },
  28. }
  29. )
  30. }
  31. export default main
  32. if (fileURLToPath(import.meta.url) === process.argv[1]) {
  33. try {
  34. await scriptRunner(main)
  35. process.exit(0)
  36. } catch (error) {
  37. console.error({ error })
  38. process.exit(1)
  39. }
  40. }