|
|
@@ -0,0 +1,39 @@
|
|
|
+import { passWordJie } from '../util/pass.js';
|
|
|
+import resSend from '../util/resSend.js';
|
|
|
+
|
|
|
+const proofZhong = (req: any, res: any, next: any) => {
|
|
|
+ const urlAll: string = req.originalUrl;
|
|
|
+
|
|
|
+ if (urlAll.includes('getProof?proof=4DAGE')) {
|
|
|
+ next();
|
|
|
+ } else {
|
|
|
+ // 获取请求头里面的 proof
|
|
|
+ let proof: string = req.headers.proof || '';
|
|
|
+ if (!proof) return resSend(res, 401, 'proof is null');
|
|
|
+
|
|
|
+ try {
|
|
|
+ const [timeCuo, timeMi, timeShi] = proof.split('||');
|
|
|
+
|
|
|
+ if (timeCuo && timeMi && timeShi) {
|
|
|
+ // 传入的时间戳-转成Number类型
|
|
|
+ const timeCuoRes = Number(timeCuo);
|
|
|
+
|
|
|
+ // 传入的时间戳加密-解密
|
|
|
+ const timeMiRes = passWordJie(timeMi);
|
|
|
+
|
|
|
+ // 传入proof有效的时间(加密字符串) - 解密
|
|
|
+ const timeShiRes = passWordJie(timeShi);
|
|
|
+
|
|
|
+ if (timeMiRes !== timeCuo) return resSend(res, 401, 'proof err');
|
|
|
+
|
|
|
+ if (Date.now() - timeCuoRes > Number(timeShiRes)) return resSend(res, 401, 'proof err');
|
|
|
+
|
|
|
+ next();
|
|
|
+ } else return resSend(res, 401, 'proof err');
|
|
|
+ } catch (error: any) {
|
|
|
+ return resSend(res, 401, 'proof err');
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+export default proofZhong;
|