This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
356 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,6 +182,8 @@ | |
161. 数字专辑&数字单曲-榜单 | ||
162. 数字专辑-语种风格馆 | ||
163. 数字专辑详情 | ||
164. 更新头像 | ||
165. 歌单封面上传 | ||
|
||
## 环境要求 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const uploadPlugin = require('../plugins/upload') | ||
module.exports = async (query, request) => { | ||
const uploadInfo = await uploadPlugin(query, request) | ||
const res = await request( | ||
'POST', | ||
`https://music.163.com/weapi/user/avatar/upload/v1`, | ||
{ | ||
imgid: uploadInfo.imgId | ||
}, | ||
{ crypto: 'weapi', cookie: query.cookie, proxy: query.proxy } | ||
) | ||
return { | ||
status: 200, | ||
body: { | ||
code: 200, | ||
data: { | ||
...uploadInfo, | ||
...res.body, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const uploadPlugin = require('../plugins/upload') | ||
module.exports = async (query, request) => { | ||
const uploadInfo = await uploadPlugin(query, request) | ||
const res = await request( | ||
'POST', | ||
`https://music.163.com/weapi/playlist/cover/update`, | ||
{ | ||
id: query.id, | ||
coverImgId: uploadInfo.imgId | ||
}, | ||
{ crypto: 'weapi', cookie: query.cookie, proxy: query.proxy } | ||
) | ||
return { | ||
status: 200, | ||
body: { | ||
code: 200, | ||
data: { | ||
...uploadInfo, | ||
...res.body, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,52 @@ | ||
{ | ||
"name": "NeteaseCloudMusicApi", | ||
"version": "3.36.0", | ||
"description": "网易云音乐 NodeJS 版 API", | ||
"scripts": { | ||
"start": "node app.js", | ||
"test": "mocha -r intelli-espower-loader -t 20000 app.test.js --exit", | ||
"lint-fix": "eslint --fix --ext .js app.js module/ util/ test/ " | ||
}, | ||
"keywords": [ | ||
"网易云音乐", | ||
"网易云", | ||
"音乐", | ||
"网易云音乐nodejs" | ||
], | ||
"main": "main.js", | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"eslint --fix", | ||
"git add" | ||
] | ||
}, | ||
"author": "binaryify", | ||
"license": "MIT", | ||
"files": [ | ||
"module", | ||
"util" | ||
], | ||
"dependencies": { | ||
"express": "^4.17.1", | ||
"pac-proxy-agent": "^3.0.1", | ||
"request": "^2.88.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^6.6.0", | ||
"eslint-plugin-html": "^6.0.0", | ||
"husky": "^3.0.9", | ||
"intelli-espower-loader": "^1.0.1", | ||
"lint-staged": "^9.4.2", | ||
"mocha": "^6.2.2", | ||
"power-assert": "^1.6.1" | ||
"name": "NeteaseCloudMusicApi", | ||
"version": "3.37.0", | ||
"description": "网易云音乐 NodeJS 版 API", | ||
"scripts": { | ||
"start": "node app.js", | ||
"test": "mocha -r intelli-espower-loader -t 20000 app.test.js --exit", | ||
"lint-fix": "eslint --fix --ext .js app.js module/ util/ test/ " | ||
}, | ||
"keywords": [ | ||
"网易云音乐", | ||
"网易云", | ||
"音乐", | ||
"网易云音乐nodejs" | ||
], | ||
"main": "main.js", | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"eslint --fix", | ||
"git add" | ||
] | ||
}, | ||
"author": "binaryify", | ||
"license": "MIT", | ||
"files": [ | ||
"module", | ||
"util" | ||
], | ||
"dependencies": { | ||
"axios": "^0.19.2", | ||
"express": "^4.17.1", | ||
"pac-proxy-agent": "^3.0.1", | ||
"request": "^2.88.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^6.6.0", | ||
"eslint-plugin-html": "^6.0.0", | ||
"husky": "^3.0.9", | ||
"intelli-espower-loader": "^1.0.1", | ||
"lint-staged": "^9.4.2", | ||
"mocha": "^6.2.2", | ||
"power-assert": "^1.6.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const axios = require('axios') | ||
module.exports = async (query, request) => { | ||
const data = { | ||
bucket: 'yyimgs', | ||
ext: 'jpg', | ||
filename: query.imgFile.name, | ||
local: false, | ||
nos_product: 0, | ||
return_body: `{"code":200,"size":"$(ObjectSize)"}`, | ||
type: 'other', | ||
} | ||
// 获取key和token | ||
const res = await request( | ||
'POST', | ||
`https://music.163.com/weapi/nos/token/alloc`, | ||
data, | ||
{ crypto: 'weapi', cookie: query.cookie, proxy: query.proxy } | ||
) | ||
// 上传图片 | ||
const res2 = await axios({ | ||
method: 'post', | ||
url: `https://nosup-hz1.127.net/yyimgs/${res.body.result.objectKey}?offset=0&complete=true&version=1.0`, | ||
headers: { | ||
'x-nos-token': res.body.result.token, | ||
'Content-Type': 'image/jpeg', | ||
}, | ||
data: query.imgFile.data, | ||
}) | ||
// 获取裁剪后图片的id | ||
const imgSize = query.imgSize || 300 | ||
const imgX = query.imgX || 0 | ||
const imgY = query.imgY || 0 | ||
const res3 = await request( | ||
'POST', | ||
`https://music.163.com/upload/img/op?id=${res.body.result.docId}&op=${imgX}y${imgY}y${imgSize}y${imgSize}`, | ||
{}, | ||
{ crypto: 'weapi', cookie: query.cookie, proxy: query.proxy } | ||
) | ||
|
||
return { | ||
// ...res.body.result, | ||
// ...res2.data, | ||
// ...res3.body, | ||
url_pre: 'https://p1.music.126.net/' + res.body.result.objectKey, | ||
url: res3.body.url, | ||
imgId: res3.body.id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>更新头像</title> | ||
</head> | ||
<body> | ||
<input id="file" type="file" name="filename" /> | ||
<img id="avatar" style="height: 200px; width: 200px; border-radius: 50%;" /> | ||
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.20.0-0/axios.min.js | ||
"></script> | ||
<script> | ||
const phone = '' | ||
const password = '' | ||
const port = 3000 | ||
let cookieToken = '' | ||
if (!phone || !password) { | ||
const msg = '请设置你的手机号码和密码' | ||
alert(msg) | ||
throw new Error(msg) | ||
} | ||
|
||
main() | ||
login() | ||
async function main() { | ||
document.querySelector('input[type="file"]').addEventListener( | ||
'change', | ||
function (e) { | ||
var file = this.files[0] | ||
upload(file) | ||
}, | ||
false | ||
) | ||
const res = await axios({ | ||
url: `http://localhost:${port}/user/detail?uid=32953014`, | ||
withCredentials: true, //关键 | ||
}) | ||
document.querySelector('#avatar').src = res.data.profile.avatarUrl | ||
} | ||
async function login() { | ||
const res = await axios({ | ||
url: `http://localhost:${port}/login/cellphone?phone=${phone}&password=${password}`, | ||
withCredentials: true, //关键 | ||
}) | ||
cookieToken = res.data.cookie | ||
} | ||
async function upload(file) { | ||
var formData = new FormData() | ||
formData.append('imgFile', file) | ||
const imgSize = await getImgSize(file) | ||
const res = await axios({ | ||
method: 'post', | ||
url: `http://localhost:3000/avatar/upload?cookie=${cookieToken}&imgSize=${imgSize.width}&imgX=0&imgY=0`, | ||
headers: { | ||
'Content-Type': 'multipart/form-data', | ||
}, | ||
data: formData, | ||
}) | ||
document.querySelector('#avatar').src = res.data.data.url | ||
} | ||
function getImgSize(file) { | ||
return new Promise((resolve, reject) => { | ||
let reader = new FileReader() | ||
reader.readAsDataURL(file) | ||
reader.onload = function (theFile) { | ||
let image = new Image() | ||
image.src = theFile.target.result | ||
image.onload = function () { | ||
resolve({ | ||
width: this.width, | ||
height: this.height | ||
}) | ||
} | ||
} | ||
}) | ||
} | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.