mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-10-20 14:41:23 +08:00
feat: 补充播客上传声音接口 #1789
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<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" multiple />
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js"></script>
|
||||
<script>
|
||||
const phone = '' // 这里填手机号
|
||||
const password = '' // 这里填密码
|
||||
const fileUpdateTime = {}
|
||||
let fileLength = 0
|
||||
let cookieToken = ''
|
||||
if (!phone || !password) {
|
||||
const msg = '请设置你的手机号码和密码'
|
||||
alert(msg)
|
||||
throw new Error(msg)
|
||||
}
|
||||
login()
|
||||
main()
|
||||
async function login() {
|
||||
const res = await axios({
|
||||
url: `/login/cellphone?phone=${phone}&password=${encodeURIComponent(
|
||||
password,
|
||||
)}`,
|
||||
withCredentials: true, //跨域的话必须设置
|
||||
})
|
||||
cookieToken = res.data.cookie
|
||||
}
|
||||
function main() {
|
||||
document
|
||||
.querySelector('input[type="file"]')
|
||||
.addEventListener('change', function (e) {
|
||||
console.log(this.files)
|
||||
let currentIndx = 0
|
||||
fileLength = this.files.length
|
||||
for (const item of this.files) {
|
||||
currentIndx += 1
|
||||
upload(item, currentIndx)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function upload(file, currentIndx) {
|
||||
var formData = new FormData()
|
||||
formData.append('songFile', file)
|
||||
axios({
|
||||
method: 'post',
|
||||
url: `/audio/upload?time=${Date.now()}&cookie=${cookieToken}`,
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
data: formData,
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(`${file.name} 上传成功`)
|
||||
if (currentIndx >= fileLength) {
|
||||
console.log('上传完毕')
|
||||
}
|
||||
})
|
||||
.catch(async (err) => {
|
||||
console.log(err)
|
||||
console.log(fileUpdateTime)
|
||||
fileUpdateTime[file.name]
|
||||
? (fileUpdateTime[file.name] += 1)
|
||||
: (fileUpdateTime[file.name] = 1)
|
||||
if (fileUpdateTime[file.name] >= 4) {
|
||||
console.error(`上传失败:${file.name}`)
|
||||
return
|
||||
} else {
|
||||
console.error(`${file.name} 失败 ${fileUpdateTime[file.name]} 次`)
|
||||
}
|
||||
// await login()
|
||||
upload(file, currentIndx)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</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
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+4
-4
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user