Moved decodeMsgpack to seprate file.
This commit is contained in:
parent
c92d71c66f
commit
bf2a8b3bc0
21
libs/database/decodeMsgpack.js
Normal file
21
libs/database/decodeMsgpack.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import msgpack from '@msgpack/msgpack'
|
||||
import fs from 'fs'
|
||||
|
||||
|
||||
/**
|
||||
* This module parses the msgpack provided by DDNet...
|
||||
* @module db/decodeMsgpack
|
||||
*/
|
||||
export default function decodeMsgpack() {
|
||||
const data = fs.readFileSync(process.env.MSGPACK_PATH ?? 'data/players.msgpack')
|
||||
const decoded = msgpack.decodeMulti(data, { wrap: true })
|
||||
const order = ['categories', 'maps', 'totalPoints', 'pointsRanks', 'pointsThisWeek', 'pointsThisMonth', 'teamRankPoints', 'rankPoints', 'serverRanks']
|
||||
let final = {}
|
||||
|
||||
let i = 0
|
||||
for (const part of decoded) {
|
||||
final[order[i]] = part
|
||||
++i
|
||||
}
|
||||
return final
|
||||
}
|
|
@ -1,26 +1,7 @@
|
|||
import msgpack from '@msgpack/msgpack'
|
||||
import fs from 'fs'
|
||||
import decodeMsgpack from './decodeMsgpack.js'
|
||||
import { execMany } from './helper.js'
|
||||
|
||||
import { sqlite } from './init.js'
|
||||
|
||||
/**
|
||||
* This module parses the msgpack provided by DDNet...
|
||||
* @module db/decodeMsgpack
|
||||
*/
|
||||
export function decodeMsgpack() {
|
||||
const data = fs.readFileSync(process.env.MSGPACK_PATH ?? 'data/players.msgpack')
|
||||
const decoded = msgpack.decodeMulti(data, { wrap: true })
|
||||
const order = ['categories', 'maps', 'totalPoints', 'pointsRanks', 'pointsThisWeek', 'pointsThisMonth', 'teamRankPoints', 'rankPoints', 'serverRanks']
|
||||
let final = {}
|
||||
|
||||
let i = 0
|
||||
for (const part of decoded) {
|
||||
final[order[i]] = part
|
||||
++i
|
||||
}
|
||||
return final
|
||||
}
|
||||
|
||||
/**
|
||||
* This generates rankings for each map...
|
||||
|
|
Loading…
Reference in New Issue
Block a user