update 添加注释

This commit is contained in:
SummerTail 2023-08-03 21:41:18 +08:00
parent da5dd7ebf9
commit 1169a9b997
3 changed files with 64 additions and 22 deletions

View File

@ -1,3 +1,7 @@
/*
配置文件获取修改接口
*/
const Router = require("koa-router") const Router = require("koa-router")
const config = require("../util/config/config") const config = require("../util/config/config")
const router = new Router({ const router = new Router({

View File

@ -9,7 +9,10 @@ const axios = require("axios");
const router = new Router() const router = new Router()
// const download = [] // const download = []
// 豆瓣img代理
/**
* 豆瓣img代理
*/
router.get("/doubanImg",async (ctx)=>{ router.get("/doubanImg",async (ctx)=>{
let url = ctx.query.url let url = ctx.query.url
let res = await axios.get(url,{ let res = await axios.get(url,{
@ -23,6 +26,9 @@ router.get("/doubanImg",async (ctx)=>{
}) })
/**
* 功能测试接口
*/
router.get("/test", async (ctx) => { router.get("/test", async (ctx) => {
// let res = await utils.uploadImg('C:/Users/11629/Desktop/80032464_p0.jpg') // let res = await utils.uploadImg('C:/Users/11629/Desktop/80032464_p0.jpg')
// ctx.body = { // ctx.body = {
@ -34,7 +40,9 @@ router.get("/test", async (ctx) => {
}) })
/**
* 视频文件信息获取
*/
router.get("/getMediaInfo", async (ctx) => { router.get("/getMediaInfo", async (ctx) => {
let url = ctx.query.filePath let url = ctx.query.filePath
let data let data
@ -50,6 +58,9 @@ router.get("/getMediaInfo", async (ctx) => {
} }
}) })
/**
* 不知道干嘛的
*/
router.get("/getQqList", async (ctx) => { router.get("/getQqList", async (ctx) => {
let url = ctx.query.url let url = ctx.query.url
let video_id = url.split("/") let video_id = url.split("/")
@ -62,6 +73,9 @@ router.get("/getQqList", async (ctx) => {
ctx.body = await getQqListData(url) ctx.body = await getQqListData(url)
}) })
/**
* 不知道干嘛的
*/
router.get("/startDown", async (ctx) => { router.get("/startDown", async (ctx) => {
let title = ctx.query.title let title = ctx.query.title
let url = ctx.query.url let url = ctx.query.url
@ -86,6 +100,10 @@ const SSE_CONF = {
maxClients: 5, // 最大连接数 maxClients: 5, // 最大连接数
pingInterval: 40000 // 重连时间 pingInterval: 40000 // 重连时间
} }
/**
* 还是不知道干嘛的
*/
router.get('/msg', KoaSSEStream(SSE_CONF), ctx => { router.get('/msg', KoaSSEStream(SSE_CONF), ctx => {
// 每次连接会进行一个 push // 每次连接会进行一个 push
clientList.push(ctx.sse); clientList.push(ctx.sse);
@ -120,4 +138,4 @@ let start = false
// start = false // start = false
// } // }
// }, 1000) // }, 1000)
module.exports = router module.exports = router

View File

@ -1,5 +1,5 @@
const Router = require("koa-router") const Router = require("koa-router")
const { serach, gen_douban } = require("../util/ptgen") const {serach, gen_douban} = require("../util/ptgen")
const axios = require("axios") const axios = require("axios")
const cheerio = require("cheerio"); const cheerio = require("cheerio");
const {addSub, getSub, delSub} = require("../util/sql/video"); // HTML页面解析 const {addSub, getSub, delSub} = require("../util/sql/video"); // HTML页面解析
@ -9,23 +9,26 @@ const router = new Router({
}) })
/**
* 可能为重复方法
*/
router.get("/search", async (ctx) => { router.get("/search", async (ctx) => {
let name = ctx.query.name let name = ctx.query.name
ctx.body = await serach(name) ctx.body = await serach(name)
}) })
// router.get("/getinfo",async (ctx)=>{ /**
// let url = ctx.query.url * 豆瓣搜索
// let info = await getinfo(url) */
// ctx.body = info
// })
router.get("/searchVideo", async (ctx) => { router.get("/searchVideo", async (ctx) => {
let name = ctx.query.name let name = ctx.query.name
ctx.body = await serach(name) ctx.body = await serach(name)
}) })
/**
* 获取豆瓣描述
*/
router.get("/getVideoInfo", async (ctx) => { router.get("/getVideoInfo", async (ctx) => {
let id = ctx.query.id let id = ctx.query.id
if (!id) { if (!id) {
@ -36,31 +39,39 @@ router.get("/getVideoInfo", async (ctx) => {
}) })
/**
* 添加订阅
*/
router.post("/addSubscribe", async (ctx) => { router.post("/addSubscribe", async (ctx) => {
// console.log(ctx.request.body) // console.log(ctx.request.body)
let data = ctx.request.body let data = ctx.request.body
try { try {
let r = await addSub(data) let r = await addSub(data)
if(r){ if (r) {
ctx.body = "订阅已存在" ctx.body = "订阅已存在"
}else{ } else {
ctx.body = "添加成功" ctx.body = "添加成功"
} }
}catch { } catch {
ctx.body = "添加失败" ctx.body = "添加失败"
} }
}) })
router.get("/getSubscribe",async (ctx)=>{ /**
let list = await getSub() * 获取订阅列表
ctx.body = list */
router.get("/getSubscribe", async (ctx) => {
ctx.body = await getSub()
}) })
/**
* 从imdb获取影视英文名称
*/
router.get("/getImdbName", async (ctx) => { router.get("/getImdbName", async (ctx) => {
let res = await axios.get(ctx.query.url, { let res = await axios.get(ctx.query.url, {
proxy: false, proxy: false,
headers:{ headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67" "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67"
} }
}) })
@ -70,13 +81,22 @@ router.get("/getImdbName", async (ctx) => {
ctx.body = $("h1").text() ctx.body = $("h1").text()
}) })
router.get("/delSubscribe",async (ctx)=>{ /**
* 删除订阅任务
*/
router.get("/delSubscribe", async (ctx) => {
try { try {
await delSub(ctx.query.id) await delSub(ctx.query.id)
ctx.body = "删除成功" ctx.body = {
}catch { code: 0,
ctx.body = "删除失败" msg: "删除成功"
}
} catch {
ctx.body = {
code: 0,
msg: "删除失败"
}
} }
}) })
module.exports = router module.exports = router