puzzle/scripts/fix_image.ts

24 lines
605 B
TypeScript
Raw Normal View History

2021-05-22 13:19:39 +02:00
import GameCommon from '../src/common/GameCommon'
import { logger } from '../src/common/Util'
import GameStorage from '../src/server/GameStorage'
2021-04-21 09:54:10 +02:00
const log = logger('fix_image.js')
function fix(gameId) {
2021-04-30 21:00:30 +02:00
GameStorage.loadGame(gameId)
2021-04-21 09:54:10 +02:00
let changed = false
let imgUrl = GameCommon.getImageUrl(gameId)
if (imgUrl.match(/^\/example-images\//)) {
log.log(`found bad imgUrl: ${imgUrl}`)
imgUrl = imgUrl.replace(/^\/example-images\//, '/uploads/')
GameCommon.setImageUrl(gameId, imgUrl)
changed = true
}
if (changed) {
2021-04-30 21:00:30 +02:00
GameStorage.persistGame(gameId)
2021-04-21 09:54:10 +02:00
}
}
fix(process.argv[2])