Ver Fonte

fix some error

Dotos há 8 anos atrás
pai
commit
9c7411d681
4 ficheiros alterados com 58 adições e 116 exclusões
  1. 46 47
      package.json
  2. 2 59
      routes/netease.js
  3. 7 8
      utils/encrypt.js
  4. 3 2
      utils/util.js

+ 46 - 47
package.json

@@ -1,48 +1,47 @@
 {
-  "name": "JsonBird",
-  "version": "1.4.0",
-  "description": "A remote data interface proxy service",
-  "author": {
-    "name": "xCss",
-    "mail": "yy.liu@foxmail.com"
-  },
-  "license": "MIT",
-  "private": true,
-  "scripts": {
-    "start": "supervisor node ./bin/www",
-    "super": "supervisor ./bin/www"
-  },
-  "repository": {
-    "type": "git",
-    "url": "git+https://github.com/xCss/JsonBird.git"
-  },
-  "keywords": [
-    "JsonBird",
-    "proxy",
-    "data interface proxy",
-    "remote data interface proxy"
-  ],
-  "bugs": {
-    "url": "https://github.com/xCss/JsonBird/issues"
-  },
-  "readme": "./readme.md",
-  "homepage": "https://github.com/xCss/JsonBird#readme",
-  "dependencies": {
-    "big-integer": "^1.6.17",
-    "blueimp-md5": "^2.7.0",
-    "body-parser": "~1.15.1",
-    "cookie-parser": "~1.4.3",
-    "crypto": "0.0.3",
-    "debug": "~2.2.0",
-    "express": "~4.13.4",
-    "express-generator": "^4.13.4",
-    "helmet": "^2.3.0",
-    "js-base64": "^2.1.9",
-    "morgan": "~1.7.0",
-    "pug": "^2.0.0-beta6",
-    "querystring": "^0.2.0",
-    "request": "^2.81.0",
-    "serve-favicon": "~2.3.0",
-    "superagent": "^2.3.0"
-  }
-}
+    "name": "JsonBird",
+    "version": "1.4.0",
+    "description": "A remote data interface proxy service",
+    "author": {
+        "name": "xCss",
+        "mail": "yy.liu@foxmail.com"
+    },
+    "license": "MIT",
+    "private": true,
+    "scripts": {
+        "start": "supervisor node ./bin/www",
+        "super": "supervisor ./bin/www"
+    },
+    "repository": {
+        "type": "git",
+        "url": "git+https://github.com/xCss/JsonBird.git"
+    },
+    "keywords": [
+        "JsonBird",
+        "proxy",
+        "data interface proxy",
+        "remote data interface proxy"
+    ],
+    "bugs": {
+        "url": "https://github.com/xCss/JsonBird/issues"
+    },
+    "readme": "./readme.md",
+    "homepage": "https://github.com/xCss/JsonBird#readme",
+    "dependencies": {
+        "big-integer": "^1.6.17",
+        "blueimp-md5": "^2.7.0",
+        "body-parser": "~1.15.1",
+        "cookie-parser": "~1.4.3",
+        "debug": "~2.2.0",
+        "express": "~4.13.4",
+        "express-generator": "^4.13.4",
+        "helmet": "^2.3.0",
+        "js-base64": "^2.1.9",
+        "morgan": "~1.7.0",
+        "pug": "^2.0.0-beta6",
+        "querystring": "^0.2.0",
+        "request": "^2.81.0",
+        "serve-favicon": "~2.3.0",
+        "superagent": "^2.3.0"
+    }
+}

+ 2 - 59
routes/netease.js

@@ -1,8 +1,7 @@
 var express = require('express');
-var request = require('superagent');
 var router = express.Router();
 
-const util = require('../utils/utils')
+const util = require('../utils/util')
 
 const links = {
     song: '/weapi/v3/song/detail',
@@ -70,6 +69,7 @@ router.get('/:channel', function(req, res, next) {
                     }
                 })
             }).catch(ex => {
+                console.log(ex)
                 res.send({
                     data: {},
                     status: {
@@ -91,64 +91,7 @@ router.get('/:channel', function(req, res, next) {
         })
     })
 
-    // res.header("Content-Type", "application/json;charset=utf-8");
-    // //console.log('ref:' + req.header('referer'));
-    // var id = req.query.id;
-    // var playlist_id = req.query.playlist_id;
-    // var headers = {};
-    // headers['Cookie'] = 'appver=1.5.0.75771;';
-    // headers['referer'] = 'http://music.163.com';
-    // headers['User-Agent'] = req.headers['user-agent'];
-
-    // var url = 'http://music.163.com/api/song/detail/?id=' + id + '&ids=%5B' + id + '%5D';
-    // if (playlist_id) {
-    //     url = 'http://music.163.com/api/playlist/detail/?id=' + playlist_id;
-    // }
-    // netease_http(headers, url, next, function(data) {
-    //     var songs = data.songs;
-    //     songs.map(function(item) {
-    //         var url = item['mp3Url'];
-    //         item['sslUrl'] = url.replace('http://m', 'https://p');
-    //         return item;
-    //     });
-    //     data.songs = songs;
-    //     res.send(data)
-    //         // var output = {
-    //         //     data: data,
-    //         //     status: {
-    //         //         code: 200,
-    //         //         message: ''
-    //         //     }
-    //         // };
-    //         // if (req.query.callback) {
-    //         //     return res.jsonp(output)
-    //         // } else {
-    //         //     return res.send(output);
-    //         // }
-    // });
 });
 
-function netease_http(headers, url, next, callback) {
-    request.get(url).set(headers).end(function(err, res) {
-        var body = {};
-        if (res && res.text) {
-            body = res.text;
-        } else if (res && res.body) {
-            body = res.body;
-        }
-        if (typeof body === 'string') {
-            try {
-                body = JSON.parse(body);
-            } catch (e) {}
-        }
-        if (!err && res.statusCode == 200) {
-            callback && callback(body);
-        } else {
-            var error = new Error(err);
-            error.status = 404;
-            next(error);
-        }
-    });
-}
 
 module.exports = router;

+ 7 - 8
utils/Crypto.js → utils/encrypt.js

@@ -1,5 +1,4 @@
 // 参考 https://github.com/darknessomi/musicbox/wiki/
-'use strict'
 const crypto = require('crypto')
 const bigInt = require('big-integer')
 const modulus = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'
@@ -17,7 +16,7 @@ String.prototype.hexEncode = function() {
     return result
 }
 
-function createSecretKey(size) {
+const createSecretKey = (size) => {
     const keys = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
     let key = ""
     for (let i = 0; i < size; i++) {
@@ -28,7 +27,7 @@ function createSecretKey(size) {
     return key
 }
 
-function aesEncrypt(text, secKey) {
+const aesEncrypt = (text, secKey) => {
     const _text = text
     const lv = new Buffer('0102030405060708', "binary")
     const _secKey = new Buffer(secKey, "binary")
@@ -38,12 +37,12 @@ function aesEncrypt(text, secKey) {
     return encrypted
 }
 
-function zfill(str, size) {
+const zfill = (str, size) => {
     while (str.length < size) str = "0" + str
     return str
 }
 
-function rsaEncrypt(text, pubKey, modulus) {
+const rsaEncrypt = (text, pubKey, modulus) => {
     const _text = text.split('').reverse().join('')
     const biText = bigInt(new Buffer(_text).toString('hex'), 16),
         biEx = bigInt(pubKey, 16),
@@ -52,8 +51,8 @@ function rsaEncrypt(text, pubKey, modulus) {
     return zfill(biRet.toString(16), 256)
 }
 
-const Encrypt = (obj) => {
-    const text = JSON.stringify(obj)
+const encrypt = (params) => {
+    const text = JSON.stringify(params)
     const secKey = createSecretKey(16)
     const encText = aesEncrypt(aesEncrypt(text, nonce), secKey)
     const encSecKey = rsaEncrypt(secKey, pubKey, modulus)
@@ -63,4 +62,4 @@ const Encrypt = (obj) => {
     }
 }
 
-module.exports = Encrypt
+module.exports = encrypt

+ 3 - 2
utils/utils.js → utils/util.js

@@ -1,4 +1,4 @@
-const Encrypt = require('./crypto.js');
+const encrypt = require('./encrypt');
 const request = require('request');
 const qs = require('querystring');
 
@@ -17,7 +17,8 @@ let options = {
 }
 const requestServer = (config) => {
     options['uri'] = `http://music.163.com${config.path}`
-    let params = Encrypt(config.params)
+    console.log(config)
+    let params = encrypt(config.params)
     return new Promise((resolve, reject) => {
         request.post({ url: options.uri, form: params }, (err, ret, body) => {
             if (!err && ret.statusCode === 200) {