fix: AppKey揭示改为显示完整明文并留审计;追溯码链接改为直连系统设置的客户端地址
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectQueue } from '@nestjs/bullmq';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Queue } from 'bullmq';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { Response } from 'express';
|
||||
@@ -35,34 +34,16 @@ export class TraceCodeService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly jobs: JobsService,
|
||||
private readonly config: ConfigService,
|
||||
private readonly storage: StorageService,
|
||||
private readonly settings: SettingsService,
|
||||
@InjectQueue(QUEUE_NAMES.GEN_CODE) private readonly genQueue: Queue,
|
||||
) {}
|
||||
|
||||
buildTraceUrl(shortCode: string): string {
|
||||
const clientBase = (this.config.get<string>('clientOrigin') || this.config.get<string>('baseUrl') || 'http://localhost:3000/trace').replace(/\/$/, '');
|
||||
return `${clientBase}/#/trace/${encodeURIComponent(shortCode)}`;
|
||||
}
|
||||
|
||||
buildShortLink(shortCode: string): string {
|
||||
const base = (this.config.get<string>('baseUrl') || 'http://localhost:3000').replace(/\/$/, '');
|
||||
return `${base}/t/${encodeURIComponent(shortCode)}`;
|
||||
}
|
||||
|
||||
// 短链 origin 以系统设置 clientBaseUrl 为准(换域名后所有链接自动跟随),失败回退 env baseUrl
|
||||
private async shortLinkOrigin(): Promise<string> {
|
||||
try {
|
||||
const clientBaseUrl = await this.settings.getClientBaseUrl();
|
||||
return new URL(clientBaseUrl).origin;
|
||||
} catch {
|
||||
return (this.config.get<string>('baseUrl') || 'http://localhost:3000').replace(/\/$/, '');
|
||||
}
|
||||
}
|
||||
|
||||
// 追溯码链接完全以系统设置「客户端地址」为准(含路径),列表/二维码/导出动态生成、换地址自动跟随。
|
||||
// 不再经 /t 短链中转(/t 跳转接口保留,兼容历史已打印二维码)。
|
||||
async buildDynamicShortLink(shortCode: string): Promise<string> {
|
||||
return `${await this.shortLinkOrigin()}/t/${encodeURIComponent(shortCode)}`;
|
||||
const clientBase = await this.settings.getClientBaseUrl();
|
||||
return `${clientBase}/#/trace/${encodeURIComponent(shortCode)}`;
|
||||
}
|
||||
|
||||
private mapOutImages(code: { outImages?: unknown }) {
|
||||
@@ -464,8 +445,8 @@ export class TraceCodeService {
|
||||
}),
|
||||
this.prisma.traceCode.count({ where }),
|
||||
]);
|
||||
// 短链统一动态生成(DB 不固化 url,换域名后列表/导出/二维码自动跟随);origin 每页只计算一次
|
||||
const origin = await this.shortLinkOrigin();
|
||||
// 链接统一动态生成(DB 不固化 url,换客户端地址后列表/导出/二维码自动跟随);base 每页只取一次
|
||||
const clientBase = await this.settings.getClientBaseUrl();
|
||||
return buildPage(
|
||||
list.map((code) => {
|
||||
const { proofs, ...rest } = code;
|
||||
@@ -473,7 +454,7 @@ export class TraceCodeService {
|
||||
const outImages = this.mapOutImages(code);
|
||||
return {
|
||||
...rest,
|
||||
url: `${origin}/t/${encodeURIComponent(code.shortCode)}`,
|
||||
url: `${clientBase}/#/trace/${encodeURIComponent(code.shortCode)}`,
|
||||
outImageUrl: outImages[0]?.url ?? null,
|
||||
outImages,
|
||||
latestProof: latestOnchainProof,
|
||||
|
||||
Reference in New Issue
Block a user