commit 7e80109eb90cbc84fbf09a82f73da823a37da453 Author: RainSun Date: Wed Aug 5 22:45:44 2020 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c715c39 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +#制定node镜像的版本 +FROM node:8.9-alpine +#声明作者 +MAINTAINER robin +#移动当前目录下面的文件到app目录下 +ADD . /app/ +#进入到app目录下面,类似cd +WORKDIR /app +#安装依赖 +RUN npm install +#程序启动脚本 +CMD ["npm", "start"] \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..caf2645 --- /dev/null +++ b/main.js @@ -0,0 +1,31 @@ +const Koa = require('koa'); +var router = require("koa-router"); +const moment = require('moment'); +const crypto = require('crypto'); + +const app = new Koa(); +const _ = new router() + +_.get('/qingting/', manageRedirect) +_.get('/qingting/:channel_id', manageRedirect) + +async function manageRedirect(ctx) { + let channel_id = ctx.params.channel_id || 388 + let url = getUrl(channel_id) + console.log(url) + ctx.response.redirect(url); +} + +function getUrl(channel_id) { + const channel_path = `/live/${channel_id}/64k.mp3` + const encode_channel_path = encodeURIComponent(channel_path) + const time = encodeURIComponent(moment().add(1, "hours").unix().toString(16)) + const app_id = encodeURIComponent('web') + var sign_path = "app_id=".concat(app_id, "&path=").concat(encode_channel_path, "&ts=").concat(time) + var sign = crypto.createHmac("md5", "Lwrpu$K5oP").update(sign_path).digest("hex").toString(); + var path = `https://lhttp.qingting.fm${channel_path}?app_id=${app_id}&ts=${time}&sign=${sign}` + return path +} + +app.use(_.routes()) +app.listen(80); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..49755ad --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "qingting", + "version": "1.0.0", + "description": "redirect to qingting", + "main": "main.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node main.js" + }, + "author": "RainSun", + "license": "ISC", + "dependencies": { + "crypto": "^1.0.1", + "koa": "^2.0.0", + "koa-router": "^7.4.0", + "moment": "^2.27.0" + } +}