Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
修复 URI malformed 错误 #1347 #1287 #1110
Browse files Browse the repository at this point in the history
  • Loading branch information
Binaryify committed Sep 8, 2021
1 parent d608f10 commit 0660928
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5,757 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# 更新日志
### 4.0.22 | 2021.9.08
- 修复 URI malformed 错误 [#1347](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1347)

### 4.0.21 | 2021.9.04
- 修复云盘上传失败问题 #1332

Expand Down
13 changes: 8 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const exec = require('child_process').exec
const cache = require('./util/apicache').middleware
const { cookieToJson } = require('./util/index')
const fileUpload = require('express-fileupload')
const decode = require('safe-decode-uri-component')

// version check
exec('npm info NeteaseCloudMusicApi version', (err, stdout, stderr) => {
if (!err) {
Expand Down Expand Up @@ -44,8 +46,9 @@ app.use((req, res, next) => {
;(req.headers.cookie || '').split(/;\s+|(?<!\s)\s+$/g).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()
req.cookies[decode(pair.slice(0, crack)).trim()] = decode(
pair.slice(crack + 1),
).trim()
})
next()
})
Expand Down Expand Up @@ -81,7 +84,7 @@ fs.readdirSync(path.join(__dirname, 'module'))
app.use(route, (req, res) => {
;[req.query, req.body].forEach((item) => {
if (typeof item.cookie === 'string') {
item.cookie = cookieToJson(decodeURIComponent(item.cookie))
item.cookie = cookieToJson(decode(item.cookie))
}
})
let query = Object.assign(
Expand All @@ -94,7 +97,7 @@ fs.readdirSync(path.join(__dirname, 'module'))

question(query, request)
.then((answer) => {
console.log('[OK]', decodeURIComponent(req.originalUrl))
console.log('[OK]', decode(req.originalUrl))

const cookies = answer.cookie
if (Array.isArray(cookies) && cookies.length > 0) {
Expand All @@ -113,7 +116,7 @@ fs.readdirSync(path.join(__dirname, 'module'))
res.status(answer.status).send(answer.body)
})
.catch((answer) => {
console.log('[ERR]', decodeURIComponent(req.originalUrl), {
console.log('[ERR]', decode(req.originalUrl), {
status: answer.status,
body: answer.body,
})
Expand Down
Loading

2 comments on commit 0660928

@vercel
Copy link

@vercel vercel bot commented on 0660928 Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 0660928 Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

netease-cloud-music-api – ./docs

netease-cloud-music-api-git-master-binaryify.vercel.app
neteasecloudmusicapi.vercel.app

Please sign in to comment.