store games in db

This commit is contained in:
Zutatensuppe 2021-07-12 01:28:14 +02:00
parent 126384e5bd
commit 4e528cc83d
14 changed files with 371 additions and 133 deletions

View file

@ -47,7 +47,7 @@ function fixOne(gameId: string) {
log.log(g.puzzle.info.image.title, imageRow.id)
GameStorage.persistGame(gameId)
GameStorage.persistGameToDb(db, gameId)
} else if (g.puzzle.info.image?.id) {
const imageId = g.puzzle.info.image.id
@ -55,7 +55,7 @@ function fixOne(gameId: string) {
log.log(g.puzzle.info.image.title, imageId)
GameStorage.persistGame(gameId)
GameStorage.persistGameToDb(db, gameId)
}
// fix log
@ -81,7 +81,7 @@ function fixOne(gameId: string) {
}
function fix() {
GameStorage.loadGames()
GameStorage.loadGamesFromDisk()
GameCommon.getAllGames().forEach((game: Game) => {
fixOne(game.id)
})

View file

@ -1,11 +1,16 @@
import GameCommon from '../src/common/GameCommon'
import { logger } from '../src/common/Util'
import Db from '../src/server/Db'
import { DB_FILE, DB_PATCHES_DIR } from '../src/server/Dirs'
import GameStorage from '../src/server/GameStorage'
const log = logger('fix_tiles.js')
const db = new Db(DB_FILE, DB_PATCHES_DIR)
db.patch(true)
function fix_tiles(gameId) {
GameStorage.loadGame(gameId)
GameStorage.loadGameFromDb(db, gameId)
let changed = false
const tiles = GameCommon.getPiecesSortedByZIndex(gameId)
for (let tile of tiles) {
@ -27,7 +32,7 @@ function fix_tiles(gameId) {
}
}
if (changed) {
GameStorage.persistGame(gameId)
GameStorage.persistGameToDb(db, gameId)
}
}

27
scripts/import_games.ts Normal file
View file

@ -0,0 +1,27 @@
import GameCommon from '../src/common/GameCommon'
import { Game } from '../src/common/Types'
import { logger } from '../src/common/Util'
import { DB_FILE, DB_PATCHES_DIR } from '../src/server/Dirs'
import Db from '../src/server/Db'
import GameStorage from '../src/server/GameStorage'
const log = logger('import_games.ts')
console.log(DB_FILE)
const db = new Db(DB_FILE, DB_PATCHES_DIR)
db.patch(true)
function run() {
GameStorage.loadGamesFromDisk()
GameCommon.getAllGames().forEach((game: Game) => {
if (!game.puzzle.info.image?.id) {
log.error(game.id + " has no image")
log.error(game.puzzle.info.image)
return
}
GameStorage.persistGameToDb(db, game.id)
})
}
run()