add sqlite 保存下载历史

This commit is contained in:
2023-06-28 21:11:21 +08:00
parent 95f09a96b8
commit b439920702
9 changed files with 109 additions and 30 deletions

View File

@@ -2,9 +2,10 @@ const Router = require("koa-router")
const { getQqListData } = require("../util/getList/qq")
const KoaSSEStream = require('koa-sse-stream');
const { dowload } = require("../util/download");
const { addDownList, getDownList, setDownState } = require("../util/sql/download");
const dayjs = require("dayjs")
const router = new Router()
const dowloadlist = []
// const dowloadlist = []
router.get("/getQqList",async (ctx)=>{
let url = ctx.query.url
@@ -16,10 +17,11 @@ router.get("/startDown",async (ctx)=>{
let title = ctx.query.title
let url = ctx.query.url
let save = ctx.query.save
dowloadlist.push({
title,url,save
})
// dowloadlist.push({
// title,url,save
// })
// startDown()
addDownList(title,url,save,new Date().getTime(),0)
ctx.body={
code:0,
msg:"添加成功"
@@ -36,27 +38,31 @@ router.get('/msg', KoaSSEStream(SSE_CONF), ctx => {
// 每次连接会进行一个 push
clientList.push(ctx.sse);
if(clientList.length > 5){
// 删除
// 超过5个删除最开始的一个
// todo 浏览器关闭后自动检测删除
clientList.shift()
}
})
let start = false
function startDown(){
function startDown(data){
start = true
dowload(dowloadlist[0],(data,isok)=>{
let name = dowloadlist[0].title
dowload(data,async (data2,isok)=>{
let name = data2.title
clientList.forEach((i)=>{
i.send(isok ? `${name}下载完成` : data )
i.send(isok ? `${name}下载完成` : data2 )
})
if(isok){
dowloadlist.shift()
// dowloadlist.shift()
await setDownState(data.id,1)
start = false
}
})
}
setInterval(()=>{
setInterval(async ()=>{
let dowloadlist = await getDownList()
console.log(dowloadlist)
if(dowloadlist.length != 0 && !start){
startDown()
startDown(dowloadlist[0])
}else if(dowloadlist.length == 0){
start = false
}

View File

@@ -13,7 +13,7 @@ router.get("/search",async (ctx)=>{
ctx.body = info
})
route.get("/getinfo",async (ctx)=>{
router.get("/getinfo",async (ctx)=>{
let url = ctx.query.url
let info = await getinfo(url)
ctx.body = info