2021-07-07 05:38:56 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2024-08-02 12:27:31 -04:00
|
|
|
const { ObjectId } = require('mongodb-legacy')
|
2019-09-26 08:42:49 -04:00
|
|
|
const { Project } = require('../app/src/models/Project')
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const { image, projectIds } = parseArgs()
|
|
|
|
await updateImage(image, projectIds)
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseArgs() {
|
|
|
|
if (process.argv.length < 4) {
|
|
|
|
printUsage()
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
const image = parseImage(process.argv[2])
|
|
|
|
const projectIds = parseProjectIds(process.argv.slice(3))
|
|
|
|
return { image, projectIds }
|
|
|
|
}
|
|
|
|
|
|
|
|
function printUsage() {
|
|
|
|
console.error('Usage: node set_tex_live_image.js <image> <projectId> ...')
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseImage(image) {
|
|
|
|
const allowedImageNames = Settings.allowedImageNames.map(x => x.imageName)
|
|
|
|
if (!allowedImageNames.includes(image)) {
|
|
|
|
console.error(`Unknown image: ${image}`)
|
|
|
|
console.error('Please use one of:')
|
|
|
|
for (const allowedImage of allowedImageNames) {
|
|
|
|
console.error(` - ${allowedImage}`)
|
|
|
|
}
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
return image
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseProjectIds(projectIds) {
|
|
|
|
const oids = []
|
|
|
|
for (const projectId of projectIds) {
|
|
|
|
let oid
|
|
|
|
try {
|
2023-12-18 05:54:01 -05:00
|
|
|
oid = new ObjectId(projectId)
|
2019-09-26 08:42:49 -04:00
|
|
|
} catch (err) {
|
|
|
|
console.error(`Invalid project id: ${projectId}`)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
oids.push(oid)
|
|
|
|
}
|
|
|
|
return oids
|
|
|
|
}
|
|
|
|
|
|
|
|
async function updateImage(image, projectIds) {
|
|
|
|
const res = await Project.updateMany(
|
2023-12-18 05:54:01 -05:00
|
|
|
{ _id: { $in: projectIds.map(id => new ObjectId(id)) } },
|
2019-09-26 08:42:49 -04:00
|
|
|
{ $set: { imageName: `quay.io/sharelatex/${image}` } }
|
|
|
|
).exec()
|
2023-02-28 08:26:18 -05:00
|
|
|
console.log(`Found ${res.matchedCount} out of ${projectIds.length} projects`)
|
|
|
|
console.log(`Modified ${res.modifiedCount} projects`)
|
2019-09-26 08:42:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
.then(() => {
|
|
|
|
process.exit()
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|