feat: 追溯码客户端预览(TOTP式令牌保护,不激活不计数,可切换激活状态预览)
This commit is contained in:
@@ -11,9 +11,12 @@ import {
|
||||
Res,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Response } from 'express';
|
||||
import { RoleType } from '@artveris/shared';
|
||||
import { TraceCodeService } from './trace-code.service';
|
||||
import { SettingsService } from '../settings/settings.service';
|
||||
import { currentPreviewToken, PREVIEW_PERIOD_MS } from '../common/utils/preview-token.util';
|
||||
import {
|
||||
BatchDeleteDto,
|
||||
BatchGroupDto,
|
||||
@@ -34,7 +37,23 @@ import { parseBigId } from '../common/utils/bigint.util';
|
||||
@ApiBearerAuth()
|
||||
@Controller()
|
||||
export class TraceCodeController {
|
||||
constructor(private readonly service: TraceCodeService) {}
|
||||
constructor(
|
||||
private readonly service: TraceCodeService,
|
||||
private readonly settings: SettingsService,
|
||||
private readonly config: ConfigService,
|
||||
) {}
|
||||
|
||||
// 预览令牌:类 TOTP,随时间自动轮换(当前+上一窗口有效)。后台点开预览页时随取随用,
|
||||
// 预览地址外泄后最长 2 个周期即失效,无法长期传播。
|
||||
@Get('trace-codes/preview-token')
|
||||
@ApiOperation({ summary: '获取 C 端预览令牌(自动轮换)' })
|
||||
async previewToken() {
|
||||
return {
|
||||
token: currentPreviewToken(this.config.get<string>('jwt.secret') || ''),
|
||||
clientBase: await this.settings.getClientBaseUrl(),
|
||||
periodMs: PREVIEW_PERIOD_MS,
|
||||
};
|
||||
}
|
||||
|
||||
@Post('trace-codes/batch')
|
||||
@Roles(RoleType.OPERATOR)
|
||||
|
||||
Reference in New Issue
Block a user