Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 qq-music-api v2.0.0 #37

Open
2 of 24 tasks
Rain120 opened this issue Jan 31, 2021 · 0 comments · May be fixed by #38
Open
2 of 24 tasks

🚀 qq-music-api v2.0.0 #37

Rain120 opened this issue Jan 31, 2021 · 0 comments · May be fixed by #38
Assignees
Labels
feature help wanted Extra attention is needed
Milestone

Comments

@Rain120
Copy link
Owner

Rain120 commented Jan 31, 2021

Hi 各位使用和 forked 的小伙伴们, 我正在计划着将本项目的版本更新一下,由于本人时间有限,所以恳请各位的支援,欢迎大家 PR 或者在此处👇 讨论。

issue visitor

Goals

  • 接口设计合理性
  • 加强代码可读性
    • 代码风格规范化
  • 加强接口可读性
    • 接口 URL
    • 接口参数
    • 接口返回
  • 加强文档可读性
    • 分类

更多请看👇详情描述

Status

  • User
  • Singer Rain120
    • 相似歌手 similar
    • 歌手信息 desc
  • Song
  • Search
  • MV
  • Album
  • Rank
  • Star
  • Radio
  • Disk
  • Recommend
  • Product
  • 文档

Branch

v2.0.0

Description

v2.0.0大版本修改是为了修复之前 接口设计可读性差 , API 不合理 等众多问题。

我们在旧版本的基础上, 针对性修改。所以对 接口参数, 接口返回, 路由 等方面做了一定的 优化, 我们推荐新用户使用当前时间最新版 v2.0.0

下面我们拿 singer.js 举个 🌰

singer.js

const YRequest = require('../module/y-axios');
const URequest = require('../module/URequest');
const { commonParams } = require('../module/config');
const moment = require('moment');
const { handleXml } = require('../util/xml');

const singerParams = Object.assign(commonParams, {
  g_tk: 1290642389,
  sign: 'zzafsjavizx8rzd4m36c2a7e17c9f884980ef9092cb8809e415',
  format: 'json',
});

// /singe/similar?singermid=0025NhlN2yWrP4
const similarOld = async (ctx, next) => {
  const { singermid: singer_mid } = ctx.query;
  const options = {
    params: {
      format: 'json',
      outCharset: 'utf-8',
      utf8: 1,
      start: 0,
      num: 5,
      singer_mid,
    },
  };

  return await YRequest({
    url: '/v8/fcg-bin/fcg_v8_simsinger.fcg',
    method: 'get',
    options,
    thenable: res => {
      if (!singer_mid) {
        ctx.status = 400;
        ctx.body = {
          message: 'no singermid',
        };
        return;
      }
      Object.assign(ctx, {
        status: 200,
        body: {
          response: res.data,
        },
      });
    },
    catcher: error => {
      console.log('error', error);
      ctx.status = 400;
      ctx.body = { error };
    },
  });
};

// 周杰伦 /singe/similar?id=4558&singermid=0025NhlN2yWrP4
const similar = async (ctx, next) => {
  const { id: singerId, singermid: singerMid, pageSize: num = 5 } = ctx.query;
  console.log('similar error: not support pageSize');
  const data = {
    comm: {
      ct: 24,
      cv: 10000,
    },
    similarSingerList: {
      method: 'GetSimilarSingerList',
      param: {
        singerId: parseInt(singerId, 10),
        singerMid,
        // TODO: QQ 貌似不支持
        num: 5,
      },
      module: 'music.SimilarSingerSvr',
    },
  };

  const params = Object.assign(singerParams, {
    '-': 'getSimilarSingerList1112654390871275',
    data: JSON.stringify(data),
  });

  return await URequest({
    method: 'get',
    params,
    thenable: res => {
      if (!singerMid) {
        ctx.status = 400;
        ctx.body = {
          message: 'no singermid',
        };
        return;
      }
      Object.assign(ctx, {
        status: 200,
        body: {
          data: res.data,
        },
      });
    },
    catcher: error => {
      console.log('error', error);
      ctx.status = 400;
      ctx.body = { error };
    },
  });
};

module.exports = {
  getSimilarSingerOld: similarOld,
  getSimilarSinger: similar,
};

对于先前接入的用户, 我们也做了一些兼容性的接口处理, 主要是 路由的变化 mapping, 具体可以在 routers/map-router.js 👇中体现, 感谢你的关注和使用。

map-router.js

const context = require('.');

module.exports = {
  // INFO: singer Module
  // /getSimilarSinger?singermid=0025NhlN2yWrP4
  '/getSimilarSinger/:singermid?': {
    cb: context.getSimilarSingerOld,
  },
  // /singe/similar?id=4558&singermid=0025NhlN2yWrP4
  '/singer/similar/:id/:singermid/:pageNum?': {
    cb: context.getSimilarSinger,
  },
};

new-router.js

const Router = require('koa-router');
const router = new Router();
const mapRouter = require('./map-router');

Object.keys(mapRouter).forEach(key => {
  if (key && mapRouter[key]) {
    const { method = 'get', cb } = mapRouter[key];
    router[method](key, cb);
  }
});

module.exports = router;
@Rain120 Rain120 added this to the v2.0.0 milestone Jan 31, 2021
@Rain120 Rain120 self-assigned this Jan 31, 2021
@Rain120 Rain120 pinned this issue Jan 31, 2021
@Rain120 Rain120 added the help wanted Extra attention is needed label Jan 31, 2021
@Rain120 Rain120 linked a pull request Jan 31, 2021 that will close this issue
11 tasks
@Rain120 Rain120 linked a pull request Jan 31, 2021 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant