fix(wechat): repair share preview on disk for sanitized delivery artifacts
Memind CI / Test, build, and release guards (push) Failing after 6s
Memind CI / Test, build, and release guards (push) Failing after 6s
Production WeChat delivery strips localPath from artifacts, so share-preview auto-repair never wrote back to HTML. Resolve paths via publishDir + relativePath, repair at materialize and delivery prep, and pass h5Root from Portal so page.generate can patch missing meta before sending links. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import fs from 'node:fs';
|
||||
import { artifactFileExists } from './page-artifact.mjs';
|
||||
import { resolveArtifactLocalPath } from './page-artifact.mjs';
|
||||
import { hasPlatformBrandMarker } from '../../mindspace-page-tag.mjs';
|
||||
|
||||
export { hasPlatformBrandMarker };
|
||||
@@ -57,26 +58,30 @@ export function verifySharePreviewMeta(html) {
|
||||
return { ok: true, reason: null };
|
||||
}
|
||||
|
||||
export function verifyArtifactSharePreview(artifact) {
|
||||
if (!artifactFileExists(artifact)) {
|
||||
return { ok: false, reason: 'missing_file' };
|
||||
}
|
||||
if (!String(artifact?.localPath ?? '').trim()) {
|
||||
if (
|
||||
typeof artifact?.sharePreview?.ok ===
|
||||
'boolean'
|
||||
) {
|
||||
return artifact.sharePreview;
|
||||
export function verifyArtifactSharePreview(artifact, { publishDir = '' } = {}) {
|
||||
const localPath = resolveArtifactLocalPath(artifact, publishDir);
|
||||
if (localPath) {
|
||||
try {
|
||||
if (fs.existsSync(localPath) && fs.statSync(localPath).isFile()) {
|
||||
const content = fs.readFileSync(localPath, 'utf8');
|
||||
return verifySharePreviewMeta(content);
|
||||
}
|
||||
} catch {
|
||||
// Fall back to cached sharePreview metadata below.
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
reason: 'missing_share_preview_evaluation',
|
||||
};
|
||||
}
|
||||
const content = fs.readFileSync(artifact.localPath, 'utf8');
|
||||
return verifySharePreviewMeta(content);
|
||||
if (
|
||||
typeof artifact?.sharePreview?.ok ===
|
||||
'boolean'
|
||||
) {
|
||||
return artifact.sharePreview;
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
reason: 'missing_file',
|
||||
};
|
||||
}
|
||||
|
||||
export function filterSharePreviewReadyArtifacts(artifacts = []) {
|
||||
return artifacts.filter((artifact) => verifyArtifactSharePreview(artifact).ok);
|
||||
export function filterSharePreviewReadyArtifacts(artifacts = [], options = {}) {
|
||||
return artifacts.filter((artifact) => verifyArtifactSharePreview(artifact, options).ok);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user