提交 b98d6119 编写于 作者: B binaryify

add eslint

上级 629533e6
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
ecmaVersion: 2018,
sourceType: 'module'
},
env: {
browser: true
},
rules: {
indent: ['error', 2, { SwitchCase: 1 }],
'key-spacing': [
2,
{
beforeColon: false,
afterColon: true
}
],
'no-octal': 2,
'no-redeclare': 2,
'comma-spacing': 2,
'no-new-object': 2,
'arrow-spacing': 2,
quotes: [
2,
'single',
{
avoidEscape: true,
allowTemplateLiterals: true
}
]
}
}
......@@ -3,44 +3,44 @@ const path = require('path')
const express = require('express')
const bodyParser = require('body-parser')
const request = require('./util/request')
const package = require('./package.json')
const packageJSON = require('./package.json')
const exec = require('child_process').exec
const cache = require('apicache').middleware
// version check
exec('npm info NeteaseCloudMusicApi version', (err, stdout, stderr) => {
if(!err){
let version = stdout.trim()
if(package.version < version){
console.log(`最新版本: ${version}, 当前版本: ${package.version}, 请及时更新`)
}
if(!err){
let version = stdout.trim()
if(packageJSON.version < version){
console.log(`最新版本: ${version}, 当前版本: ${packageJSON.version}, 请及时更新`)
}
}
})
const app = express()
// CORS
app.use((req, res, next) => {
if(req.path !== '/' && !req.path.includes('.')){
res.header({
'Access-Control-Allow-Credentials': true,
'Access-Control-Allow-Origin': req.headers.origin || '*',
'Access-Control-Allow-Headers': 'X-Requested-With',
'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS',
'Content-Type': 'application/json; charset=utf-8'
})
}
next()
if(req.path !== '/' && !req.path.includes('.')){
res.header({
'Access-Control-Allow-Credentials': true,
'Access-Control-Allow-Origin': req.headers.origin || '*',
'Access-Control-Allow-Headers': 'X-Requested-With',
'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS',
'Content-Type': 'application/json; charset=utf-8'
})
}
next()
})
// cookie parser
app.use((req, res, next) => {
req.cookies = {}, (req.headers.cookie || '').split(/\s*;\s*/).forEach(pair => {
let crack = pair.indexOf('=')
if(crack < 1 || crack == pair.length - 1) return
req.cookies[decodeURIComponent(pair.slice(0, crack)).trim()] = decodeURIComponent(pair.slice(crack + 1)).trim()
})
next()
req.cookies = {}, (req.headers.cookie || '').split(/\s*;\s*/).forEach(pair => {
let crack = pair.indexOf('=')
if(crack < 1 || crack == pair.length - 1) return
req.cookies[decodeURIComponent(pair.slice(0, crack)).trim()] = decodeURIComponent(pair.slice(crack + 1)).trim()
})
next()
})
// body parser
......@@ -55,37 +55,37 @@ app.use(express.static(path.join(__dirname, 'public')))
// router
const special = {
'daily_signin.js': '/daily_signin',
'fm_trash.js': '/fm_trash',
'personal_fm.js': '/personal_fm'
'daily_signin.js': '/daily_signin',
'fm_trash.js': '/fm_trash',
'personal_fm.js': '/personal_fm'
}
fs.readdirSync(path.join(__dirname, 'module')).reverse().forEach(file => {
if(!(/\.js$/i.test(file))) return
let route = (file in special) ? special[file] : '/' + file.replace(/\.js$/i, '').replace(/_/g, '/')
let question = require(path.join(__dirname, 'module', file))
if(!(/\.js$/i.test(file))) return
let route = (file in special) ? special[file] : '/' + file.replace(/\.js$/i, '').replace(/_/g, '/')
let question = require(path.join(__dirname, 'module', file))
app.use(route, (req, res) => {
let query = Object.assign({}, req.query, req.body, {cookie: req.cookies})
question(query, request)
.then(answer => {
console.log('[OK]', decodeURIComponent(req.originalUrl))
res.append('Set-Cookie', answer.cookie)
res.status(answer.status).send(answer.body)
})
.catch(answer => {
console.log('[ERR]', decodeURIComponent(req.originalUrl))
if(answer.body.code =='301') answer.body.msg = '需要登录'
res.append('Set-Cookie', answer.cookie)
res.status(answer.status).send(answer.body)
})
})
app.use(route, (req, res) => {
let query = Object.assign({}, req.query, req.body, {cookie: req.cookies})
question(query, request)
.then(answer => {
console.log('[OK]', decodeURIComponent(req.originalUrl))
res.append('Set-Cookie', answer.cookie)
res.status(answer.status).send(answer.body)
})
.catch(answer => {
console.log('[ERR]', decodeURIComponent(req.originalUrl))
if(answer.body.code =='301') answer.body.msg = '需要登录'
res.append('Set-Cookie', answer.cookie)
res.status(answer.status).send(answer.body)
})
})
})
const port = process.env.PORT || 3000
app.server = app.listen(port, () => {
console.log(`server running @ http://localhost:${port}`)
console.log(`server running @ http://localhost:${port}`)
})
module.exports = app
......@@ -5,11 +5,11 @@ module.exports = (query, request) => {
nickname: query.nickname
};
return request(
"POST",
'POST',
`http://music.163.com/eapi/activate/initProfile`,
data,
{
crypto: "eapi",
crypto: 'eapi',
cookie: query.cookie,
proxy: query.proxy,
url: '/api/activate/initProfile'
......
// 专辑内容
module.exports = (query, request) => {
return request(
'POST', `https://music.163.com/weapi/v1/album/${query.id}`, {},
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
return request(
'POST', `https://music.163.com/weapi/v1/album/${query.id}`, {},
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
}
\ No newline at end of file
......@@ -2,11 +2,11 @@
module.exports = (query, request) => {
const data = {
id: query.id
};
}
return request(
"POST",
'POST',
`https://music.163.com/api/album/detail/dynamic`,
data,
{ crypto: "weapi", cookie: query.cookie, proxy: query.proxy }
);
};
{ crypto: 'weapi', cookie: query.cookie, proxy: query.proxy }
)
}
// 最新专辑
module.exports = (query, request) => {
return request(
'POST', `https://music.163.com/api/discovery/newAlbum`, {},
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
return request(
'POST', `https://music.163.com/api/discovery/newAlbum`, {},
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
}
// 已收藏专辑列表
module.exports = (query, request) => {
query.t = (query.t == 1 ? 'sub' : 'unsub')
const data = {
id: query.id
};
return request("POST", `https://music.163.com/api/album/${query.t}`, data, {
crypto: "weapi",
cookie: query.cookie,
proxy: query.proxy
});
query.t = (query.t == 1 ? 'sub' : 'unsub')
const data = {
id: query.id
};
return request('POST', `https://music.163.com/api/album/${query.t}`, data, {
crypto: 'weapi',
cookie: query.cookie,
proxy: query.proxy
});
};
// 已收藏专辑列表
module.exports = (query, request) => {
const data = {
limit: query.limit || 25,
offset: query.offset || 0,
total: true
}
return request(
'POST', `https://music.163.com/weapi/album/sublist`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
const data = {
limit: query.limit || 25,
offset: query.offset || 0,
total: true
}
return request(
'POST', `https://music.163.com/weapi/album/sublist`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
}
\ No newline at end of file
// 歌手专辑列表
module.exports = (query, request) => {
const data = {
limit: query.limit || 30,
offset: query.offset || 0,
total: true
}
return request(
'POST', `https://music.163.com/weapi/artist/albums/${query.id}`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
const data = {
limit: query.limit || 30,
offset: query.offset || 0,
total: true
}
return request(
'POST', `https://music.163.com/weapi/artist/albums/${query.id}`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
}
\ No newline at end of file
// 歌手介绍
module.exports = (query, request) => {
const data = {
id: query.id
}
return request(
'POST', `https://music.163.com/weapi/artist/introduction`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
const data = {
id: query.id
}
return request(
'POST', `https://music.163.com/weapi/artist/introduction`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
}
\ No newline at end of file
......@@ -23,15 +23,15 @@
*/
module.exports = (query, request) => {
const data = {
categoryCode: query.cat || '1001',
initial: (query.initial || '').toUpperCase().charCodeAt() || '',
offset: query.offset || 0,
limit: query.limit || 30,
total: true
}
return request(
'POST', `https://music.163.com/weapi/artist/list`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
const data = {
categoryCode: query.cat || '1001',
initial: (query.initial || '').toUpperCase().charCodeAt() || '',
offset: query.offset || 0,
limit: query.limit || 30,
total: true
}
return request(
'POST', `https://music.163.com/weapi/artist/list`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
}
\ No newline at end of file
// 歌手相关MV
module.exports = (query, request) => {
const data = {
artistId: query.id,
limit: query.limit,
offset: query.offset,
total: true
}
return request(
'POST', `https://music.163.com/weapi/artist/mvs`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
const data = {
artistId: query.id,
limit: query.limit,
offset: query.offset,
total: true
}
return request(
'POST', `https://music.163.com/weapi/artist/mvs`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
}
\ No newline at end of file
// 收藏与取消收藏歌手
module.exports = (query, request) => {
query.t = (query.t == 1 ? 'sub' : 'unsub')
const data = {
artistId: query.id,
artistIds: '[' + query.id + ']'
}
return request(
'POST', `https://music.163.com/weapi/artist/${query.t}`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
query.t = (query.t == 1 ? 'sub' : 'unsub')
const data = {
artistId: query.id,
artistIds: '[' + query.id + ']'
}
return request(
'POST', `https://music.163.com/weapi/artist/${query.t}`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
}
\ No newline at end of file
// 关注歌手列表
module.exports = (query, request) => {
const data = {
limit: query.limit || 25,
offset: query.offset || 0,
total: true
}
return request(
'POST', `https://music.163.com/weapi/artist/sublist`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
const data = {
limit: query.limit || 25,
offset: query.offset || 0,
total: true
}
return request(
'POST', `https://music.163.com/weapi/artist/sublist`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
}
\ No newline at end of file
// 歌手单曲
module.exports = (query, request) => {
return request(
'POST', `https://music.163.com/weapi/v1/artist/${query.id}`, {},
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
return request(
'POST', `https://music.163.com/weapi/v1/artist/${query.id}`, {},
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
}
\ No newline at end of file
// 首页轮播图
module.exports = (query, request) => {
const type = {
0: 'pc',
1: 'android',
2: 'iphone',
3: 'ipad'
}[query.type || 0] || 'pc';
return request(
'POST', `https://music.163.com/api/v2/banner/get`, {clientType: type},
{crypto: 'linuxapi', proxy: query.proxy}
)
const type = {
0: 'pc',
1: 'android',
2: 'iphone',
3: 'ipad'
}[query.type || 0] || 'pc';
return request(
'POST', `https://music.163.com/api/v2/banner/get`, {clientType: type},
{crypto: 'linuxapi', proxy: query.proxy}
)
}
\ No newline at end of file
module.exports = (query, request) => {
const data = {
"e_r": true
'e_r': true
};
Object.keys(query).forEach(i => {
if (/^\/api\//.test(i)) {
......
......@@ -5,11 +5,11 @@ module.exports = (query, request) => {
cellphone: query.phone
};
return request(
"POST",
'POST',
`http://music.163.com/eapi/cellphone/existence/check`,
data,
{
crypto: "eapi",
crypto: 'eapi',
cookie: query.cookie,
proxy: query.proxy,
url: '/api/cellphone/existence/check'
......
// 歌曲可用性
module.exports = (query, request) => {
const data = {
ids: '[' + parseInt(query.id) + ']',
br: parseInt(query.br || 999000)
}
return request(
'POST', `https://music.163.com/weapi/song/enhance/player/url`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
const data = {
ids: '[' + parseInt(query.id) + ']',
br: parseInt(query.br || 999000)
}
return request(
'POST', `https://music.163.com/weapi/song/enhance/player/url`, data,
{crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
)
.then(response => {
let playable = false
if(response.body.code == 200){
if(response.body.data[0].code == 200){
playable = true
}
}
if(playable){
response.body = {success: true, message: 'ok'}
return response
}
else{
response.status = 404
response.body = {success: false, message: '亲爱的,暂无版权'}
return Promise.reject(response)
let playable = false
if(response.body.code == 200){
if(response.body.data[0].code == 200){
playable = true
}
}
if(playable){
response.body = {success: true, message: 'ok'}
return response
}
else{
response.status = 404
response.body = {success: false, message: '亲爱的,暂无版权'}
return Promise.reject(response)
}
})
}
\ No newline at end of file
// 发送与删除评论
module.exports = (query, request) => {
query.cookie.os = 'pc'
query.t = (query.t == 1 ? 'add' : 'delete')
query.type = {
0: 'R_SO_4_', // 歌曲
1: 'R_MV_5_', // MV
2: 'A_PL_0_', // 歌单
3: 'R_AL_3_', // 专辑
4: 'A_DJ_1_', // 电台,
5: 'R_VI_62_',// 视频
6: 'A_EV_2_' // 动态
}[query.type]
const data = {
threadId: query.type + query.id
}
query.cookie.os = 'pc'
query.t = (query.t == 1 ? 'add' : 'delete')
query.type = {
0: 'R_SO_4_', // 歌曲
1: 'R_MV_5_', // MV
2: 'A_PL_0_', // 歌单
3: 'R_AL_3_', // 专辑
4: 'A_DJ_1_', // 电台,
5: 'R_VI_62_', // 视频
6: 'A_EV_2_' // 动态
}[query.type]
const data = {
threadId: query.type + query.id
}
if(query.type == 'A_EV_2_'){
data.threadId = query.threadId