UNPKG

7daystodie-api-wrapper

Version:
37 lines (31 loc) 944 B
/* eslint-env node */ const ipInt = require('ip-to-int'); const fs = require('fs'); const path = require('path'); const JSON5 = require("json5"); const maxIP = ipInt('255.255.255.255').toInt(); const tapesDir = path.join(__dirname, '..', 'test', 'tapes'); const files = fs.readdirSync(tapesDir); const replaceIP = (obj) => { if (!obj) { return; } if (typeof obj !== 'object') { return; } if (obj.ip) { obj.ip = ipInt(obj.steamid.replace('Steam_', '') % maxIP).toIP(); } for (const subObj of Object.values(obj)) { replaceIP(subObj); } }; for (const file of files) { const fullFilename = path.join(tapesDir, file); const data = JSON5.parse(fs.readFileSync(fullFilename).toString()); replaceIP(data); if (data.meta && data.meta.host) { data.meta.host = 'https://7d2d.csmm.app'; } fs.writeFileSync(fullFilename, JSON5.stringify(data, null, 4)); }