patch_detector: refactor

This commit is contained in:
2026-02-28 09:28:13 +01:00
parent fe128c0848
commit ea27a0d6f8

View File

@@ -33,21 +33,19 @@ const CDRAGON_ASSETS = [
main() main()
async function main() { async function main() {
const client = await connectToDatabase()
const dbPatch = await getLatestPatchFromDatabase(client)
// In dev mode, get patch from database (the one we have match data for) // In dev mode, get patch from database (the one we have match data for)
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
console.log('Development mode: downloading cache for database patch') console.log('Development mode: downloading cache for database patch')
const client = await connectToDatabase()
const dbPatch = await getLatestPatchFromDatabase(client)
await client.close() await client.close()
if (dbPatch) { if (dbPatch) {
console.log('Latest patch in database: ' + dbPatch) console.log('Latest patch in database: ' + dbPatch)
await downloadAssets(dbPatch) await downloadAssets(dbPatch)
} else { } else {
console.log('No patch found in database, fetching latest from game...') console.log('No patch found in database!')
const latestPatch = await fetchLatestPatch()
console.log('Latest game patch: ' + latestPatch)
await downloadAssets(latestPatch)
} }
return return
} }
@@ -55,12 +53,12 @@ async function main() {
// Production mode: check database and update if new patch // Production mode: check database and update if new patch
const newPatch = await fetchLatestPatch() const newPatch = await fetchLatestPatch()
console.log('Latest patch is: ' + newPatch) console.log('Latest patch is: ' + newPatch)
const client = await connectToDatabase()
const newDate = new Date() const newDate = new Date()
if (!(await compareLatestSavedPatch(client, newPatch, newDate))) { if (!(await compareLatestSavedPatch(client, newPatch, newDate))) {
await downloadAssets(newPatch) await downloadAssets(newPatch)
} }
await client.close() await client.close()
} }