返回 AiToEarn
original.guard.ts
根目录 / project / aitoearn-electron / server / src / guard / original.guard.ts
1 /*
2 * @Author: nevin
3 * @Date: 2024-12-22 21:14:15
4 * @LastEditTime: 2025-02-25 22:13:11
5 * @LastEditors: nevin
6 * @Description: 保留原始请求守卫
7 */
8 import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
9 import { SetMetadata } from '@nestjs/common';
10 import { Reflector } from '@nestjs/core';
11
12 export const IS_ORIGINAL_KEY = 'isOriginal';
13 export const Original = () => SetMetadata(IS_ORIGINAL_KEY, true);
14
15 @Injectable()
16 export class OriginalGuard implements CanActivate {
17 constructor(private reflector: Reflector) {}
18
19 async canActivate(context: ExecutionContext): Promise<boolean> {
20 const isPass = this.reflector.getAllAndOverride<boolean>(IS_ORIGINAL_KEY, [
21 context.getHandler(),
22 context.getClass(),
23 ]);
24 if (isPass) {
25 // 💡 查看此条件
26 return true;
27 }
28
29 return true;
30 }
31 }
32
32 lines TYPESCRIPT