fix: 统一追溯码并修正天河链存证跳转

This commit is contained in:
Nixevol
2026-07-13 07:06:43 +08:00
parent 61d813a096
commit 09b9887a30
21 changed files with 79 additions and 98 deletions
+1 -4
View File
@@ -11,7 +11,6 @@ const prisma = new PrismaClient();
const storageDir = resolve(process.env.STORAGE_LOCAL_DIR || './storage');
const ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const shortId = customAlphabet(ALPHABET, 10);
const codeId = customAlphabet(ALPHABET, 18);
// 公开短码须为 12 位纯数字(与 TRACE_CODE_PATTERN=/^\d{12}$/ 一致),否则 C 端公开溯源会判 INVALID
const numericId = customAlphabet('0123456789', 12);
function uniqueShortCode(used: Set<string>): string {
@@ -221,7 +220,6 @@ async function ensureSampleData(): Promise<void> {
const isActive = artworkActive && k < 2; // 该款前两套已激活
const code = await prisma.traceCode.create({
data: {
code: codeId(),
shortCode,
artworkId: artwork.id,
batchId: batch.id,
@@ -241,7 +239,6 @@ async function ensureSampleData(): Promise<void> {
traceCodeId: code.id,
artworkId: artwork.id,
shortCode,
code: code.code,
archiveNo: `ARTVERIS-${String(artwork.id).padStart(6, '0')}`,
batchNo: batch.batchNo,
queryCount: 3 + k,
@@ -256,7 +253,7 @@ async function ensureSampleData(): Promise<void> {
},
});
}
const dataHash = '0x' + createHash('sha256').update(JSON.stringify({ c: code.code })).digest('hex');
const dataHash = '0x' + createHash('sha256').update(JSON.stringify({ shortCode })).digest('hex');
const txHash = '0x' + randomBytes(32).toString('hex');
await prisma.blockchainProof.create({
data: {