Skip to content

Instantly share code, notes, and snippets.

@malys
Last active May 24, 2024 09:56
Show Gist options
  • Save malys/b5b9f281ed5442ff7eeb23660762df45 to your computer and use it in GitHub Desktop.
Save malys/b5b9f281ed5442ff7eeb23660762df45 to your computer and use it in GitHub Desktop.
[SAIC Map update] check version of maps update without download 15Go Zip file #saic #map
/node_modules/
/package-lock.json

saicMap

Get latest version of MG4 Luxury map

Installation

npm install

Usage

VIN=XXXXX && npm run download

License

MIT

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)
{
"name": "saicMap",
"version": "1.0.0",
"description": "Download VN.txt and get map version",
"main": "index.mjs",
"scripts": {
"download": "node index.mjs"
},
"author": "",
"license": "ISC",
"dependencies": {
"cli-color": "^2.0.4",
"request": "^2.88.2",
"unzipper": "^0.11.3"
}
}
del d:\tmp\version.txt
set TIMEOUT=60
node B:\prog\code\saicMG4\map\index.mjs %TIMEOUT%
ping 127.0.0.1 -n %TIMEOUT% > nul
start notepad d:\tmp\version.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment