add 配置读取写入
This commit is contained in:
parent
c4f88a5368
commit
a0d7b9b17f
5
config.json
Normal file
5
config.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"downloadPath": "",
|
||||||
|
"vCookies": "",
|
||||||
|
"torrentSavePath": ""
|
||||||
|
}
|
4
index.js
4
index.js
@ -2,7 +2,7 @@ const Koa = require('koa');
|
|||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
const static = require('koa-static')
|
const static = require('koa-static')
|
||||||
app.use(static("./view/dist"))
|
app.use(static("./view/dist"))
|
||||||
const { koaBody } = require('koa-body');
|
const {koaBody} = require('koa-body');
|
||||||
const KoaSSEStream = require('koa-sse-stream');
|
const KoaSSEStream = require('koa-sse-stream');
|
||||||
|
|
||||||
app.use(koaBody());
|
app.use(koaBody());
|
||||||
@ -20,7 +20,9 @@ app.use(async (ctx, next) => {
|
|||||||
const index = require("./router/index.js")
|
const index = require("./router/index.js")
|
||||||
app.use(index.routes()).use(index.allowedMethods())
|
app.use(index.routes()).use(index.allowedMethods())
|
||||||
const videoInfo = require("./router/videoInfo.js");
|
const videoInfo = require("./router/videoInfo.js");
|
||||||
|
const config = require("./router/config.js")
|
||||||
|
|
||||||
|
app.use(config.routes()).use(config.allowedMethods())
|
||||||
app.use(videoInfo.routes()).use(videoInfo.allowedMethods())
|
app.use(videoInfo.routes()).use(videoInfo.allowedMethods())
|
||||||
app.listen(3050, "0.0.0.0");
|
app.listen(3050, "0.0.0.0");
|
||||||
|
|
||||||
|
32
router/config.js
Normal file
32
router/config.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
const Router = require("koa-router")
|
||||||
|
const config = require("../util/config/config")
|
||||||
|
const router = new Router({
|
||||||
|
prefix: "/config"
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置文件接口
|
||||||
|
*/
|
||||||
|
router.get('/getConfig', async (ctx) => {
|
||||||
|
let json = config.getConfig();
|
||||||
|
const b = json === '{}'
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: b ? -1 : 0,
|
||||||
|
msg: b ? 'ok' : "error",
|
||||||
|
data: json
|
||||||
|
}
|
||||||
|
})
|
||||||
|
/**
|
||||||
|
* 设置配置文件接口
|
||||||
|
*/
|
||||||
|
router.get('/setConfig', async (ctx) => {
|
||||||
|
let b = config.setConfig(ctx.data);
|
||||||
|
return {
|
||||||
|
code: b ? -1 : 0,
|
||||||
|
msg: b ? 'ok' : "error",
|
||||||
|
data: null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router
|
30
util/config/config.js
Normal file
30
util/config/config.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const fs = require("fs");
|
||||||
|
const {cwd} = require("process");
|
||||||
|
const path = require('path');
|
||||||
|
let configPath = path.join(cwd(), "/config.json");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置文件
|
||||||
|
* @returns {JSON}
|
||||||
|
*/
|
||||||
|
function getConfig() {
|
||||||
|
let file = fs.readFileSync(configPath);
|
||||||
|
return JSON.parse(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存配置文件
|
||||||
|
* @param string {JSON}
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
function setConfig(string) {
|
||||||
|
fs.writeFileSync("config.json", JSON.stringify(string, null, 2));
|
||||||
|
return getConfig() === string;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getConfig,
|
||||||
|
setConfig
|
||||||
|
}
|
1
view/dist/assets/index-6ef103ac.css
vendored
1
view/dist/assets/index-6ef103ac.css
vendored
File diff suppressed because one or more lines are too long
4
view/dist/index.html
vendored
4
view/dist/index.html
vendored
@ -6,8 +6,8 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Vite + Vue</title>
|
<title>Vite + Vue</title>
|
||||||
<meta name="referrer" content="never">
|
<meta name="referrer" content="never">
|
||||||
<script type="module" crossorigin src="./assets/index-b619957d.js"></script>
|
<script type="module" crossorigin src="./assets/index-ccfbebb1.js"></script>
|
||||||
<link rel="stylesheet" href="./assets/index-6ef103ac.css">
|
<link rel="stylesheet" href="./assets/index-e0450ab1.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
Loading…
Reference in New Issue
Block a user