|
|
|
|
|
import unzipper from "unzipper"; |
|
import fs from "node:fs" |
|
import request from "request" |
|
import clc from "cli-color"; |
|
const FILE = 'd:/tmp/version.txt' |
|
|
|
/** |
|
* Extract version |
|
* @param {string} data |
|
* @returns version |
|
* @example getVersion("https://s3.ap-southeast-1.amazonaws.com/iov-mapdata.soimt.com/mapdata/eu/te/23Q4_EU_20240111021553_p/maps.zip") |
|
*/ |
|
function getVersion(data) { |
|
const regex = /\/(2[^\/]+)\//gm; |
|
let m = regex.exec(data) |
|
if (m !== null && m.length > 0) { |
|
return m[1] |
|
} |
|
return undefined |
|
|
|
} |
|
if (!process.env.VIN) { |
|
console.log(`${clc.red("Please set VIN env variable ex: set/export VIN=LSJWH409XXXXXX")} `) |
|
} |
|
let TIMEOUT=60 |
|
if (process.argv.length > 2) { |
|
TIMEOUT = parseInt(process.argv[2]) |
|
} |
|
|
|
let response = await fetch(`https://iov-mapmg.soimt.com/api/mapdata/getMapdataInfoOfVehicle?vin=${process.env.VIN}`, { |
|
"credentials": "include", |
|
"headers": { |
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0", |
|
"Accept": "application/json, text/plain, */*", |
|
"Accept-Language": "en", |
|
"Authorization": "Basic c2FiZXI6c2FiZXJfc2VjcmV0", |
|
"Sec-Fetch-Dest": "empty", |
|
"Sec-Fetch-Mode": "cors", |
|
"Sec-Fetch-Site": "same-origin", |
|
"Pragma": "no-cache", |
|
"Cache-Control": "no-cache" |
|
}, |
|
"referrer": "https://iov-mapmg.soimt.com/", |
|
"method": "POST", |
|
"mode": "cors" |
|
}); |
|
const result = await response.json(); |
|
const targetVersion = result.data.packageName //getVersion(result.data.packageUrl) |
|
if (targetVersion) { |
|
console.log(`${clc.green.underline("Target version:")} ${clc.blue(targetVersion)}`) |
|
const VNUrl = `https://iov-mapmg.soimt.com/api${result.data.vnFileUrl}` |
|
|
|
//Download VN file |
|
console.log(`${clc.green.underline("Downloading VN:")} ${clc.blue(VNUrl)}`) |
|
request.get(VNUrl) |
|
.pipe(fs.createWriteStream("VN.txt")); |
|
|
|
//Download maps |
|
console.log(`${clc.green.underline("Downloading map:")} ${clc.blue(result.data.packageUrl)}`) |
|
request.get(result.data.packageUrl) |
|
.pipe(unzipper.ParseOne('version\.txt', { forceStream: true })) |
|
.pipe(fs.createWriteStream(FILE)); |
|
} |
|
|
|
setTimeout(() => { |
|
console.log(fs.readFileSync(FILE).toString()) |
|
process.exit(0) |
|
}, TIMEOUT * 1000) |