mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
添加cookie管理页
This commit is contained in:
+1
-28
@@ -1,7 +1,7 @@
|
||||
import { getFileContentByName, getLastModifyFilePath } from '../config/util';
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { Container } from 'typedi';
|
||||
import { Logger } from 'winston';
|
||||
import * as fs from 'fs';
|
||||
import config from '../config';
|
||||
const route = Router();
|
||||
|
||||
@@ -41,30 +41,3 @@ export default (app: Router) => {
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
function getFileContentByName(fileName) {
|
||||
if (fs.existsSync(fileName)) {
|
||||
return fs.readFileSync(fileName, 'utf8');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
function getLastModifyFilePath(dir) {
|
||||
var filePath = '';
|
||||
|
||||
if (fs.existsSync(dir)) {
|
||||
var lastmtime = 0;
|
||||
|
||||
var arr = fs.readdirSync(dir);
|
||||
|
||||
arr.forEach(function (item) {
|
||||
var fullpath = path.join(dir, item);
|
||||
var stats = fs.statSync(fullpath);
|
||||
if (stats.isFile()) {
|
||||
if (stats.mtimeMs >= lastmtime) {
|
||||
filePath = fullpath;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import { Container } from 'typedi';
|
||||
import CookieService from '../services/cookie';
|
||||
import { celebrate, Joi } from 'celebrate';
|
||||
import { Logger } from 'winston';
|
||||
import { getFileContentByName } from '../config/util';
|
||||
import config from '../config';
|
||||
const route = Router();
|
||||
|
||||
export default (app: Router) => {
|
||||
@@ -25,4 +27,34 @@ export default (app: Router) => {
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
route.get(
|
||||
'/cookies',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
const logger: Logger = Container.get('logger');
|
||||
try {
|
||||
const cookieService = Container.get(CookieService);
|
||||
const data = await cookieService.getCookies();
|
||||
return res.send({ code: 200, data });
|
||||
} catch (e) {
|
||||
logger.error('🔥 error: %o', e);
|
||||
return next(e);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
route.get(
|
||||
'/cookie',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
const logger: Logger = Container.get('logger');
|
||||
try {
|
||||
const cookieService = Container.get(CookieService);
|
||||
const data = await cookieService.addCookie();
|
||||
return res.send({ code: 200, data });
|
||||
} catch (e) {
|
||||
logger.error('🔥 error: %o', e);
|
||||
return next(e);
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user