feat: 完善安装部署与数字溯源码
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import { Controller, Get, Param, Req, Res } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Request, Response } from 'express';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
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 config: ConfigService,
|
||||
private readonly settings: SettingsService,
|
||||
) {}
|
||||
|
||||
@Public()
|
||||
@@ -26,10 +26,8 @@ export class PublicTraceController {
|
||||
// 短链跳转:扫码打开 /t/:shortCode -> 重定向到 C 端溯源页(不在 /api 前缀下)
|
||||
@Public()
|
||||
@Get('t/:shortCode')
|
||||
redirect(@Param('shortCode') shortCode: string, @Res() res: Response) {
|
||||
const template =
|
||||
this.config.get<string>('traceUrlTemplate') ||
|
||||
'http://localhost:5174/#/pages/trace/index?code={code}';
|
||||
res.redirect(302, template.replace('{code}', encodeURIComponent(shortCode)));
|
||||
async redirect(@Param('shortCode') shortCode: string, @Res() res: Response) {
|
||||
const clientBaseUrl = await this.settings.getClientBaseUrl();
|
||||
res.redirect(302, `${clientBaseUrl}/#/trace/${encodeURIComponent(shortCode)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import type Redis from 'ioredis';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { ArtworkStatus, AuditStatus, QueryResult, ProofStatus, TraceCodeStatus } from '@artveris/shared';
|
||||
import { ArtworkStatus, AuditStatus, QueryResult, ProofStatus, TRACE_CODE_PATTERN, TraceCodeStatus } from '@artveris/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { StorageService } from '../storage/storage.service';
|
||||
import { REDIS_CLIENT } from '../redis/redis.module';
|
||||
@@ -92,6 +92,10 @@ export class PublicTraceService {
|
||||
}
|
||||
|
||||
async trace(shortCode: string, ctx: TraceContext) {
|
||||
if (!TRACE_CODE_PATTERN.test(shortCode)) {
|
||||
await this.writeLog(null, null, shortCode, QueryResult.INVALID, ctx);
|
||||
return { status: 'INVALID' as const };
|
||||
}
|
||||
const id = await this.resolveId(shortCode);
|
||||
if (id === null) {
|
||||
await this.writeLog(null, null, shortCode, QueryResult.INVALID, ctx);
|
||||
|
||||
Reference in New Issue
Block a user