重构后端,完善获取资源/下载列表、博客列表接口
This commit is contained in:
17
Server/src/Plugs/Middleware/Auth.ts
Normal file
17
Server/src/Plugs/Middleware/Auth.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import config from "../../config";
|
||||
import ServerStdResponse from "../../ServerStdResponse";
|
||||
import Logger from "../Logger";
|
||||
const logger = new Logger("Auth");
|
||||
const Auth = (req: Request, res: Response, next: NextFunction) => {
|
||||
let token = req.headers.authorization;
|
||||
if (token === config.authToken || token == config.adminToken) {
|
||||
next();
|
||||
} else {
|
||||
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.ip;
|
||||
logger.info(`API[${req.method}][${req.url.split('?')[0]}] 请求鉴权不通过[${token}][${ip}]`);
|
||||
res.json(ServerStdResponse.AUTH_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
export default Auth;
|
||||
17
Server/src/Plugs/Middleware/AuthAdmin.ts
Normal file
17
Server/src/Plugs/Middleware/AuthAdmin.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import config from "../../config";
|
||||
import ServerStdResponse from "../../ServerStdResponse";
|
||||
import Logger from "../Logger";
|
||||
const logger = new Logger("AuthAdmin");
|
||||
const AuthAdmin = (req: Request, res: Response, next: NextFunction) => {
|
||||
let token = req.headers.authorization;
|
||||
if (token === config.adminToken) {
|
||||
next();
|
||||
} else {
|
||||
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.ip;
|
||||
logger.info(`API[${req.method}][${req.url.split('?')[0]}] 请求鉴权不通过[${token}][${ip}]`);
|
||||
res.json(ServerStdResponse.AUTH_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
export default AuthAdmin;
|
||||
9
Server/src/Plugs/Middleware/Unbind.ts
Normal file
9
Server/src/Plugs/Middleware/Unbind.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import Logger from "../Logger";
|
||||
const logger = new Logger("Unbind");
|
||||
const Unbind = (req: Request, res: Response, next: NextFunction) => {
|
||||
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.ip;
|
||||
logger.info(`API[${req.method}][${req.url.split('?')[0]}] 请求了未绑定的接口[${ip}]`);
|
||||
}
|
||||
|
||||
export default Unbind;
|
||||
Reference in New Issue
Block a user