diff --git a/module/audio_upload.js b/module/audio_upload.js
new file mode 100644
index 0000000..11ea4b4
--- /dev/null
+++ b/module/audio_upload.js
@@ -0,0 +1,66 @@
+const { default: axios } = require('axios')
+var xml2js = require('xml2js')
+var parser = new xml2js.Parser(/* options */)
+module.exports = async (query, request) => {
+ let ext = 'mp3'
+ if (query.songFile.name.indexOf('flac') > -1) {
+ ext = 'flac'
+ }
+ const filename = query.songFile.name
+ .replace('.' + ext, '')
+ .replace(/\s/g, '')
+ .replace(/\./g, '_')
+ query.cookie.os = 'pc'
+ query.cookie.appver = '2.9.7'
+ if (!query.songFile) {
+ return Promise.reject({
+ status: 500,
+ body: {
+ msg: '请上传音乐文件',
+ code: 500,
+ },
+ })
+ }
+
+ const tokenRes = await request(
+ 'POST',
+ `https://music.163.com/weapi/nos/token/alloc`,
+ {
+ bucket: 'ymusic',
+ ext: ext,
+ filename: filename,
+ local: false,
+ nos_product: 0,
+ type: 'other',
+ },
+ { crypto: 'weapi', cookie: query.cookie, proxy: query.proxy },
+ )
+
+ const objectKey = tokenRes.body.result.objectKey.replace('/', '%2F')
+ const res = await axios({
+ method: 'post',
+ url: `https://ymusic.nos-hz.163yun.com/${objectKey}?uploads`,
+ headers: {
+ 'x-nos-token': tokenRes.body.result.token,
+ 'Content-Type': 'audio/mpeg',
+ },
+ data: null,
+ })
+ // return xml
+ const res2 = await parser.parseStringPromise(res.data)
+
+ await axios({
+ method: 'put',
+ url: `https://ymusic.nos-hz.163yun.com/${objectKey}?partNumber=1&uploadId=${res2.InitiateMultipartUploadResult.UploadId[0]}`,
+ headers: {
+ 'x-nos-token': tokenRes.body.result.token,
+ },
+ data: query.songFile.data,
+ })
+ return {
+ status: 200,
+ body: {
+ code: 200,
+ },
+ }
+}
diff --git a/package.json b/package.json
index a6d0d60..5acfa12 100644
--- a/package.json
+++ b/package.json
@@ -72,6 +72,7 @@
"qrcode": "^1.4.4",
"safe-decode-uri-component": "^1.2.1",
"tunnel": "^0.0.6",
+ "xml2js": "^0.6.2",
"yargs": "^17.1.1"
},
"devDependencies": {
diff --git a/public/audio_upload.html b/public/audio_upload.html
new file mode 100644
index 0000000..a5a662c
--- /dev/null
+++ b/public/audio_upload.html
@@ -0,0 +1,84 @@
+
+
+
+
+
+ 播客上传
+
+
+
+
+
+
+
+
+
diff --git a/public/avatar_update.html b/public/avatar_update.html
index 02eed7d..dfa34bd 100644
--- a/public/avatar_update.html
+++ b/public/avatar_update.html
@@ -34,14 +34,14 @@
)
const res = await axios({
url: `/user/detail?uid=32953014×tamp=${Date.now()}`,
- withCredentials: true, //关键
+ withCredentials: true, //跨域的话必须设置
})
document.querySelector('#avatar').src = res.data.profile.avatarUrl
}
async function login() {
const res = await axios({
url: `/login/cellphone?phone=${phone}&password=${password}`,
- withCredentials: true, //关键
+ withCredentials: true, //跨域的话必须设置
})
cookieToken = res.data.cookie
}
diff --git a/public/cloud.html b/public/cloud.html
index 9459185..0a38ca1 100644
--- a/public/cloud.html
+++ b/public/cloud.html
@@ -27,7 +27,7 @@
async function login() {
const res = await axios({
url: `/login/cellphone?phone=${phone}&password=${encodeURIComponent(password)}`,
- withCredentials: true, //关键
+ withCredentials: true, //跨域的话必须设置
})
cookieToken = res.data.cookie
}
diff --git a/public/playlist_cover_update.html b/public/playlist_cover_update.html
index d2da2d9..d9f348f 100644
--- a/public/playlist_cover_update.html
+++ b/public/playlist_cover_update.html
@@ -48,7 +48,7 @@
async function login() {
const res = await axios({
url: `/login/cellphone?phone=${phone}&password=${password}`,
- withCredentials: true, //关键
+ withCredentials: true, //跨域的话必须设置
})
cookieToken = res.data.cookie
}
diff --git a/public/test.html b/public/test.html
index fccca52..f3a1dd1 100644
--- a/public/test.html
+++ b/public/test.html
@@ -23,14 +23,14 @@
$.ajax({
url: `/login/cellphone?phone=${phone}&password=${password}`,
xhrFields: {
- withCredentials: true, //关键
+ withCredentials: true, //跨域的话必须设置
},
success: function (data) {
console.log(data)
$.ajax({
url: `/recommend/resource `,
xhrFields: {
- withCredentials: true, //关键
+ withCredentials: true, //跨域的话必须设置
},
success: function (data) {
console.log(data)
@@ -47,12 +47,12 @@
axios({
url: `/login/cellphone?phone=${phone}&password=${password}`,
- withCredentials: true, //关键
+ withCredentials: true, //跨域的话必须设置
}).then(function (res) {
console.log(res.data)
axios({
url: `/recommend/resource`,
- withCredentials: true, //关键
+ withCredentials: true, //跨域的话必须设置
}).then(function (res) {
console.log(res.data)
})
diff --git a/util/config.json b/util/config.json
index 6b1cc2b..dbe22e6 100644
--- a/util/config.json
+++ b/util/config.json
@@ -1,5 +1,5 @@
{
- "anonymous_token": "bf8bfeabb1aa84f9c8c3906c04a04fb864322804c83f5d607e91a04eae463c9436bd1a17ec353cf780b396507a3f7464e8a60f4bbc019437993166e004087dd32d1490298caf655c2353e58daa0bc13cc7d5c198250968580b12c1b8817e3f5c807e650dd04abd3fb8130b7ae43fcc5b",
+ "anonymous_token": "de91e1f8119d32e01cc73efcb82c0a30c9137e8d4f88dbf5e3d7bf3f28998f21add2bc8204eeee5e56c0bbb8743574b46ca2c10c35dc172199bef9bf4d60ecdeab066bb4dc737d1c3324751bcc9aaf44c3061cd18d77b7a0",
"resourceTypeMap": {
"0": "R_SO_4_",
"1": "R_MV_5_",
diff --git a/yarn.lock b/yarn.lock
index ce6b5ef..05148fd 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3109,6 +3109,11 @@ safe-decode-uri-component@^1.2.1:
resolved "https://registry.npm.taobao.org/safer-buffer/download/safer-buffer-2.1.2.tgz"
integrity sha1-RPoWGwGHuVSd2Eu5GAL5vYOFzWo=
+sax@>=0.6.0:
+ version "1.2.4"
+ resolved "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
+ integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
+
semver@^5.4.1:
version "5.7.1"
resolved "https://registry.npmmirror.com/semver/-/semver-5.7.1.tgz"
@@ -3736,6 +3741,19 @@ wrappy@1:
resolved "https://registry.npm.taobao.org/wrappy/download/wrappy-1.0.2.tgz"
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
+xml2js@^0.6.2:
+ version "0.6.2"
+ resolved "https://registry.npmjs.org/xml2js/-/xml2js-0.6.2.tgz#dd0b630083aa09c161e25a4d0901e2b2a929b499"
+ integrity sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==
+ dependencies:
+ sax ">=0.6.0"
+ xmlbuilder "~11.0.0"
+
+xmlbuilder@~11.0.0:
+ version "11.0.1"
+ resolved "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3"
+ integrity sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==
+
xtend@^4.0.0:
version "4.0.2"
resolved "https://registry.npm.taobao.org/xtend/download/xtend-4.0.2.tgz"