首次激活改条件更新消除并发竞态;备份恢复补模型全集与版本校验防清库; 审核列表分页总数、操作日志未捕获 Promise、出库导入重复码、加密密钥可编辑、 溯源码盐以 env 为准、证书按 originKey reconcile、env 加载去重等修复; 新增 parseBigId 防非法入参 500、全局安全响应头、去除 SVG 上传、接入 throttler 限流、 入队失败补偿、hashData 稳定序列化、无效码负缓存、看板已激活口径调整; 移除冗余 TraceCode.outImage 列统一 outImages(迁移 drop_trace_code_out_image)。
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import { Controller, Get, Param, Req, Res } from '@nestjs/common';
|
|
import { Request, Response } from 'express';
|
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
import { Throttle } from '@nestjs/throttler';
|
|
import { Public } from '../common/decorators/public.decorator';
|
|
import { extractIp } from '../common/utils/ua.util';
|
|
import { PublicTraceService } from './public-trace.service';
|
|
import { SettingsService } from '../settings/settings.service';
|
|
|
|
@ApiTags('公开溯源')
|
|
@Controller()
|
|
export class PublicTraceController {
|
|
constructor(
|
|
private readonly service: PublicTraceService,
|
|
private readonly settings: SettingsService,
|
|
) {}
|
|
|
|
@Public()
|
|
@Get('public/trace/:shortCode')
|
|
// 公开溯源软限流:每 IP 每分钟 60 次,抑制脚本刷量污染防伪统计与日志
|
|
@Throttle({ default: { limit: 60, ttl: 60_000 } })
|
|
@ApiOperation({ summary: 'C 端溯源查询(匿名)' })
|
|
trace(@Param('shortCode') shortCode: string, @Req() req: Request) {
|
|
const ip = extractIp(req.headers as Record<string, unknown>, req.ip);
|
|
const userAgent = req.headers['user-agent'];
|
|
return this.service.trace(shortCode, { ip, userAgent });
|
|
}
|
|
|
|
// 短链跳转:扫码打开 /t/:shortCode -> 重定向到 C 端溯源页(不在 /api 前缀下)
|
|
@Public()
|
|
@Get('t/:shortCode')
|
|
async redirect(@Param('shortCode') shortCode: string, @Res() res: Response) {
|
|
const clientBaseUrl = await this.settings.getClientBaseUrl();
|
|
res.redirect(302, `${clientBaseUrl}/#/trace/${encodeURIComponent(shortCode)}`);
|
|
}
|
|
}
|