enable_writefull_without_autoCreatedAccount.mjs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. const { ObjectId } = mongodb
  6. async function main() {
  7. // search for file of users to force into auto load
  8. const userIdsPath = process.argv[2]
  9. const userIdsFile = fs.readFileSync(userIdsPath, 'utf8')
  10. let userIdsList = userIdsFile
  11. userIdsList = userIdsList
  12. .split('\n')
  13. .filter(id => id?.length)
  14. .map(id => new ObjectId(id))
  15. console.log(
  16. `enabling writefull with autoCreatedAccount:false for ${userIdsList.length} users`
  17. )
  18. // 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
  19. // not this does NOT call writefull's first load function for the user's account
  20. await db.users.updateMany(
  21. { _id: { $in: userIdsList } },
  22. {
  23. $set: {
  24. 'writefull.enabled': true,
  25. 'writefull.autoCreatedAccount': false,
  26. },
  27. }
  28. )
  29. }
  30. export default main
  31. if (fileURLToPath(import.meta.url) === process.argv[1]) {
  32. try {
  33. await main()
  34. process.exit(0)
  35. } catch (error) {
  36. console.error({ error })
  37. process.exit(1)
  38. }
  39. }