fix: recover WeChat page thumbnail delivery
Memind CI / Test, build, and release guards (pull_request) Successful in 5m1s
Memind CI / Test, build, and release guards (pull_request) Successful in 5m1s
This commit is contained in:
@@ -13,6 +13,29 @@ function htmlSrcForWorkspaceAsset(workspaceRelativePath) {
|
||||
return normalized.slice('public/'.length) || null;
|
||||
}
|
||||
|
||||
const IMAGE_MAKE_IDEMPOTENCY_KEY_MAX_LENGTH = 128;
|
||||
const WECHAT_PAGE_THUMBNAIL_KEY_PATTERN = /^wechat-[a-zA-Z0-9._-]+-page-\d+-thumbnail$/;
|
||||
|
||||
function boundedIdempotencyKey(base, suffix = '') {
|
||||
const normalizedBase = String(base ?? '').trim();
|
||||
const normalizedSuffix = String(suffix ?? '');
|
||||
return `${normalizedBase.slice(0, Math.max(0, IMAGE_MAKE_IDEMPOTENCY_KEY_MAX_LENGTH - normalizedSuffix.length))}${normalizedSuffix}`;
|
||||
}
|
||||
|
||||
function resolveImageMakeIdempotencyKey({ idempotencyKey, purpose, prompt, negativePrompt }) {
|
||||
const normalized = String(idempotencyKey ?? '').trim();
|
||||
if (!normalized) return `imgreq_${crypto.randomUUID()}`;
|
||||
if (purpose !== 'hero' || !WECHAT_PAGE_THUMBNAIL_KEY_PATTERN.test(normalized)) {
|
||||
return normalized;
|
||||
}
|
||||
const promptHash = crypto
|
||||
.createHash('sha256')
|
||||
.update([purpose, String(prompt ?? '').trim(), String(negativePrompt ?? '').trim()].join('\0'))
|
||||
.digest('hex')
|
||||
.slice(0, 12);
|
||||
return boundedIdempotencyKey(normalized, `-p-${promptHash}`);
|
||||
}
|
||||
|
||||
function resolvePurposeDimensions(spec, env, logger) {
|
||||
const widthKey = `IMAGE_MAKE_${spec.envPrefix}_WIDTH`;
|
||||
const heightKey = `IMAGE_MAKE_${spec.envPrefix}_HEIGHT`;
|
||||
@@ -65,7 +88,12 @@ export function createMindSpaceImageGenerationService({
|
||||
const maxAttempts = Number.isFinite(configuredAttempts)
|
||||
? Math.max(1, Math.min(3, Math.floor(configuredAttempts)))
|
||||
: 3;
|
||||
const baseIdempotencyKey = idempotencyKey || `imgreq_${crypto.randomUUID()}`;
|
||||
const baseIdempotencyKey = resolveImageMakeIdempotencyKey({
|
||||
idempotencyKey,
|
||||
purpose,
|
||||
prompt,
|
||||
negativePrompt,
|
||||
});
|
||||
let generated = null;
|
||||
let acceptedReview = null;
|
||||
let retryFeedback = '';
|
||||
@@ -76,7 +104,7 @@ export function createMindSpaceImageGenerationService({
|
||||
: prompt;
|
||||
const attemptKey = attempt === 1
|
||||
? baseIdempotencyKey
|
||||
: `${baseIdempotencyKey.slice(0, 160)}-review-${attempt}`;
|
||||
: boundedIdempotencyKey(baseIdempotencyKey, `-review-${attempt}`);
|
||||
generated = await imageMakeClient.generateImage({
|
||||
prompt: attemptPrompt,
|
||||
negativePrompt,
|
||||
|
||||
Reference in New Issue
Block a user