add eslint

This commit is contained in:
binaryify
2019-08-16 10:57:31 +08:00
parent 629533e674
commit b98d611989
143 changed files with 1166 additions and 1125 deletions
+23 -23
View File
@@ -7,44 +7,44 @@ const publicKey = '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBi
const eapiKey = 'e82ckenh8dichen8'
const aesEncrypt = (buffer, mode, key, iv) => {
const cipher = crypto.createCipheriv('aes-128-' + mode, key, iv)
return Buffer.concat([cipher.update(buffer),cipher.final()])
const cipher = crypto.createCipheriv('aes-128-' + mode, key, iv)
return Buffer.concat([cipher.update(buffer), cipher.final()])
}
const rsaEncrypt = (buffer, key) => {
buffer = Buffer.concat([Buffer.alloc(128 - buffer.length), buffer])
return crypto.publicEncrypt({key: key, padding: crypto.constants.RSA_NO_PADDING}, buffer)
buffer = Buffer.concat([Buffer.alloc(128 - buffer.length), buffer])
return crypto.publicEncrypt({key: key, padding: crypto.constants.RSA_NO_PADDING}, buffer)
}
const weapi = (object) => {
const text = JSON.stringify(object)
const secretKey = crypto.randomBytes(16).map(n => (base62.charAt(n % 62).charCodeAt()))
return {
params: aesEncrypt(Buffer.from(aesEncrypt(Buffer.from(text), 'cbc', presetKey, iv).toString('base64')), 'cbc', secretKey, iv).toString('base64'),
encSecKey: rsaEncrypt(secretKey.reverse(), publicKey).toString('hex')
}
const text = JSON.stringify(object)
const secretKey = crypto.randomBytes(16).map(n => (base62.charAt(n % 62).charCodeAt()))
return {
params: aesEncrypt(Buffer.from(aesEncrypt(Buffer.from(text), 'cbc', presetKey, iv).toString('base64')), 'cbc', secretKey, iv).toString('base64'),
encSecKey: rsaEncrypt(secretKey.reverse(), publicKey).toString('hex')
}
}
const linuxapi = (object) => {
const text = JSON.stringify(object)
return {
eparams: aesEncrypt(Buffer.from(text), 'ecb', linuxapiKey, '').toString('hex').toUpperCase()
}
const text = JSON.stringify(object)
return {
eparams: aesEncrypt(Buffer.from(text), 'ecb', linuxapiKey, '').toString('hex').toUpperCase()
}
}
const eapi = (url, object) => {
const text = typeof object === 'object' ? JSON.stringify(object) : object;
const message = `nobody${url}use${text}md5forencrypt`
const digest = crypto.createHash('md5').update(message).digest('hex')
const data = `${url}-36cd479b6b5-${text}-36cd479b6b5-${digest}`
return {
params: aesEncrypt(Buffer.from(data), 'ecb', eapiKey, '').toString('hex').toUpperCase()
}
const text = typeof object === 'object' ? JSON.stringify(object) : object;
const message = `nobody${url}use${text}md5forencrypt`
const digest = crypto.createHash('md5').update(message).digest('hex')
const data = `${url}-36cd479b6b5-${text}-36cd479b6b5-${digest}`
return {
params: aesEncrypt(Buffer.from(data), 'ecb', eapiKey, '').toString('hex').toUpperCase()
}
}
const decrypt = cipherBuffer => {
const decipher = crypto.createDecipheriv('aes-128-ecb',eapiKey,'')
return Buffer.concat([decipher.update(cipherBuffer), decipher.final()])
const decipher = crypto.createDecipheriv('aes-128-ecb', eapiKey, '')
return Buffer.concat([decipher.update(cipherBuffer), decipher.final()])
}
module.exports = {weapi, linuxapi, eapi, decrypt}
+14 -14
View File
@@ -70,20 +70,20 @@ const createRequest = (method, url, data, options) => {
const cookie = options.cookie || {};
const csrfToken = cookie['__csrf'] || ''
const header = {
"osver": cookie.osver, //系统版本
"deviceId": cookie.deviceId, //encrypt.base64.encode(imei + '\t02:00:00:00:00:00\t5106025eb79a5247\t70ffbaac7')
"appver": cookie.appver || "6.1.1", // app版本
"versioncode": cookie.versioncode || "140", //版本号
"mobilename": cookie.mobilename, //设备model
"buildver": cookie.buildver || Date.now().toString().substr(0, 10),
"resolution": cookie.resolution || "1920x1080", //设备分辨率
"__csrf": csrfToken,
"os": cookie.os || 'android',
"channel": cookie.channel,
"requestId":`${Date.now()}_${Math.floor(Math.random() * 1000).toString().padStart(4, '0')}`
'osver': cookie.osver, //系统版本
'deviceId': cookie.deviceId, //encrypt.base64.encode(imei + '\t02:00:00:00:00:00\t5106025eb79a5247\t70ffbaac7')
'appver': cookie.appver || '6.1.1', // app版本
'versioncode': cookie.versioncode || '140', //版本号
'mobilename': cookie.mobilename, //设备model
'buildver': cookie.buildver || Date.now().toString().substr(0, 10),
'resolution': cookie.resolution || '1920x1080', //设备分辨率
'__csrf': csrfToken,
'os': cookie.os || 'android',
'channel': cookie.channel,
'requestId': `${Date.now()}_${Math.floor(Math.random() * 1000).toString().padStart(4, '0')}`
}
if (cookie.MUSIC_U) header["MUSIC_U"] = cookie.MUSIC_U
if (cookie.MUSIC_A) header["MUSIC_A"] = cookie.MUSIC_A
if (cookie.MUSIC_U) header['MUSIC_U'] = cookie.MUSIC_U
if (cookie.MUSIC_A) header['MUSIC_A'] = cookie.MUSIC_A
headers['Cookie'] = Object.keys(header)
.map(
key =>
@@ -94,7 +94,7 @@ const createRequest = (method, url, data, options) => {
.join('; ')
data.header = header
data = encrypt.eapi(options.url, data)
url = url.replace(/\w*api/,'eapi')
url = url.replace(/\w*api/, 'eapi')
}
const answer = { status: 500, body: {}, cookie: [] }