Merge pull request #1241 from greenhat616/master

修复解析问题,改善 Docker 支持
This commit is contained in:
binaryify 2021-05-24 10:34:57 +08:00 committed by GitHub
commit c2d738822e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 5541 additions and 19 deletions

1
.husky/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
_

4
.husky/pre-commit Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged

View File

@ -3,11 +3,8 @@ FROM node:lts-alpine
WORKDIR /app
COPY . /app
RUN rm -f package-lock.json \
; rm -rf .idea \
; rm -rf node_modules \
; npm config set registry "https://registry.npm.taobao.org/" \
&& npm install
RUN npm config set registry "https://registry.npm.taobao.org/" \
&& npm install --production
EXPOSE 3000
CMD ["node", "app.js"]

5
app.js
View File

@ -42,9 +42,8 @@ app.use((req, res, next) => {
;(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()
req.cookies[decodeURIComponent(pair.slice(0, crack)).trim()] =
decodeURIComponent(pair.slice(crack + 1)).trim()
})
next()
})

View File

@ -13,7 +13,8 @@ module.exports = (query, request) => {
},
).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
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,
playlists = []
while ((result = pattern.exec(response.body)) != null) {

5524
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,8 @@
"start": "node app.js",
"test": "mocha -r intelli-espower-loader -t 20000 app.test.js --exit",
"lint": "eslint **/*.{js,ts}",
"lint-fix": "eslint --fix **/*.{js,ts}"
"lint-fix": "eslint --fix **/*.{js,ts}",
"prepare": "husky install"
},
"keywords": [
"网易云音乐",
@ -53,6 +54,7 @@
"eslint-config-prettier": "7.1.0",
"eslint-plugin-html": "6.1.2",
"eslint-plugin-prettier": "3.3.1",
"husky": "6.0.0",
"intelli-espower-loader": "1.0.1",
"lint-staged": "11.0.0",
"mocha": "8.3.2",

View File

@ -127,7 +127,7 @@ const createRequest = (method, url, data, options) => {
settings.httpAgent = new PacProxyAgent(options.proxy)
settings.httpsAgent = new PacProxyAgent(options.proxy)
} else {
var purl = qs.parse(options.proxy)
const purl = qs.parse(options.proxy)
if (purl.hostname) {
const agent = tunnel.httpsOverHttp({
proxy: {
@ -172,13 +172,19 @@ const createRequest = (method, url, data, options) => {
}
} catch (e) {
// console.log(e)
answer.body = body
try {
answer.body = JSON.parse(body.toString())
} catch (err) {
// console.log(err)
// can't decrypt and can't parse directly
answer.body = body
}
answer.status = res.status
}
answer.status =
100 < answer.status && answer.status < 600 ? answer.status : 400
if (answer.status == 200) resolve(answer)
if (answer.status === 200) resolve(answer)
else reject(answer)
})
.catch((err) => {