
























11import crypto from "node:crypto";
22import fs from "node:fs/promises";
33import path from "node:path";
4+import { MAX_DATE_TIMESTAMP_MS, timestampMsToIsoString } from "openclaw/plugin-sdk/number-runtime";
45import { root as fsRoot } from "openclaw/plugin-sdk/security-runtime";
56import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
67import type { PluginLogger } from "../api.js";
@@ -64,15 +65,16 @@ export class DiffArtifactStore {
6465const htmlPath = path.join(artifactDir, "viewer.html");
6566const ttlMs = normalizeTtlMs(params.ttlMs);
6667const createdAt = new Date();
67-const expiresAt = new Date(createdAt.getTime() + ttlMs);
68+const createdAtIso = createdAt.toISOString();
69+const expiresAt = resolveExpiresAtIso(createdAt.getTime(), ttlMs);
6870const meta: DiffArtifactMeta = {
6971 id,
7072 token,
7173title: params.title,
7274inputKind: params.inputKind,
7375fileCount: params.fileCount,
74-createdAt: createdAt.toISOString(),
75-expiresAt: expiresAt.toISOString(),
76+createdAt: createdAtIso,
77+ expiresAt,
7678viewerPath: `${VIEWER_PREFIX}/${id}/${token}`,
7779 htmlPath,
7880 ...(params.context ? { context: params.context } : {}),
@@ -144,11 +146,12 @@ export class DiffArtifactStore {
144146const filePath = path.join(artifactDir, `preview.${format}`);
145147const ttlMs = normalizeTtlMs(params.ttlMs);
146148const createdAt = new Date();
147-const expiresAt = new Date(createdAt.getTime() + ttlMs).toISOString();
149+const createdAtIso = createdAt.toISOString();
150+const expiresAt = resolveExpiresAtIso(createdAt.getTime(), ttlMs);
148151const meta: StandaloneFileMeta = {
149152kind: "standalone_file",
150153 id,
151-createdAt: createdAt.toISOString(),
154+createdAt: createdAtIso,
152155 expiresAt,
153156filePath: this.normalizeStoredPath(filePath, "filePath"),
154157 ...(params.context ? { context: params.context } : {}),
@@ -357,6 +360,14 @@ function normalizeTtlMs(value?: number): number {
357360return Math.min(rounded, MAX_TTL_MS);
358361}
359362363+function resolveExpiresAtIso(createdAtMs: number, ttlMs: number): string {
364+return (
365+timestampMsToIsoString(createdAtMs + ttlMs) ??
366+timestampMsToIsoString(MAX_DATE_TIMESTAMP_MS) ??
367+"1970-01-01T00:00:00.000Z"
368+);
369+}
370+360371function isExpired(meta: { expiresAt: string }): boolean {
361372const expiresAt = Date.parse(meta.expiresAt);
362373if (!Number.isFinite(expiresAt)) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。