| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2025-02-15 20:59:55 |
| 4 | * @LastEditTime: 2025-04-27 18:00:18 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: signIn SignIn 签到 |
| 7 | */ |
| 8 | import { |
| 9 | Body, |
| 10 | Controller, |
| 11 | Get, |
| 12 | Param, |
| 13 | Post, |
| 14 | Query, |
| 15 | UploadedFile, |
| 16 | UseInterceptors, |
| 17 | } from '@nestjs/common'; |
| 18 | import { ApiOperation, ApiTags } from '@nestjs/swagger'; |
| 19 | import { |
| 20 | AccessBackDto, |
| 21 | ArchiveAddByUtokenBodyDto, |
| 22 | ArchiveAddByUtokenQueryDto, |
| 23 | } from './dto/bilibili.dto'; |
| 24 | import { BilibiliService } from './bilibili.service'; |
| 25 | import { GetToken, Public } from 'src/auth/auth.guard'; |
| 26 | import { FileInterceptor } from '@nestjs/platform-express'; |
| 27 | import { TokenInfo } from 'src/auth/interfaces/auth.interfaces'; |
| 28 | |
| 29 | @ApiTags('plat/bilibili - B站平台') |
| 30 | @Controller('plat/bilibili') |
| 31 | export class BilibiliController { |
| 32 | constructor(private readonly bilibiliService: BilibiliService) {} |
| 33 | |
| 34 | @ApiOperation({ summary: '获取页面的认证URL' }) |
| 35 | @Get('auth/url/:type') |
| 36 | async getAuthUrl( |
| 37 | @GetToken() token: TokenInfo, |
| 38 | @Param('type') type: 'h5' | 'pc', |
| 39 | ) { |
| 40 | const res = await this.bilibiliService.getAuthUrl(token.id, type); |
| 41 | return res; |
| 42 | } |
| 43 | |
| 44 | @ApiOperation({ summary: '获取AccessToken,并记录到用户,给平台回调用' }) |
| 45 | @Public() |
| 46 | @Get('auth/back/:userId') |
| 47 | async getAccessToken( |
| 48 | @Param('userId') userId: string, |
| 49 | @Query() query: AccessBackDto, |
| 50 | ) { |
| 51 | const res = await this.bilibiliService.setUserAccessToken({ |
| 52 | userId, |
| 53 | ...query, |
| 54 | }); |
| 55 | return res; |
| 56 | } |
| 57 | |
| 58 | @ApiOperation({ summary: '查询用户已授权权限列表' }) |
| 59 | @Get('account/scopes') |
| 60 | async getAccountScopes(@GetToken() token: TokenInfo) { |
| 61 | const accessToken = await this.bilibiliService.getUserAccessToken(token.id); |
| 62 | return this.bilibiliService.getAccountScopes(accessToken); |
| 63 | } |
| 64 | |
| 65 | @ApiOperation({ summary: '视频初始化' }) |
| 66 | @Post('video/init') |
| 67 | async videoInit(@GetToken() token: TokenInfo) { |
| 68 | const accessToken = await this.bilibiliService.getUserAccessToken(token.id); |
| 69 | return this.bilibiliService.videoInit(accessToken); |
| 70 | } |
| 71 | |
| 72 | @ApiOperation({ summary: '封面上传' }) |
| 73 | @UseInterceptors(FileInterceptor('file')) |
| 74 | @Post('cover/upload') |
| 75 | async coverUpload( |
| 76 | @GetToken() token: TokenInfo, |
| 77 | @UploadedFile() file: Express.Multer.File, |
| 78 | ) { |
| 79 | const accessToken = await this.bilibiliService.getUserAccessToken(token.id); |
| 80 | return this.bilibiliService.coverUpload(accessToken, file); |
| 81 | } |
| 82 | |
| 83 | @ApiOperation({ summary: '视频稿件提交' }) |
| 84 | @Post('archive/add-by-utoken') |
| 85 | async archiveAddByUtoken( |
| 86 | @Query() query: ArchiveAddByUtokenQueryDto, |
| 87 | @Body() body: ArchiveAddByUtokenBodyDto, |
| 88 | ) { |
| 89 | const data = { |
| 90 | ...body, |
| 91 | no_reprint: body.noReprint, |
| 92 | tag: body.tag.join(','), |
| 93 | }; |
| 94 | const { accessToken, uploadToken } = query; |
| 95 | return this.bilibiliService.archiveAddByUtoken( |
| 96 | accessToken, |
| 97 | uploadToken, |
| 98 | data, |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | @ApiOperation({ summary: '分区查询' }) |
| 103 | @Get('archive/type/list/:accessToken') |
| 104 | async archiveTypeList(@GetToken() token: TokenInfo) { |
| 105 | const accessToken = await this.bilibiliService.getUserAccessToken(token.id); |
| 106 | return this.bilibiliService.archiveTypeList(accessToken); |
| 107 | } |
| 108 | } |
| 109 |