2023-06-14 15:43:04 +08:00
|
|
|
const Router = require("koa-router")
|
2023-06-30 20:49:07 +08:00
|
|
|
const {getQqListData} = require("../util/getList/qq")
|
2023-06-30 22:56:45 +08:00
|
|
|
const utils = require("../util/utils")
|
2023-06-14 15:43:04 +08:00
|
|
|
const KoaSSEStream = require('koa-sse-stream');
|
2023-06-30 20:49:07 +08:00
|
|
|
const {dowload} = require("../util/download");
|
|
|
|
const {addDownList, getDownList, setDownState} = require("../util/sql/download");
|
2023-07-02 00:18:16 +08:00
|
|
|
const {getMediaInfo} = require("../util/utils");
|
2023-07-12 14:51:00 +08:00
|
|
|
const axios = require("axios");
|
2023-06-14 15:43:04 +08:00
|
|
|
const router = new Router()
|
2023-07-03 12:04:52 +08:00
|
|
|
// const download = []
|
2023-06-14 15:43:04 +08:00
|
|
|
|
2023-07-12 14:51:00 +08:00
|
|
|
// 豆瓣img代理
|
|
|
|
router.get("/doubanImg",async (ctx)=>{
|
|
|
|
let url = ctx.query.url
|
|
|
|
let res = await axios.get(url,{
|
|
|
|
proxy:false,
|
|
|
|
headers:{
|
|
|
|
Referer: "https://movie.douban.com/"
|
|
|
|
},
|
|
|
|
responseType:"stream"
|
|
|
|
})
|
|
|
|
ctx.body = res.data
|
|
|
|
})
|
|
|
|
|
2023-07-04 19:04:31 +08:00
|
|
|
|
|
|
|
router.get("/test", async (ctx) => {
|
2023-07-31 22:24:56 +08:00
|
|
|
// let res = await utils.uploadImg('C:/Users/11629/Desktop/80032464_p0.jpg')
|
|
|
|
// ctx.body = {
|
|
|
|
// code: 0,
|
|
|
|
// msg: "test",
|
|
|
|
// data: res
|
|
|
|
// }
|
|
|
|
global.start = true
|
2023-07-04 19:04:31 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-07-02 00:18:16 +08:00
|
|
|
router.get("/getMediaInfo", async (ctx) => {
|
|
|
|
let url = ctx.query.filePath
|
|
|
|
let data
|
|
|
|
await getMediaInfo(url).then(value => {
|
|
|
|
data = value;
|
|
|
|
})
|
2023-07-02 00:32:27 +08:00
|
|
|
let verify = (data.media === null)
|
|
|
|
console.info(verify)
|
2023-07-02 00:18:16 +08:00
|
|
|
ctx.body = {
|
2023-07-02 00:32:27 +08:00
|
|
|
code: verify ? -1 : 0,
|
|
|
|
msg: verify ? "读取文件失败" : "",
|
2023-07-02 00:18:16 +08:00
|
|
|
data: data
|
|
|
|
}
|
|
|
|
})
|
2023-06-30 20:49:07 +08:00
|
|
|
|
|
|
|
router.get("/getQqList", async (ctx) => {
|
2023-06-14 15:43:04 +08:00
|
|
|
let url = ctx.query.url
|
2023-07-03 12:04:52 +08:00
|
|
|
let video_id = url.split("/")
|
|
|
|
for (let i in video_id) {
|
|
|
|
if (video_id[i] === "cover") {
|
|
|
|
video_id = video_id[i + 1].replace(".html")
|
2023-06-29 22:00:07 +08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2023-07-03 12:04:52 +08:00
|
|
|
ctx.body = await getQqListData(url)
|
2023-06-14 15:43:04 +08:00
|
|
|
})
|
|
|
|
|
2023-06-30 20:49:07 +08:00
|
|
|
router.get("/startDown", async (ctx) => {
|
2023-06-14 15:43:04 +08:00
|
|
|
let title = ctx.query.title
|
|
|
|
let url = ctx.query.url
|
2023-06-14 22:02:50 +08:00
|
|
|
let save = ctx.query.save
|
2023-07-03 12:04:52 +08:00
|
|
|
// download.push({
|
2023-06-28 21:11:21 +08:00
|
|
|
// title,url,save
|
|
|
|
// })
|
2023-06-14 15:43:04 +08:00
|
|
|
// startDown()
|
2023-06-30 20:49:07 +08:00
|
|
|
addDownList(title, url, save, new Date().getTime(), 0)
|
|
|
|
ctx.body = {
|
|
|
|
code: 0,
|
|
|
|
msg: "添加成功"
|
2023-06-14 15:43:04 +08:00
|
|
|
}
|
|
|
|
})
|
2023-07-01 23:08:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-14 15:43:04 +08:00
|
|
|
// 连接池
|
|
|
|
const clientList = [];
|
|
|
|
// koa-sse-stream 配置
|
|
|
|
const SSE_CONF = {
|
|
|
|
maxClients: 5, // 最大连接数
|
|
|
|
pingInterval: 40000 // 重连时间
|
|
|
|
}
|
|
|
|
router.get('/msg', KoaSSEStream(SSE_CONF), ctx => {
|
|
|
|
// 每次连接会进行一个 push
|
|
|
|
clientList.push(ctx.sse);
|
2023-06-30 20:49:07 +08:00
|
|
|
if (clientList.length > 5) {
|
2023-06-28 21:11:21 +08:00
|
|
|
// 超过5个删除最开始的一个
|
|
|
|
// todo 浏览器关闭后自动检测删除
|
2023-06-15 10:47:25 +08:00
|
|
|
clientList.shift()
|
|
|
|
}
|
2023-06-14 15:43:04 +08:00
|
|
|
})
|
|
|
|
let start = false
|
2023-07-22 15:56:26 +08:00
|
|
|
// 下载检测
|
|
|
|
// function startDown(data) {
|
|
|
|
// start = true
|
|
|
|
// dowload(data, async (data2, isok) => {
|
|
|
|
// let name = data2.title
|
|
|
|
// clientList.forEach((i) => {
|
|
|
|
// i.send(isok ? `${name}下载完成` : data2)
|
|
|
|
// })
|
|
|
|
// if (isok) {
|
|
|
|
// // dowloadlist.shift()
|
|
|
|
// await setDownState(data.id, 1)
|
|
|
|
// start = false
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// 定时检测下载地址
|
|
|
|
// setInterval(async () => {
|
|
|
|
// let dowloadlist = await getDownList()
|
|
|
|
// if (dowloadlist.length !== 0 && !start) {
|
|
|
|
// startDown(dowloadlist[0])
|
|
|
|
// } else if (dowloadlist.length === 0) {
|
|
|
|
// start = false
|
|
|
|
// }
|
|
|
|
// }, 1000)
|
2023-06-14 15:43:04 +08:00
|
|
|
module.exports = router
|