songUpload.js 1.1 KB
Newer Older
1 2 3 4 5 6 7
const axios = require('axios')
module.exports = async (query, request) => {
  //   获取key和token
  const tokenRes = await request(
    'POST',
    `https://music.163.com/weapi/nos/token/alloc`,
    {
B
binaryify 已提交
8
      bucket: 'jd-musicrep-privatecloud-audio-public',
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
      ext: 'mp3',
      filename: query.songFile.name.replace('.mp3', ''),
      local: false,
      nos_product: 3,
      type: 'audio',
      md5: query.songFile.md5,
    },
    { crypto: 'weapi', cookie: query.cookie, proxy: query.proxy },
  )

  // 上传
  const objectKey = tokenRes.body.result.objectKey.replace('/', '%2F')
  try {
    await axios({
      method: 'post',
B
binaryify 已提交
24
      url: `http://45.127.129.8/jd-musicrep-privatecloud-audio-public/${objectKey}?offset=0&complete=true&version=1.0`,
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
      headers: {
        'x-nos-token': tokenRes.body.result.token,
        'Content-MD5': query.songFile.md5,
        'Content-Type': 'audio/mpeg',
        'Content-Length': String(query.songFile.size),
      },
      data: query.songFile.data,
    })
  } catch (error) {
    console.log('error', error.response)
  }
  return {
    ...tokenRes,
  }
}