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

Commit

Permalink
Merge branch 'master' of github.com:Binaryify/NeteaseCloudMusicApi
Browse files Browse the repository at this point in the history
  • Loading branch information
Binaryify committed Feb 15, 2021
2 parents 289dbd1 + 90fa494 commit 25cc98f
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 60 deletions.
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
"tunnel": "^0.0.6"
},
"devDependencies": {
"@types/node": "14.14.21",
"@types/node": "14.14.25",
"@typescript-eslint/eslint-plugin": "4.4.1",
"@typescript-eslint/parser": "4.4.1",
"eslint": "7.18.0",
"eslint": "7.19.0",
"eslint-config-prettier": "7.1.0",
"eslint-plugin-html": "6.0.3",
"eslint-plugin-prettier": "3.3.1",
Expand Down
119 changes: 71 additions & 48 deletions public/cloud.html
Original file line number Diff line number Diff line change
@@ -1,55 +1,78 @@
<!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" accept="audio/mpeg" />
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>云盘上传</title>
</head>

<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.20.0-0/axios.min.js"></script>
<script>
<body>
<input id="file" type="file" multiple/>

const phone = ''
const password = ''
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=${password}`,
withCredentials: true, //关键
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.20.0-0/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)
}
})
cookieToken = res.data.cookie
}
async function main() {
document
.querySelector('input[type="file"]')
.addEventListener('change', function (e) {
var file = this.files[0]
upload(file)
})
}
}

async function upload(file) {
var formData = new FormData()
formData.append('songFile', file)
const res = await axios({
method: 'post',
url: `http://localhost:3000/cloud?time=${Date.now()}`,
headers: {
'Content-Type': 'multipart/form-data',
},
data: formData,
})
}
</script>
</body>
</html>
function upload(file, currentIndx) {
var formData = new FormData()
formData.append('songFile', file)
axios({
method: 'post',
url: `http://localhost:3000/cloud?time=${Date.now()}`,
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>

1 comment on commit 25cc98f

@vercel
Copy link

@vercel vercel bot commented on 25cc98f Feb 15, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.