comment_like.js 1.5 KB
Newer Older
N
Nzix 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
//comment like
// module.exports = (req, res, createWebAPIRequest, request) => {
//   let cookie = req.get('Cookie') ? req.get('Cookie') : ''
//   cookie = 'os=pc;' + cookie
//   const cid = req.query.cid //评论 id
//   const id = req.query.id
//   const typeMap = {
//     0: 'R_SO_4_', //歌曲
//     1: 'R_MV_5_', //mv
//     2: 'A_PL_0_', //歌单
//     3: 'R_AL_3_', //专辑
//     4: 'A_DJ_1_', //电台
//     5: 'R_VI_62_' //  视频
//   }
//   const type = typeMap[req.query.type]
//   const data = {
//     threadId: `${type}${id}`,
//     commentId: cid,
//     csrf_token: ''
//   }
//   const action = req.query.t == 1 ? 'like' : 'unlike'

//   const url = `/weapi/v1/comment/${action}`
//   createWebAPIRequest(
//     'music.163.com',
//     url,
//     'POST',
//     data,
//     cookie,
//     music_req => res.send(music_req),
//     err => res.status(502).send('fetch error')
//   )
// }

module.exports = (query, request) => {
    query.cookie = 'os=pc;' + query.cookie
    query.t = (query.t == 1 ? 'like' : 'unlike')
    query.type = {
        0: 'R_SO_4_', //  歌曲
        1: 'R_MV_5_', //  mv
        2: 'A_PL_0_', //  歌单
        3: 'R_AL_3_', //  专辑
        4: 'A_DJ_1_', //  电台,
        5: 'R_VI_62_' //  视频
    }[query.type]
    const data = {
        threadId: `${query.type}${query.id}`,
        commentId: query.cid
    }
    return request(
        'POST', `http://music.163.com/weapi/v1/comment/${query.t}`, data,
        {crypto: 'weapi', cookie: query.cookie, proxy: query.proxy}
    )
}