feat: 客户页面改为站内查看存证和证书
This commit is contained in:
@@ -26,15 +26,20 @@ describe('Consumer certificate lifecycle', () => {
|
||||
afterEach(() => jest.restoreAllMocks());
|
||||
it('GET only reads persisted state and never starts a job or calls Tianhe', async () => {
|
||||
const { service, prisma, config } = fixture('NONE');
|
||||
expect(await service.status('123456000001')).toMatchObject({ status: 'NONE', url: null });
|
||||
expect(await service.status('123456000001')).toMatchObject({ status: 'NONE', certificate: null });
|
||||
expect(prisma.blockchainProof.updateMany).not.toHaveBeenCalled();
|
||||
expect(prisma.$transaction).not.toHaveBeenCalled();
|
||||
expect(config.getAllRaw).not.toHaveBeenCalled();
|
||||
});
|
||||
it('returns an existing shared certificate without consulting credentials or submitting', async () => {
|
||||
const { service, row, config } = fixture('READY');
|
||||
row.certificateUrl = 'https://test.tichain.tianhecloud.com/#/certificate?address=' + settings.tianheWalletAddress + '&txHash=0x' + 'a'.repeat(64) + '&digest=' + 'b'.repeat(64);
|
||||
expect(await service.request('123456000001')).toMatchObject({ status: 'READY', url: row.certificateUrl });
|
||||
row.certificateUrl = 'https://test.tichain.tianhecloud.com/#/certificate?address=' + settings.tianheWalletAddress + '&txHash=0x' + 'a'.repeat(64) + '&digest=' + 'b'.repeat(64) + '&createTime=1789844077000';
|
||||
const result = await service.request('123456000001');
|
||||
expect(result).toMatchObject({
|
||||
status: 'READY',
|
||||
certificate: { text: 'frozen-evidence', digest: 'b'.repeat(64), txHash: '0x' + 'a'.repeat(64), author: settings.tianheWalletAddress, createdAt: '2026-09-19T18:54:37.000Z' },
|
||||
});
|
||||
expect(JSON.stringify(result)).not.toContain('tianhecloud');
|
||||
expect(config.getAllRaw).not.toHaveBeenCalled();
|
||||
});
|
||||
it('does not send when another worker owns the lease', async () => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { DEFAULT_CERTIFICATE_TEXT_TEMPLATE, ErrorCode, renderCertificateText, TR
|
||||
import { BusinessException } from '../common/exceptions/business.exception';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { SettingsService } from '../settings/settings.service';
|
||||
import { certificateAuthorUrl, DepositEnvironment, DepositProvider, DepositRejected, safeCertificateUrl } from './deposit.provider';
|
||||
import { DepositEnvironment, DepositProvider, DepositRejected, presentStoredCertificate } from './deposit.provider';
|
||||
|
||||
interface CertificateRequest {
|
||||
version: 1;
|
||||
@@ -43,12 +43,13 @@ export class DepositCertificateService {
|
||||
|
||||
private async view(proof: BlockchainProof, artist?: string | null) {
|
||||
const request = proof.certificateRequest as unknown as CertificateRequest | null;
|
||||
const url = request && proof.certificateState === 'READY'
|
||||
? safeCertificateUrl(proof.certificateUrl, request.environment, request.address) : null;
|
||||
const certificate = request && proof.certificateState === 'READY'
|
||||
? presentStoredCertificate(proof.certificateUrl, request.environment, request.address, request.text, await this.settings.get('certificateAuthorMode'), artist)
|
||||
: null;
|
||||
return {
|
||||
status: proof.certificateState === 'READY' && !url ? 'FAILED' : proof.certificateState,
|
||||
url: url ? certificateAuthorUrl(url, await this.settings.get('certificateAuthorMode'), artist) : null,
|
||||
status: proof.certificateState === 'READY' && !certificate ? 'FAILED' : proof.certificateState,
|
||||
generatedAt: proof.certificateGeneratedAt,
|
||||
certificate,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { certificateAuthorUrl, depositSignature, DepositProvider, DepositRejected, safeCertificateUrl } from './deposit.provider';
|
||||
import { certificateAuthorUrl, depositSignature, DepositProvider, DepositRejected, presentStoredCertificate, safeCertificateUrl } from './deposit.provider';
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
describe('V3 deposit protocol', () => {
|
||||
@@ -28,6 +28,16 @@ describe('V3 deposit protocol', () => {
|
||||
}
|
||||
expect(safeCertificateUrl('https://test.tichain.tianhecloud.com/' + suffix, 'test', 'wrong')).toBeNull();
|
||||
});
|
||||
it('presents stored certificate fields without the Tianhe page address', () => {
|
||||
const address = '0x' + 'a'.repeat(40);
|
||||
const txHash = '0x' + 'c'.repeat(64);
|
||||
const digest = 'd'.repeat(64);
|
||||
const stored = `https://tichain.tianhecloud.com/#/certificate?address=${address}&txHash=${txHash}&digest=${digest}&createTime=1789867663000`;
|
||||
const view = presentStoredCertificate(stored, 'production', address, '十二生肖莲花手工杯', 'ARTWORK_ARTIST', '黄志伟');
|
||||
expect(view).toEqual({ text: '十二生肖莲花手工杯', digest, txHash, author: '黄志伟', createdAt: '2026-09-20T01:27:43.000Z' });
|
||||
expect(JSON.stringify(view)).not.toContain('tianhecloud');
|
||||
expect(presentStoredCertificate(stored, 'production', address, '十二生肖莲花手工杯', 'WALLET', '黄志伟')?.author).toBe(address);
|
||||
});
|
||||
it('uses signed headers, does not expose keys in URL/body and rejects ambiguous acceptance', async () => {
|
||||
const fetcher = jest.spyOn(global, 'fetch').mockResolvedValue({ ok: true, json: async () => ({ code: 200, success: true, data: 'different-id' }) } as any);
|
||||
await expect(new DepositProvider('test', 'app', 'secret').submit('address', 'op', '证据'))
|
||||
|
||||
@@ -14,6 +14,26 @@ export function depositSignature(path: string, query: Record<string, unknown>, b
|
||||
return createHash('sha256').update(json + timestamp + key, 'utf8').digest('hex');
|
||||
}
|
||||
|
||||
export interface StoredCertificateView {
|
||||
text: string;
|
||||
digest: string;
|
||||
txHash: string;
|
||||
author: string;
|
||||
createdAt: string | null;
|
||||
}
|
||||
|
||||
/** 公开页面只接收存证字段。天河链证书网址留在服务端,不进入浏览器。 */
|
||||
export function presentStoredCertificate(value: unknown, environment: DepositEnvironment, address: string, text: string, mode: string | null, artist?: string | null): StoredCertificateView | null {
|
||||
if (!safeCertificateUrl(value, environment, address) || !text.trim()) return null;
|
||||
const params = new URLSearchParams(new URL(String(value)).hash.slice('#/certificate?'.length));
|
||||
const digest = params.get('digest') || '';
|
||||
const txHash = params.get('txHash') || '';
|
||||
const rawTime = params.get('createTime');
|
||||
const created = rawTime && /^\d+$/.test(rawTime) ? new Date(Number(rawTime)) : null;
|
||||
const author = mode === 'ARTWORK_ARTIST' && artist?.trim() ? artist.trim() : address;
|
||||
return { text, digest, txHash, author, createdAt: created && !Number.isNaN(created.getTime()) ? created.toISOString() : null };
|
||||
}
|
||||
|
||||
export function safeCertificateUrl(value: unknown, environment: DepositEnvironment, address?: string): string | null {
|
||||
if (typeof value !== 'string') return null;
|
||||
try {
|
||||
|
||||
@@ -96,8 +96,7 @@ function createHarness(options: {
|
||||
set: jest.fn().mockResolvedValue('OK'),
|
||||
};
|
||||
const storage = { getUrl: jest.fn((key: string) => `/uploads/${key}`) };
|
||||
const settings = { getAllRaw: jest.fn().mockResolvedValue({}) };
|
||||
const service = new PublicTraceService(prisma as any, storage as any, settings as any, redis as any);
|
||||
const service = new PublicTraceService(prisma as any, storage as any, redis as any);
|
||||
return { service, prisma };
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,8 @@ import {
|
||||
} from '@artveris/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { StorageService } from '../storage/storage.service';
|
||||
import { SettingsService } from '../settings/settings.service';
|
||||
import { REDIS_CLIENT } from '../redis/redis.module';
|
||||
import { parseUserAgent } from '../common/utils/ua.util';
|
||||
import { buildTianheExplorerTxUrl } from '../blockchain/tianhe.provider';
|
||||
|
||||
type TraceCodeWithRel = Prisma.TraceCodeGetPayload<{ include: { batch: true; artwork: true } }>;
|
||||
type ArtworkWithRel = Prisma.ArtworkGetPayload<{
|
||||
@@ -45,7 +43,6 @@ export class PublicTraceService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly storage: StorageService,
|
||||
private readonly settings: SettingsService,
|
||||
@Inject(REDIS_CLIENT) private readonly redis: Redis,
|
||||
) {}
|
||||
|
||||
@@ -271,8 +268,6 @@ export class PublicTraceService {
|
||||
|
||||
const result = firstActivate ? QueryResult.FIRST_ACTIVATE : QueryResult.REPEAT;
|
||||
await this.writeLog(id, artwork.id, shortCode, result, ctx, { ...code, ...updated });
|
||||
const explorerUrl = await this.resolveExplorerUrl(proof);
|
||||
|
||||
return {
|
||||
status: 'OK' as const,
|
||||
queriedAt: now,
|
||||
@@ -281,7 +276,7 @@ export class PublicTraceService {
|
||||
queryCount: updated.queryCount,
|
||||
firstActivatedAt: updated.firstActivatedAt,
|
||||
},
|
||||
...this.buildArtworkPayload(artwork, code, proof, explorerUrl),
|
||||
...this.buildArtworkPayload(artwork, code, proof),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -329,7 +324,6 @@ export class PublicTraceService {
|
||||
|
||||
const now = new Date();
|
||||
const firstQuery = state === 'inactive';
|
||||
const explorerUrl = await this.resolveExplorerUrl(proof);
|
||||
return {
|
||||
status: 'OK' as const,
|
||||
preview: true,
|
||||
@@ -341,7 +335,7 @@ export class PublicTraceService {
|
||||
queryCount: code.queryCount > 0 ? code.queryCount : 2,
|
||||
firstActivatedAt: code.firstActivatedAt ?? now,
|
||||
},
|
||||
...this.buildArtworkPayload(artwork, code, proof, explorerUrl),
|
||||
...this.buildArtworkPayload(artwork, code, proof),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -362,13 +356,11 @@ export class PublicTraceService {
|
||||
blockHeight: bigint | null;
|
||||
chainName: string | null;
|
||||
onchainAt: Date | null;
|
||||
explorerUrl: string | null;
|
||||
contractAddress: string | null;
|
||||
status: string;
|
||||
failureReason: string | null;
|
||||
submittedAt: Date | null;
|
||||
} | null,
|
||||
explorerUrl: string | null,
|
||||
) {
|
||||
return {
|
||||
artwork: {
|
||||
@@ -414,7 +406,6 @@ export class PublicTraceService {
|
||||
blockHeight: proof.blockHeight,
|
||||
chainName: proof.chainName,
|
||||
onchainAt: proof.onchainAt,
|
||||
explorerUrl,
|
||||
contractAddress: proof.contractAddress,
|
||||
submittedAt: proof.submittedAt,
|
||||
failureReason: this.publicFailureReason(proof.status, proof.failureReason),
|
||||
@@ -471,18 +462,6 @@ export class PublicTraceService {
|
||||
};
|
||||
}
|
||||
|
||||
private async resolveExplorerUrl(
|
||||
proof: { txHash: string | null; chainName: string | null; explorerUrl: string | null } | null,
|
||||
): Promise<string | null> {
|
||||
const tianheProof =
|
||||
proof?.chainName === '天河链' ||
|
||||
/tianhe|tichain/i.test(proof?.chainName || '') ||
|
||||
/tianhecloud\.com/i.test(proof?.explorerUrl || '');
|
||||
if (!proof?.txHash || !tianheProof) return proof?.explorerUrl ?? null;
|
||||
const settings = await this.settings.getAllRaw();
|
||||
return buildTianheExplorerTxUrl(settings.tianheBaseUrl || '', proof.txHash, settings.tianheEnv);
|
||||
}
|
||||
|
||||
private buildFields(
|
||||
fields: Array<{ fieldKey: string; label: string; type: string }>,
|
||||
dynamic: unknown,
|
||||
|
||||
@@ -44,10 +44,17 @@ export function fetchAppInfo(): Promise<any> {
|
||||
return instance.get('/settings/public') as unknown as Promise<any>;
|
||||
}
|
||||
|
||||
export interface TraceCertificateRecord {
|
||||
text: string;
|
||||
digest: string;
|
||||
txHash: string;
|
||||
author: string;
|
||||
createdAt: string | null;
|
||||
}
|
||||
export interface TraceCertificateResult {
|
||||
status: 'NONE' | 'PENDING' | 'SUBMITTING' | 'CHECKING' | 'WAITING' | 'READY' | 'UNKNOWN' | 'FAILED';
|
||||
url: string | null;
|
||||
generatedAt: string | null;
|
||||
certificate: TraceCertificateRecord | null;
|
||||
}
|
||||
export function requestTraceCertificate(shortCode: string): Promise<TraceCertificateResult> {
|
||||
return instance.post(`/public/trace/${encodeURIComponent(shortCode)}/certificate`, {}) as unknown as Promise<TraceCertificateResult>;
|
||||
|
||||
@@ -58,15 +58,7 @@
|
||||
<span class="chain-v">{{ formatTime(blockchain.onchainAt) }}</span>
|
||||
</div>
|
||||
<div class="chain-actions">
|
||||
<a
|
||||
v-if="explorerUrl"
|
||||
class="chain-link"
|
||||
:href="explorerUrl"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{{ t('chain.explorer') }}
|
||||
</a>
|
||||
<button v-if="blockchain.txHash" class="chain-link" @click="openProof">{{ t('chain.explorer') }}</button>
|
||||
<button ref="certificateButton" v-if="canViewCertificate" class="chain-link certificate-link" :disabled="opening || preview" @click="viewCertificate">
|
||||
{{ t('chain.certificateView') }}
|
||||
</button>
|
||||
@@ -76,29 +68,54 @@
|
||||
<div v-else class="chain-empty muted">{{ t('chain.notOnchain') }}</div>
|
||||
</section>
|
||||
<Teleport to="body">
|
||||
<dialog ref="proofDialog" class="certificate-dialog" aria-labelledby="proof-dialog-title" @cancel.prevent="closeProof">
|
||||
<button class="certificate-close" :aria-label="t('viewer.close')" @click="closeProof">×</button>
|
||||
<h3 id="proof-dialog-title">{{ t('chain.proofTitle') }}</h3>
|
||||
<div class="sheet-body">
|
||||
<div v-for="row in proofRows" :key="row.label" class="sheet-row">
|
||||
<span>{{ row.label }}</span>
|
||||
<strong>{{ row.value }}</strong>
|
||||
<button v-if="row.copy" class="icon-copy" :aria-label="t('chain.copy')" @click="$emit('copy', row.copy)">
|
||||
<svg viewBox="0 0 24 24" width="15" height="15" aria-hidden="true">
|
||||
<rect x="9" y="9" width="11" height="11" rx="2" fill="none" stroke="currentColor" stroke-width="1.7" />
|
||||
<path d="M5 15V5a2 2 0 0 1 2-2h8" fill="none" stroke="currentColor" stroke-width="1.7" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
<dialog ref="certificateDialog" class="certificate-dialog" aria-labelledby="certificate-dialog-title" @cancel.prevent="closeCertificateDialog">
|
||||
<button class="certificate-close" :aria-label="t('viewer.close')" @click="closeCertificateDialog">×</button>
|
||||
<h3 id="certificate-dialog-title">{{ t('chain.certificateView') }}</h3>
|
||||
<div v-if="!certificateError" class="certificate-spinner" aria-hidden="true" />
|
||||
<div aria-live="polite">
|
||||
<div v-if="!certificateError && !certificateRecord" class="certificate-spinner" aria-hidden="true" />
|
||||
<div class="sheet-body" aria-live="polite">
|
||||
<p v-if="certificateError" role="alert">{{ certificateError }}</p>
|
||||
<div v-else-if="certificateRecord" class="certificate-sheet">
|
||||
<div v-for="row in certificateRows" :key="row.label" class="sheet-row">
|
||||
<span>{{ row.label }}</span>
|
||||
<strong>{{ row.value }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<ol v-else class="certificate-steps">
|
||||
<li v-for="(key, index) in certificateSteps" :key="key" :class="{ current: certificatePhase === index, done: certificatePhase > index }">
|
||||
<span aria-hidden="true">{{ certificatePhase > index ? '✓' : index + 1 }}</span>{{ t(key) }}
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
<button v-if="certificateError && retryable" class="certificate-retry" @click="viewCertificate">{{ t('chain.certificateCheckAgain') }}</button>
|
||||
<div v-if="certificateRecord || (certificateError && retryable)" class="dialog-actions">
|
||||
<button v-if="certificateRecord" class="certificate-retry" type="button" @click="downloadCertificate">{{ t('chain.certificateDownload') }}</button>
|
||||
<button v-else class="certificate-retry" type="button" @click="viewCertificate">{{ t('chain.certificateCheckAgain') }}</button>
|
||||
</div>
|
||||
</dialog>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onUnmounted, ref, watch } from 'vue';
|
||||
import { fetchTraceCertificate, requestTraceCertificate, type TraceCertificateResult } from '@/api';
|
||||
import { fetchTraceCertificate, requestTraceCertificate, type TraceCertificateRecord, type TraceCertificateResult } from '@/api';
|
||||
import { downloadCertificatePng } from '@/utils/certificateImage';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import dayjs from 'dayjs';
|
||||
import { safeTraceUrl } from './media';
|
||||
|
||||
type ProofStatus = 'PENDING' | 'SUBMITTING' | 'CONFIRMING' | 'ONCHAIN' | 'FAILED' | 'UNKNOWN';
|
||||
const STATUSES = new Set<ProofStatus>([
|
||||
@@ -121,7 +138,7 @@ const props = defineProps<{
|
||||
contractAddress?: string | null;
|
||||
blockHeight?: string | number | null;
|
||||
onchainAt?: string | null;
|
||||
explorerUrl?: string | null;
|
||||
blockHash?: string | null;
|
||||
failureReason?: string | null;
|
||||
chainName?: string | null;
|
||||
} | null;
|
||||
@@ -131,11 +148,13 @@ const { t } = useI18n();
|
||||
const opening = ref(false);
|
||||
const certificateError = ref('');
|
||||
const canViewCertificate = computed(() => props.blockchain?.status === 'ONCHAIN' && Boolean(props.blockchain.txHash) && props.blockchain.chainName === '天河链');
|
||||
const proofDialog = ref<HTMLDialogElement>();
|
||||
const certificateDialog = ref<HTMLDialogElement>();
|
||||
const certificateButton = ref<HTMLButtonElement>();
|
||||
const certificatePhase = ref(0);
|
||||
const certificateRecord = ref<TraceCertificateRecord | null>(null);
|
||||
const retryable = ref(true);
|
||||
const certificateSteps = ['chain.certificateRetrieving', 'chain.certificateAcquiring', 'chain.certificateRedirecting'];
|
||||
const certificateSteps = ['chain.certificateRetrieving', 'chain.certificateAcquiring', 'chain.certificatePreparing'];
|
||||
let certificateTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
let certificateRun = 0;
|
||||
let certificatePolls = 0;
|
||||
@@ -147,9 +166,16 @@ function stopCertificateWait() {
|
||||
}
|
||||
function closeCertificateDialog() {
|
||||
stopCertificateWait();
|
||||
certificateRecord.value = null;
|
||||
certificateDialog.value?.close();
|
||||
certificateButton.value?.focus();
|
||||
}
|
||||
function openProof() {
|
||||
proofDialog.value?.showModal();
|
||||
}
|
||||
function closeProof() {
|
||||
proofDialog.value?.close();
|
||||
}
|
||||
function failCertificate(messageKey: string, canRetry = true) {
|
||||
certificateError.value = t(messageKey);
|
||||
retryable.value = canRetry;
|
||||
@@ -157,11 +183,10 @@ function failCertificate(messageKey: string, canRetry = true) {
|
||||
}
|
||||
function showCertificateResult(result: TraceCertificateResult, run: number, code: string) {
|
||||
if (run !== certificateRun) return;
|
||||
if (result.status === 'READY' && result.url) {
|
||||
if (result.status === 'READY' && result.certificate) {
|
||||
certificatePhase.value = 2;
|
||||
certificateTimer = setTimeout(() => {
|
||||
if (run === certificateRun) window.location.assign(result.url!);
|
||||
}, 350);
|
||||
certificateRecord.value = result.certificate;
|
||||
opening.value = false;
|
||||
return;
|
||||
}
|
||||
if (result.status === 'FAILED') return failCertificate('chain.certificateFailed', false);
|
||||
@@ -203,15 +228,47 @@ const status = computed<ProofStatus>(() => {
|
||||
const value = props.blockchain?.status as ProofStatus | undefined;
|
||||
return value && STATUSES.has(value) ? value : 'ONCHAIN';
|
||||
});
|
||||
const explorerUrl = computed(() => safeTraceUrl(props.blockchain?.explorerUrl || undefined));
|
||||
const proofRows = computed(() => {
|
||||
const chain = props.blockchain;
|
||||
if (!chain) return [];
|
||||
return [
|
||||
{ label: t('chain.hash'), value: chain.txHash || '-', copy: chain.txHash || '' },
|
||||
{ label: t('chain.contract'), value: chain.contractAddress || '-', copy: chain.contractAddress || '' },
|
||||
{ label: t('chain.blockHeight'), value: chain.blockHeight == null ? '-' : String(chain.blockHeight), copy: '' },
|
||||
{ label: t('chain.blockHash'), value: chain.blockHash || '-', copy: chain.blockHash || '' },
|
||||
{ label: t('chain.onchainAt'), value: chain.onchainAt ? formatTime(chain.onchainAt) : '-', copy: '' },
|
||||
];
|
||||
});
|
||||
const certificateRows = computed(() => {
|
||||
const record = certificateRecord.value;
|
||||
if (!record) return [];
|
||||
return [
|
||||
{ label: t('chain.certificateContent'), value: record.text },
|
||||
{ label: t('chain.certificateDigest'), value: record.digest },
|
||||
{ label: t('chain.hash'), value: record.txHash },
|
||||
{ label: t('chain.certificateAuthor'), value: record.author },
|
||||
{ label: t('chain.certificateTime'), value: formatTime(record.createdAt) },
|
||||
];
|
||||
});
|
||||
function downloadCertificate() {
|
||||
const record = certificateRecord.value;
|
||||
if (!record) return;
|
||||
downloadCertificatePng({
|
||||
title: t('chain.certificateView'),
|
||||
filename: `certificate-${props.shortCode}.png`,
|
||||
rows: certificateRows.value,
|
||||
});
|
||||
}
|
||||
|
||||
function ellipsis(value?: string | null) {
|
||||
if (!value) return '-';
|
||||
return value.length > 16 ? `${value.slice(0, 8)}…${value.slice(-6)}` : value;
|
||||
}
|
||||
|
||||
function formatTime(value: string) {
|
||||
return dayjs(value).format('YYYY-MM-DD HH:mm');
|
||||
function formatTime(value?: string | null) {
|
||||
if (!value) return '-';
|
||||
const parsed = dayjs(value);
|
||||
return parsed.isValid() ? parsed.format('YYYY-MM-DD HH:mm') : '-';
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -301,9 +358,14 @@ function formatTime(value: string) {
|
||||
.chain-link {
|
||||
display: inline-block;
|
||||
margin-top: 10px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
color: var(--brand-2);
|
||||
font: inherit;
|
||||
font-size: 14px;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
.chain-empty {
|
||||
font-size: 13px;
|
||||
@@ -312,7 +374,13 @@ function formatTime(value: string) {
|
||||
.chain-actions { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
|
||||
.certificate-link { margin-left: auto; padding: 0; border: 0; background: none; cursor: pointer; font-family: inherit; }
|
||||
.certificate-link:disabled { opacity: .55; cursor: default; }
|
||||
.certificate-dialog { width: min(360px, calc(100vw - 40px)); box-sizing: border-box; padding: 28px; border: 1px solid var(--border); border-radius: 16px; background: var(--card-bg); color: var(--text); box-shadow: 0 16px 60px #0003; }
|
||||
.certificate-dialog { width: min(420px, calc(100vw - 40px)); max-height: min(640px, calc(100vh - 48px)); box-sizing: border-box; padding: 28px; border: 1px solid var(--border); border-radius: 16px; background: var(--card-bg); color: var(--text); box-shadow: 0 16px 60px #0003; }
|
||||
.certificate-dialog[open] { display: flex; flex-direction: column; }
|
||||
.sheet-body { overflow: auto; min-height: 0; }
|
||||
.sheet-row { display: grid; grid-template-columns: 72px minmax(0, 1fr) auto; gap: 8px; align-items: start; padding: 8px 0; border-bottom: 1px dashed var(--trace-divider); font-size: 13px; }
|
||||
.sheet-row span { color: var(--muted); }
|
||||
.sheet-row strong { font-weight: 500; word-break: break-all; white-space: pre-wrap; }
|
||||
.dialog-actions { padding-top: 16px; }
|
||||
.certificate-dialog::backdrop { background: #0007; }
|
||||
.certificate-dialog h3 { margin: 0 0 22px; font-size: 18px; }
|
||||
.certificate-close { position: absolute; top: 9px; right: 12px; border: 0; background: transparent; color: var(--muted); font-size: 25px; cursor: pointer; }
|
||||
|
||||
@@ -27,5 +27,12 @@ export function openTraceViewer(items: PublicMediaItem[], index: number): void {
|
||||
|
||||
export function safeTraceUrl(value?: string): string {
|
||||
const url = traceMediaUrl(value);
|
||||
return /^(https?:\/\/|\/)/i.test(url) ? url : '';
|
||||
if (!/^(https?:\/\/|\/)/i.test(url)) return '';
|
||||
if (url.startsWith('/')) return url;
|
||||
try {
|
||||
if (/(^|\.)tianhecloud\.com$/i.test(new URL(url).hostname)) return '';
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@
|
||||
"contract": "Contract",
|
||||
"blockHeight": "Block Height",
|
||||
"onchainAt": "On-chain Time",
|
||||
"blockHash": "Block Hash",
|
||||
"proofTitle": "Attestation",
|
||||
"explorer": "View Proof",
|
||||
"copy": "Copy",
|
||||
"copied": "Copied",
|
||||
@@ -71,8 +73,13 @@
|
||||
"certificateUnavailable": "Unable to check the certificate. Please try again later.",
|
||||
"certificateRetrieving": "Retrieving attestation details",
|
||||
"certificateAcquiring": "Preparing your certificate",
|
||||
"certificateRedirecting": "Opening your certificate",
|
||||
"certificateDelayed": "Your certificate is not ready yet. Please try again later."
|
||||
"certificatePreparing": "Assembling your certificate",
|
||||
"certificateDelayed": "Your certificate is not ready yet. Please try again later.",
|
||||
"certificateContent": "Attestation text",
|
||||
"certificateDigest": "Digest",
|
||||
"certificateAuthor": "Author",
|
||||
"certificateTime": "Created",
|
||||
"certificateDownload": "Download certificate"
|
||||
},
|
||||
"field": {
|
||||
"viewFile": "View file"
|
||||
|
||||
@@ -59,6 +59,8 @@
|
||||
"contract": "合约地址",
|
||||
"blockHeight": "区块高度",
|
||||
"onchainAt": "上链时间",
|
||||
"blockHash": "区块哈希",
|
||||
"proofTitle": "存证详情",
|
||||
"explorer": "查看存证",
|
||||
"copy": "复制",
|
||||
"copied": "已复制",
|
||||
@@ -71,8 +73,13 @@
|
||||
"certificateUnavailable": "暂时无法查询证书,请稍后重试。",
|
||||
"certificateRetrieving": "正在调取存证数据",
|
||||
"certificateAcquiring": "获取存证证书",
|
||||
"certificateRedirecting": "正在打开存证证书",
|
||||
"certificateDelayed": "证书暂未就绪,请稍后再试。"
|
||||
"certificatePreparing": "正在整理存证证书",
|
||||
"certificateDelayed": "证书暂未就绪,请稍后再试。",
|
||||
"certificateContent": "存证内容",
|
||||
"certificateDigest": "摘要",
|
||||
"certificateAuthor": "作者",
|
||||
"certificateTime": "生成时间",
|
||||
"certificateDownload": "下载证书"
|
||||
},
|
||||
"field": {
|
||||
"viewFile": "查看文件"
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
export interface CertificateImageInput {
|
||||
title: string;
|
||||
rows: Array<{ label: string; value: string }>;
|
||||
filename: string;
|
||||
}
|
||||
|
||||
const FONT = '"Microsoft YaHei", "PingFang SC", sans-serif';
|
||||
|
||||
function wrap(ctx: CanvasRenderingContext2D, value: string, maxWidth: number): string[] {
|
||||
const lines: string[] = [];
|
||||
let line = '';
|
||||
for (const char of Array.from(value || '-')) {
|
||||
const next = line + char;
|
||||
if (line && ctx.measureText(next).width > maxWidth) {
|
||||
lines.push(line);
|
||||
line = char;
|
||||
} else {
|
||||
line = next;
|
||||
}
|
||||
}
|
||||
lines.push(line || '-');
|
||||
return lines;
|
||||
}
|
||||
|
||||
export function downloadCertificatePng(input: CertificateImageInput): void {
|
||||
const width = 750;
|
||||
const pad = 48;
|
||||
const maxWidth = width - pad * 2;
|
||||
const measure = document.createElement('canvas').getContext('2d');
|
||||
if (!measure) return;
|
||||
const lines: Array<{ text: string; font: string; gap: number; color: string }> = [];
|
||||
measure.font = `bold 28px ${FONT}`;
|
||||
for (const text of wrap(measure, input.title, maxWidth)) {
|
||||
lines.push({ text, font: measure.font, gap: 36, color: '#143028' });
|
||||
}
|
||||
for (const row of input.rows) {
|
||||
measure.font = `bold 14px ${FONT}`;
|
||||
lines.push({ text: row.label, font: measure.font, gap: 22, color: '#5c6b66' });
|
||||
measure.font = `16px ${FONT}`;
|
||||
const wrapped = wrap(measure, row.value, maxWidth);
|
||||
wrapped.forEach((text, index) => {
|
||||
lines.push({ text, font: measure.font, gap: index === wrapped.length - 1 ? 28 : 22, color: '#1c1c1c' });
|
||||
});
|
||||
}
|
||||
const height = pad * 2 + lines.reduce((sum, line) => sum + line.gap, 0);
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = width * 2;
|
||||
canvas.height = height * 2;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
ctx.scale(2, 2);
|
||||
ctx.fillStyle = '#f7f3ea';
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
ctx.strokeStyle = '#0f766e';
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeRect(18, 18, width - 36, height - 36);
|
||||
let y = pad + 8;
|
||||
for (const line of lines) {
|
||||
ctx.font = line.font;
|
||||
ctx.fillStyle = line.color;
|
||||
ctx.fillText(line.text, pad, y);
|
||||
y += line.gap;
|
||||
}
|
||||
canvas.toBlob((blob) => {
|
||||
if (!blob) return;
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = input.filename;
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}, 'image/png');
|
||||
}
|
||||
+1
-1
@@ -213,7 +213,7 @@ flowchart LR
|
||||
## 九、C 端与查验
|
||||
|
||||
- C 端溯源页区块链卡展示:链名、交易哈希、合约地址、区块高度、上链时间;tokenId 仍由后端保存,当前不对消费者展示;
|
||||
- 「查看存证」按当前天河环境动态跳转 DApp 浏览器**交易详情页**(`transDetail?hash=<mintTxHash>`):测试环境使用 `test.explorer.tianhecloud.com`,正式环境使用 `explorer.tianhecloud.com`;链接不沿用数据库中的历史接口 URL;
|
||||
- 「查看存证」打开站内存证详情,展示已保存的交易哈希、合约地址、区块高度、区块哈希和上链时间。公开溯源接口不返回天河链区块浏览器地址。
|
||||
- 数据哈希为平台内部计算并保留的结构化内容摘要,不随当前 publish 请求上链,也不是链上交易标识或消费者追溯码,不在 C 端展示。
|
||||
|
||||
## 十、生产上线检查单
|
||||
|
||||
+4
-4
@@ -8,15 +8,15 @@
|
||||
|
||||
扫码页区块链模块底部左侧为“查看存证”、右侧靠右为“查看证书”,均不显示箭头。仅明确 ONCHAIN 且有交易哈希的天河链实物显示证书按钮,未上链或处理中均不显示。仅已激活、正常、已审核通过的实物可申请。普通页面打开、刷新与证书状态 GET 都不会提交存证;后台预览模式按钮禁用,不产生付费副作用。
|
||||
|
||||
点击后在当前页面弹出进度窗口,文案依次为“正在调取存证数据”“获取存证证书”“正在打开存证证书”。先读取已保存链接,没有时才 POST 申请并轮询状态;完成后当前页面跳转到官方证书网页,避免新窗口被拦截。弹窗可关闭,关闭只停止当前页面等待,后台已提交任务继续完成。再次点击直接读取数据库已有链接,不重复生成。官方网页提供证书展示及下载,不保存图片到本平台。旧的独立等待页已移除。
|
||||
点击后在当前页面弹出进度窗口,文案依次为“正在调取存证数据”“获取存证证书”“正在整理存证证书”。先读取已保存的证书字段,没有时才 POST 申请并轮询状态;完成后在弹窗内展示存证内容、摘要、交易哈希、作者和生成时间,并可下载本平台生成的证书图片。弹窗可关闭,关闭只停止当前页面等待,后台已提交任务继续完成。再次点击直接读取数据库已有记录,不重复生成。公开接口不返回天河链网址,客户页面也不再跳转到天河链。旧的独立等待页已移除。
|
||||
|
||||
新证书首次点击时按系统设置 `certificateTextTemplate` 渲染并冻结正文,默认 `{{作品名称}} {{版本}}`,例如“十二生肖莲花手工杯 一个装”。设置入口为“系统设置 → 区块链 → 证书文本模板”,帮助按钮点击后才弹出字段说明。支持 `{{作品名称}}`、`{{版本}}`、`{{追溯码}}`、`{{档案编号}}`、`{{作者}}`,可自由排序、重复使用并插入普通文本或换行。版本按作品模板中显示名为“版本”的字段取值,当前数据键为 `size`,不能硬编码成 `version`。
|
||||
|
||||
模板最多500字符,拒绝未知占位符、错误花括号及表达式;只做纯文本替换,不执行代码、不解析Markdown。缺失字段替换为空,最终文本不能为空或超过2000字符。模板缺省时自动使用默认值,无需迁移数据库。更改模板只影响之后的首次申请,已经排队、提交或完成的证据与链接保持不变,不重新生成。即使同款同版本渲染出相同文本,仍按每件实物分别保存operateId与状态。
|
||||
模板最多500字符,拒绝未知占位符、错误花括号及表达式;只做纯文本替换,不执行代码、不解析Markdown。缺失字段替换为空,最终文本不能为空或超过2000字符。模板缺省时自动使用默认值,无需迁移数据库。更改模板只影响之后的首次申请,已经排队、提交或完成的证据保持不变,不重新生成。即使同款同版本渲染出相同文本,仍按每件实物分别保存operateId与状态。
|
||||
|
||||
模板允许真实换行,链接编码为 `%0A`;官方网页样式可能把换行合并为空格,用户已接受该显示限制。证书证明的是本次提交的文本快照,作品后续编辑不自动重生成。证书 V3 哈希和生成时间独立于原 NFT 发行哈希/时间。
|
||||
模板允许真实换行。证书证明的是本次提交的文本快照,作品后续编辑不自动重生成。证书 V3 哈希和生成时间独立于原 NFT 发行哈希/时间。
|
||||
|
||||
“证书作者显示”使用单选项:默认 `WALLET`(存证钱包地址),可选 `ARTWORK_ARTIST`(作品作者名称)。官方网页已实测支持独立的 `author` 显示参数;平台保留原始证书链接和 `address`,在返回链接时仅按设置添加或移除 `author`。名称取该实物作品档案的艺术家字段,空值回退钱包地址。此显示设置在已有证书下次打开时也生效,不修改原证据、存证主体、哈希或生成时间,不重新调用天河链接口。它是显示名称,不表示将存证交易签名身份改成艺术家本人。说明集中在帮助按钮弹窗中。
|
||||
“证书作者显示”使用单选项:默认 `WALLET`(存证钱包地址),可选 `ARTWORK_ARTIST`(作品作者名称)。名称取该实物作品档案的艺术家字段,空值回退钱包地址。公开接口只返回作者显示名和存证字段,不返回天河链网址。此显示设置在已有证书下次打开时也生效,不修改原证据、存证主体、哈希或生成时间,不重新调用天河链接口。它是显示名称,不表示将存证交易签名身份改成艺术家本人。说明集中在帮助按钮弹窗中。
|
||||
|
||||
## 服务端状态与恢复
|
||||
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@
|
||||
| 计费口径 | 按**每次调用上链接口**计费(非按容量)。"是否每件都上链/只上重点件"是纯运营成本决策,与代码无关 |
|
||||
| 钱包粒度 | **单平台托管钱包**(公证者身份),UserID 固定 `artveris-platform`;每件实物的链上凭据(txHash/tokenId)互相独立,钱包地址不标识物品、不在 C 端展示 |
|
||||
| 已售出标记 | **不需要**在链上做交易账单/已售出标记(甲方原话"不需要") |
|
||||
| C 端查验入口 | 「查看存证」跳天河区块浏览器**交易详情页** `#/tiChain/transDetail?hash=<mintTxHash>`(不选藏品详情页,因不传媒体会显示"未获取到媒体内容") |
|
||||
| C 端查验入口 | 「查看存证」打开站内存证详情;「查看证书」在站内展示并下载。公开接口不返回天河链网址,客户页面不能跳转到天河链。 |
|
||||
|
||||
### 3.2 链上身份与密钥安全
|
||||
|
||||
|
||||
Reference in New Issue
Block a user