From bf2a8b3bc0329c676dbe319f3d87b2d00d1dc492 Mon Sep 17 00:00:00 2001 From: BurnyLlama Date: Mon, 1 Nov 2021 22:20:13 +0100 Subject: [PATCH] Moved decodeMsgpack to seprate file. --- libs/database/decodeMsgpack.js | 21 +++++++++++++++++++++ libs/database/tasks.js | 21 +-------------------- 2 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 libs/database/decodeMsgpack.js diff --git a/libs/database/decodeMsgpack.js b/libs/database/decodeMsgpack.js new file mode 100644 index 0000000..47f1a8b --- /dev/null +++ b/libs/database/decodeMsgpack.js @@ -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 +} diff --git a/libs/database/tasks.js b/libs/database/tasks.js index 93c69f6..93ccbfc 100644 --- a/libs/database/tasks.js +++ b/libs/database/tasks.js @@ -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...