Skip to content

Commit

Permalink
style: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
hq001 committed Dec 4, 2020
1 parent 76bdafd commit 5e61608
Show file tree
Hide file tree
Showing 53 changed files with 3,452 additions and 1,935 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NeteaseCloudMusicApi/
packages/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 4 additions & 4 deletions packages/api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ app.use((req, res, next) => {
// cookie parser
app.use((req, res, next) => {
req.cookies = {}
;(req.headers.cookie || '').split(/\s*;\s*/).forEach((pair) => {
;(req.headers.cookie || '').split(/\s*;\s*/).forEach(pair => {
let crack = pair.indexOf('=')
if (crack < 1 || crack == pair.length - 1) return
req.cookies[
Expand Down Expand Up @@ -56,7 +56,7 @@ const special = {

fs.readdirSync(path.join(__dirname, 'module'))
.reverse()
.forEach((file) => {
.forEach(file => {
if (!file.endsWith('.js')) return
let route =
file in special
Expand All @@ -77,12 +77,12 @@ fs.readdirSync(path.join(__dirname, 'module'))
)

question(query, request)
.then((answer) => {
.then(answer => {
console.log('[OK]', decodeURIComponent(req.originalUrl))
res.append('Set-Cookie', answer.cookie)
res.status(answer.status).send(answer.body)
})
.catch((answer) => {
.catch(answer => {
console.log('[ERR]', decodeURIComponent(req.originalUrl), {
status: answer.status,
body: answer.body,
Expand Down
4 changes: 2 additions & 2 deletions packages/api/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ before(() => {
app = require('./app.js')
global.host = 'http://localhost:' + app.server.address().port
})
after((done) => {
after(done => {
app.server.close(done)
})

fs.readdirSync(path.join(__dirname, 'test')).forEach((file) => {
fs.readdirSync(path.join(__dirname, 'test')).forEach(file => {
require(path.join(__dirname, 'test', file))
})
4 changes: 2 additions & 2 deletions packages/api/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const { cookieToJson } = require('./util/index')
let obj = {}
fs.readdirSync(path.join(__dirname, 'module'))
.reverse()
.forEach((file) => {
.forEach(file => {
if (!file.endsWith('.js')) return
let fileModule = require(path.join(__dirname, 'module', file))
obj[file.split('.').shift()] = function (data) {
obj[file.split('.').shift()] = function(data) {
if (typeof data.cookie === 'string') {
data.cookie = cookieToJson(data.cookie)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/module/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = (query, request) => {
const data = {
e_r: true,
}
Object.keys(query).forEach((i) => {
Object.keys(query).forEach(i => {
if (/^\/api\//.test(i)) {
data[i] = query[i]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/module/check_music.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = (query, request) => {
proxy: query.proxy,
realIP: query.realIP,
},
).then((response) => {
).then(response => {
let playable = false
if (response.body.code == 200) {
if (response.body.data[0].code == 200) {
Expand Down
5 changes: 2 additions & 3 deletions packages/api/module/like.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ module.exports = (query, request) => {
}
return request(
'POST',
`https://music.163.com/weapi/radio/like?alg=${
query.alg || 'itembased'
}&trackId=${query.id}&time=${query.time || 25}`,
`https://music.163.com/weapi/radio/like?alg=${query.alg ||
'itembased'}&trackId=${query.id}&time=${query.time || 25}`,
data,
{
crypto: 'weapi',
Expand Down
5 changes: 4 additions & 1 deletion packages/api/module/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ module.exports = async (query, request) => {
username: query.email,
password:
query.md5_password ||
crypto.createHash('md5').update(query.password).digest('hex'),
crypto
.createHash('md5')
.update(query.password)
.digest('hex'),
rememberLogin: 'true',
}
let result = await request(
Expand Down
5 changes: 4 additions & 1 deletion packages/api/module/login_cellphone.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ module.exports = async (query, request) => {
countrycode: query.countrycode || '86',
password:
query.md5_password ||
crypto.createHash('md5').update(query.password).digest('hex'),
crypto
.createHash('md5')
.update(query.password)
.digest('hex'),
rememberLogin: 'true',
}
let result = await request(
Expand Down
2 changes: 1 addition & 1 deletion packages/api/module/login_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = (query, request) => {
`https://music.163.com`,
{},
{ cookie: query.cookie, proxy: query.proxy, realIP: query.realIP },
).then((response) => {
).then(response => {
try {
let profile = eval(`(${/GUser\s*=\s*([^;]+);/.exec(response.body)[1]})`)
let bindings = eval(`(${/GBinds\s*=\s*([^;]+);/.exec(response.body)[1]})`)
Expand Down
2 changes: 1 addition & 1 deletion packages/api/module/playlist_track_add.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = async (query, request) => {
const data = {
id: query.pid,
tracks: JSON.stringify(
query.ids.split(',').map((item) => {
query.ids.split(',').map(item => {
return { type: 3, id: item }
}),
),
Expand Down
2 changes: 1 addition & 1 deletion packages/api/module/playlist_track_delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = async (query, request) => {
const data = {
id: query.id,
tracks: JSON.stringify(
query.ids.split(',').map((item) => {
query.ids.split(',').map(item => {
return { type: 3, id: item }
}),
),
Expand Down
5 changes: 4 additions & 1 deletion packages/api/module/register_cellphone.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ module.exports = (query, request) => {
const data = {
captcha: query.captcha,
phone: query.phone,
password: crypto.createHash('md5').update(query.password).digest('hex'),
password: crypto
.createHash('md5')
.update(query.password)
.digest('hex'),
nickname: query.nickname,
}
return request('POST', `https://music.163.com/api/register/cellphone`, data, {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/module/related_playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = (query, request) => {
proxy: query.proxy,
realIP: query.realIP,
},
).then((response) => {
).then(response => {
try {
const pattern = /<div class="cver u-cover u-cover-3">[\s\S]*?<img src="([^"]+)">[\s\S]*?<a class="sname f-fs1 s-fc0" href="([^"]+)"[^>]*>([^<]+?)<\/a>[\s\S]*?<a class="nm nm f-thide s-fc3" href="([^"]+)"[^>]*>([^<]+?)<\/a>/g
let result,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/module/song_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module.exports = (query, request) => {
query.ids = query.ids.split(/\s*,\s*/)
const data = {
c: '[' + query.ids.map((id) => '{"id":' + id + '}').join(',') + ']',
c: '[' + query.ids.map(id => '{"id":' + id + '}').join(',') + ']',
ids: '[' + query.ids.join(',') + ']',
}
return request('POST', `https://music.163.com/weapi/v3/song/detail`, data, {
Expand Down
Loading

0 comments on commit 5e61608

Please sign in to comment.