From 08892252575a89e6b7cb48f05b40b2d406f0e022 Mon Sep 17 00:00:00 2001 From: tone <3341154833@qq.com> Date: Sun, 22 Jun 2025 21:17:39 +0800 Subject: [PATCH] lint --- .../admin/controller/admin-user.controller.ts | 2 +- .../web/admin-web-resource.controller.ts | 2 +- tone-page-server/src/app.module.ts | 12 ++++--- tone-page-server/src/auth/auth.controller.ts | 2 +- tone-page-server/src/auth/auth.module.ts | 1 - tone-page-server/src/auth/role.enum.ts | 4 +-- .../src/auth/strategies/jwt.strategy.ts | 8 +++-- tone-page-server/src/blog/blog.controller.ts | 3 +- tone-page-server/src/blog/blog.service.ts | 2 +- .../src/common/guard/roles.guard.ts | 24 ++++++++------ .../src/notification/notification.service.ts | 31 +++++++++++-------- .../src/user/entities/user-session.entity.ts | 2 +- tone-page-server/src/user/user.service.ts | 4 +-- .../verification/verification.controller.ts | 10 ++++-- .../src/verification/verification.service.ts | 12 ++++--- .../app/console/(with-menu)/storage/page.tsx | 3 +- 16 files changed, 72 insertions(+), 50 deletions(-) diff --git a/tone-page-server/src/admin/controller/admin-user.controller.ts b/tone-page-server/src/admin/controller/admin-user.controller.ts index 6c3fd7a..d25d5f4 100644 --- a/tone-page-server/src/admin/controller/admin-user.controller.ts +++ b/tone-page-server/src/admin/controller/admin-user.controller.ts @@ -25,7 +25,7 @@ import { AuthGuard } from '@nestjs/passport'; @UseGuards(AuthGuard('jwt'), RolesGuard) @Roles(Role.Admin) export class AdminUserController { - constructor(private readonly userService: UserService) { } + constructor(private readonly userService: UserService) {} @Get() async list(@Query() listDto: ListDto) { diff --git a/tone-page-server/src/admin/controller/web/admin-web-resource.controller.ts b/tone-page-server/src/admin/controller/web/admin-web-resource.controller.ts index 3e5a919..ee130e4 100644 --- a/tone-page-server/src/admin/controller/web/admin-web-resource.controller.ts +++ b/tone-page-server/src/admin/controller/web/admin-web-resource.controller.ts @@ -20,7 +20,7 @@ import { ResourceService } from 'src/resource/resource.service'; @UseGuards(AuthGuard('jwt'), RolesGuard) @Roles(Role.Admin) export class AdminWebResourceController { - constructor(private readonly resourceService: ResourceService) { } + constructor(private readonly resourceService: ResourceService) {} @Get() async list() { diff --git a/tone-page-server/src/app.module.ts b/tone-page-server/src/app.module.ts index aeee023..9084e46 100644 --- a/tone-page-server/src/app.module.ts +++ b/tone-page-server/src/app.module.ts @@ -30,10 +30,12 @@ import { ThrottlerModule } from '@nestjs/throttler'; }), PassportModule.register({ defaultStrategy: 'jwt' }), ThrottlerModule.forRoot({ - throttlers: [{ - limit: 1000, - ttl: 60000, // 1 minute - }], + throttlers: [ + { + limit: 1000, + ttl: 60000, // 1 minute + }, + ], }), UserModule, AuthModule, @@ -47,4 +49,4 @@ import { ThrottlerModule } from '@nestjs/throttler'; controllers: [AppController], providers: [AppService], }) -export class AppModule { } +export class AppModule {} diff --git a/tone-page-server/src/auth/auth.controller.ts b/tone-page-server/src/auth/auth.controller.ts index 4b9b12d..05cf354 100644 --- a/tone-page-server/src/auth/auth.controller.ts +++ b/tone-page-server/src/auth/auth.controller.ts @@ -17,7 +17,7 @@ export class AuthController { constructor( private readonly authService: AuthService, private readonly userSessionService: UserSessionService, - ) { } + ) {} @Post('login') @UseGuards(ThrottlerGuard) diff --git a/tone-page-server/src/auth/auth.module.ts b/tone-page-server/src/auth/auth.module.ts index 870b2f0..6c13af9 100644 --- a/tone-page-server/src/auth/auth.module.ts +++ b/tone-page-server/src/auth/auth.module.ts @@ -10,7 +10,6 @@ import { JwtStrategy } from './strategies/jwt.strategy'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { VerificationModule } from 'src/verification/verification.module'; import { OptionalAuthGuard } from './strategies/OptionalAuthGuard'; -import { NotificationModule } from 'src/notification/notification.module'; @Module({ imports: [ diff --git a/tone-page-server/src/auth/role.enum.ts b/tone-page-server/src/auth/role.enum.ts index a286eb4..1ffa041 100644 --- a/tone-page-server/src/auth/role.enum.ts +++ b/tone-page-server/src/auth/role.enum.ts @@ -1,3 +1,3 @@ export enum Role { - Admin = 'admin', -} \ No newline at end of file + Admin = 'admin', +} diff --git a/tone-page-server/src/auth/strategies/jwt.strategy.ts b/tone-page-server/src/auth/strategies/jwt.strategy.ts index 817c184..99c4845 100644 --- a/tone-page-server/src/auth/strategies/jwt.strategy.ts +++ b/tone-page-server/src/auth/strategies/jwt.strategy.ts @@ -1,4 +1,8 @@ -import { BadRequestException, Injectable, UnauthorizedException } from '@nestjs/common'; +import { + BadRequestException, + Injectable, + UnauthorizedException, +} from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { PassportStrategy } from '@nestjs/passport'; import { ExtractJwt, Strategy } from 'passport-jwt'; @@ -37,7 +41,7 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') { return { ...user, - sessionId + sessionId, }; } } diff --git a/tone-page-server/src/blog/blog.controller.ts b/tone-page-server/src/blog/blog.controller.ts index 093350f..b753dab 100644 --- a/tone-page-server/src/blog/blog.controller.ts +++ b/tone-page-server/src/blog/blog.controller.ts @@ -3,7 +3,6 @@ import { Body, Controller, Get, - Ip, Param, ParseUUIDPipe, Post, @@ -21,7 +20,7 @@ export class BlogController { constructor( private readonly blogService: BlogService, private readonly userService: UserService, - ) { } + ) {} @Get() getBlogs() { diff --git a/tone-page-server/src/blog/blog.service.ts b/tone-page-server/src/blog/blog.service.ts index 71d39e3..5e4718b 100644 --- a/tone-page-server/src/blog/blog.service.ts +++ b/tone-page-server/src/blog/blog.service.ts @@ -11,7 +11,7 @@ export class BlogService { private readonly blogRepository: Repository, @InjectRepository(BlogComment) private readonly blogCommentRepository: Repository, - ) { } + ) {} async list() { return this.blogRepository.find({ diff --git a/tone-page-server/src/common/guard/roles.guard.ts b/tone-page-server/src/common/guard/roles.guard.ts index 6ef59f2..65340e2 100644 --- a/tone-page-server/src/common/guard/roles.guard.ts +++ b/tone-page-server/src/common/guard/roles.guard.ts @@ -1,30 +1,34 @@ -import { BadRequestException, CanActivate, ExecutionContext, ForbiddenException, Injectable } from '@nestjs/common'; +import { + BadRequestException, + CanActivate, + ExecutionContext, + ForbiddenException, + Injectable, +} from '@nestjs/common'; import { Reflector } from '@nestjs/core'; import { Role } from 'src/auth/role.enum'; import { User } from 'src/user/entities/user.entity'; @Injectable() export class RolesGuard implements CanActivate { - constructor( - private reflector: Reflector, - ) { } + constructor(private reflector: Reflector) {} async canActivate(context: ExecutionContext): Promise { - const requiredRoles = this.reflector.getAllAndOverride('roles', [ - context.getHandler(), - context.getClass(), - ]); + const requiredRoles = this.reflector.getAllAndOverride( + 'roles', + [context.getHandler(), context.getClass()], + ); if (!requiredRoles) return true; const request = context.switchToHttp().getRequest(); - const user = request.user as (User | void); + const user = request.user as User | void; if (!user) { throw new BadRequestException('服务器内部错误'); } - if (!requiredRoles.some(role => user.roles.includes(role))) { + if (!requiredRoles.some((role) => user.roles.includes(role))) { throw new ForbiddenException('权限不足'); } diff --git a/tone-page-server/src/notification/notification.service.ts b/tone-page-server/src/notification/notification.service.ts index 538a4e7..c177643 100644 --- a/tone-page-server/src/notification/notification.service.ts +++ b/tone-page-server/src/notification/notification.service.ts @@ -1,14 +1,13 @@ import { BadRequestException, Injectable } from '@nestjs/common'; import Dm20151123, * as $Dm20151123 from '@alicloud/dm20151123'; -import OpenApi, * as $OpenApi from '@alicloud/openapi-client'; -import Client, * as $dm from "@alicloud/dm20151123"; -import Util, * as $Util from '@alicloud/tea-util'; +import * as $OpenApi from '@alicloud/openapi-client'; +// import Client, * as $dm from '@alicloud/dm20151123'; +import * as $Util from '@alicloud/tea-util'; import Credential, { Config } from '@alicloud/credentials'; @Injectable() export class NotificationService { - private dm: Dm20151123; constructor() { @@ -23,7 +22,7 @@ export class NotificationService { this.dm = new Dm20151123(config); } - private getMailHtmlBody(option: { type: 'login-verify', code: string }) { + private getMailHtmlBody(option: { type: 'login-verify'; code: string }) { if (option.type === 'login-verify') { return ` @@ -76,25 +75,31 @@ export class NotificationService { - ` + `; } else { throw new Error('未配置的模版'); } } - - async sendMail(option: { type: 'login-verify', targetMail: string, code: string; }) { + async sendMail(option: { + type: 'login-verify'; + targetMail: string; + code: string; + }) { const runtime = new $Util.RuntimeOptions({}); const singleSendMailRequest = new $Dm20151123.SingleSendMailRequest({ - accountName: "security@tonesc.cn", + accountName: 'security@tonesc.cn', addressType: 1, replyToAddress: false, toAddress: `${option.targetMail}`, - subject: "【特恩的日志】登陆验证码", - htmlBody: this.getMailHtmlBody({ type: 'login-verify', code: option.code }), - textBody: "", - }) + subject: '【特恩的日志】登陆验证码', + htmlBody: this.getMailHtmlBody({ + type: 'login-verify', + code: option.code, + }), + textBody: '', + }); try { await this.dm.singleSendMailWithOptions(singleSendMailRequest, runtime); diff --git a/tone-page-server/src/user/entities/user-session.entity.ts b/tone-page-server/src/user/entities/user-session.entity.ts index 6c1aede..121c31f 100644 --- a/tone-page-server/src/user/entities/user-session.entity.ts +++ b/tone-page-server/src/user/entities/user-session.entity.ts @@ -28,4 +28,4 @@ export class UserSession { /** * 考虑是否使用sessionId代替id,以节省存储空间 - */ \ No newline at end of file + */ diff --git a/tone-page-server/src/user/user.service.ts b/tone-page-server/src/user/user.service.ts index e52adea..7d500ef 100644 --- a/tone-page-server/src/user/user.service.ts +++ b/tone-page-server/src/user/user.service.ts @@ -18,7 +18,7 @@ export class UserService { constructor( @InjectRepository(User) private readonly userRepository: Repository, - ) { } + ) {} /** * @deprecated 尽量不使用该方法 @@ -40,7 +40,7 @@ export class UserService { return this.userRepository.findOne({ where: { userId, - } + }, }); } diff --git a/tone-page-server/src/verification/verification.controller.ts b/tone-page-server/src/verification/verification.controller.ts index eb8f482..e54e421 100644 --- a/tone-page-server/src/verification/verification.controller.ts +++ b/tone-page-server/src/verification/verification.controller.ts @@ -1,11 +1,17 @@ -import { BadRequestException, Body, Controller, Post, UseGuards } from '@nestjs/common'; +import { + BadRequestException, + Body, + Controller, + Post, + UseGuards, +} from '@nestjs/common'; import { SendVerificationCodeDto } from './dto/send-verification-code.dto'; import { VerificationService } from './verification.service'; import { Throttle, ThrottlerGuard } from '@nestjs/throttler'; @Controller('verification') export class VerificationController { - constructor(private readonly verificationService: VerificationService) { } + constructor(private readonly verificationService: VerificationService) {} @Post('send') @UseGuards(ThrottlerGuard) diff --git a/tone-page-server/src/verification/verification.service.ts b/tone-page-server/src/verification/verification.service.ts index 340ac9b..ba925dd 100644 --- a/tone-page-server/src/verification/verification.service.ts +++ b/tone-page-server/src/verification/verification.service.ts @@ -5,7 +5,7 @@ import { NotificationService } from 'src/notification/notification.service'; export class VerificationService { private readonly logger = new Logger(VerificationService.name); - constructor(private readonly notificationService: NotificationService) { } + constructor(private readonly notificationService: NotificationService) {} private pool: Map< string, @@ -51,10 +51,12 @@ export class VerificationService { this.saveCode(key, code); this.logger.log(`Email[${email}] code: ${code}`); // 发送验证码 - await this.notificationService.sendMail({ type: 'login-verify', targetMail: email, code, }).catch(() => { - this.clearCode(key); - throw new BadRequestException('发送失败,请稍后再试'); - }) + await this.notificationService + .sendMail({ type: 'login-verify', targetMail: email, code }) + .catch(() => { + this.clearCode(key); + throw new BadRequestException('发送失败,请稍后再试'); + }); return true; } diff --git a/tone-page-web/app/console/(with-menu)/storage/page.tsx b/tone-page-web/app/console/(with-menu)/storage/page.tsx index 1df6e65..d75cd32 100644 --- a/tone-page-web/app/console/(with-menu)/storage/page.tsx +++ b/tone-page-web/app/console/(with-menu)/storage/page.tsx @@ -53,7 +53,7 @@ export default function Page() { refreshSTSToken: async () => { await storeMeta.refresh(); if (!storeMeta.stsTokenData) throw new Error(); - const { AccessKeyId, AccessKeySecret, SecurityToken } = data; + const { AccessKeyId, AccessKeySecret, SecurityToken } = storeMeta.stsTokenData; return { accessKeyId: AccessKeyId, accessKeySecret: AccessKeySecret, @@ -65,6 +65,7 @@ export default function Page() { ossStore.setStore(store); ossStore.setWorkDir(`tone-page/${data.userId}`) ossStore.loadObjectList(); + // eslint-disable-next-line react-hooks/exhaustive-deps -- storeMeta引用会导致无限循环,依赖stsTokenData即可 }, [storeMeta.stsTokenData]); const handleRefreshFileList = async () => ossStore.loadObjectList().catch(e => toast.error(e.message));