Improve WeChat MP replies and ship MindSpace/H5 production updates.
Add WeChat service account routing with sync acks, connectivity tests, and context isolation; document deploy runbooks; and bundle related MindSpace, voice, Plaza, and server gateway changes for production rollout. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -164,6 +164,37 @@ export function createPublicationService(pool, options = {}) {
|
||||
return resolved;
|
||||
};
|
||||
|
||||
const resolveStoragePathCandidates = (storageKey) => {
|
||||
const normalized = String(storageKey ?? '').replace(/\\/g, '/');
|
||||
const withoutMd = normalized.endsWith('.md') ? normalized.slice(0, -3) : normalized;
|
||||
const match = withoutMd.match(/^users\/([^/]+)\/(assets|pages)\/([^/]+)\/(v\d+)$/);
|
||||
if (!match) return [normalized];
|
||||
const [, userId, scope, entityId, versionTag] = match;
|
||||
return [
|
||||
normalized,
|
||||
`users/${userId}/${scope}/${entityId}/versions/${versionTag}.md`,
|
||||
`users/${userId}/${scope}/${entityId}/versions/${versionTag}`,
|
||||
].filter((candidate, index, list) => list.indexOf(candidate) === index);
|
||||
};
|
||||
|
||||
const resolveReadableStoragePath = async (storageKey) => {
|
||||
let lastError = null;
|
||||
for (const candidate of resolveStoragePathCandidates(storageKey)) {
|
||||
const absolutePath = absoluteStoragePath(candidate);
|
||||
try {
|
||||
await fs.stat(absolutePath);
|
||||
return absolutePath;
|
||||
} catch (error) {
|
||||
if (error?.code === 'ENOENT') {
|
||||
lastError = error;
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
throw lastError ?? Object.assign(new Error('存储文件不存在'), { code: 'storage_not_found' });
|
||||
};
|
||||
|
||||
const loadVersion = async (userId, pageId, pageVersionId) => {
|
||||
const [rows] = await pool.query(
|
||||
`SELECT p.id AS page_id, p.title, p.summary, p.page_type, p.template_id, p.current_version_id,
|
||||
@@ -181,7 +212,7 @@ export function createPublicationService(pool, options = {}) {
|
||||
return {
|
||||
...row,
|
||||
version_no: Number(row.version_no),
|
||||
content: await fs.readFile(absoluteStoragePath(row.storage_key), 'utf8'),
|
||||
content: await fs.readFile(await resolveReadableStoragePath(row.storage_key), 'utf8'),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -610,7 +641,7 @@ export function createPublicationService(pool, options = {}) {
|
||||
],
|
||||
);
|
||||
return {
|
||||
html: await fs.readFile(absoluteStoragePath(row.storage_key), 'utf8'),
|
||||
html: await fs.readFile(await resolveReadableStoragePath(row.storage_key), 'utf8'),
|
||||
publication: publicationResponse({ ...row, view_count: Number(row.view_count) + 1 }),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user