Last active
November 8, 2023 06:00
-
-
Save haubar/a3e1a690f0220ec4a8790dfb3b413568 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios') | |
const qs = require('qs') | |
exports.cars = async(req, res) => { | |
if(req.query.code){ | |
return getdetail(req, res) | |
} | |
return getlist(req, res) | |
} | |
const getUrl = async(url, data='', headers='', method='GET') => { | |
headers = headers ? headers : {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'} | |
const options = { | |
method: method, | |
headers: headers, | |
data: data, | |
url | |
} | |
// console.log(options) | |
return await axios(options) | |
.then(async (res) => { | |
return res.data | |
}).catch(async (err) => { | |
await setTimeout(() => console.log(' To Reconnect !'), 6000); | |
throw new Error(err) | |
}) | |
} | |
const getdetail = async(req, res) => { | |
let id = req.query.code | |
let headers = {'User-Agent':process.env.COMMAND_WGET_HEADER} | |
let url = process.env.CARS_CONTENT_URL.replace('%s', id) | |
let json = await getUrl(url, '', headers) | |
res.status(200).send(json) | |
} | |
const getlist = async(req, res) => { | |
let data = { | |
'page': req.query.page, | |
'perPage': req.query.perpage, | |
'prMn': req.query.prmn, | |
'prMx': req.query.prmx, | |
'rd': req.query.rd, | |
'stkTypId': req.query.stktypid, | |
'searchSource': req.query.searchsource, | |
'zc': req.query.zc, | |
'localVehicles': req.query.localvehicles, | |
'shippable-dealers-checkbox': req.query.shippable, | |
'sort': req.query.short, | |
'mdId': req.query.mdid, | |
'yrId': req.query.yrid, | |
'mkId': req.query.mkid, | |
'mlgId': req.query.mlgid, | |
'clrId': req.query.clrid, | |
'intClrId': req.query.intclrid, | |
'drvTrnId': req.query.drvtrnid, | |
'transTypeId': req.query.transtypeid, | |
'cylCntId': req.query.cylcntid, | |
'photoId': req.query.photoid, | |
'drCntId': req.query.drcntid, | |
'normFeatureId': req.query.normfeatureid, | |
'fuelTypeId': req.query.fueltypeid, | |
'cpoId': req.query.cpoid | |
} | |
let headers = {'User-Agent':process.env.COMMAND_WGET_HEADER} | |
let url = process.env.CARS_URL+qs.stringify(data) | |
let json = await getUrl(url, '', headers) | |
res.status(200).send(json) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment