mindspace: close authority boundaries
This commit is contained in:
+10
-15
@@ -1,4 +1,3 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { normalizeWorkspaceRelativePath } from './mindspace-pages.mjs';
|
||||
|
||||
@@ -251,13 +250,11 @@ export async function ensurePlazaPostForPublication({
|
||||
|
||||
export async function quickPlazaFromChat({
|
||||
user,
|
||||
h5Root,
|
||||
bundle,
|
||||
body,
|
||||
mindSpacePages,
|
||||
mindSpacePublications,
|
||||
plazaPosts,
|
||||
publishDir,
|
||||
}) {
|
||||
if (!mindSpacePages || !mindSpacePublications || !plazaPosts) {
|
||||
throw Object.assign(new Error('Plaza 或 MindSpace 未启用'), { code: 'plaza_unavailable' });
|
||||
@@ -374,7 +371,7 @@ export async function quickPlazaFromPublicHtml({
|
||||
mindSpacePages,
|
||||
mindSpacePublications,
|
||||
plazaPosts,
|
||||
publishDir,
|
||||
readWorkspaceHtml,
|
||||
}) {
|
||||
if (!mindSpacePages || !mindSpacePublications || !plazaPosts) {
|
||||
throw Object.assign(new Error('Plaza 或 MindSpace 未启用'), { code: 'plaza_unavailable' });
|
||||
@@ -388,18 +385,16 @@ export async function quickPlazaFromPublicHtml({
|
||||
mindSpacePages,
|
||||
});
|
||||
|
||||
const resolvedRoot = path.resolve(publishDir);
|
||||
const filePath = path.resolve(publishDir, normalized);
|
||||
if (filePath !== resolvedRoot && !filePath.startsWith(`${resolvedRoot}${path.sep}`)) {
|
||||
throw Object.assign(new Error('路径越界'), { code: 'invalid_public_html_path' });
|
||||
}
|
||||
|
||||
let content;
|
||||
try {
|
||||
content = await fs.readFile(filePath, 'utf8');
|
||||
} catch {
|
||||
throw Object.assign(new Error('页面文件不存在'), { code: 'static_page_not_found' });
|
||||
if (typeof readWorkspaceHtml !== 'function') {
|
||||
throw Object.assign(
|
||||
new Error('MindSpace 页面读取服务不可用'),
|
||||
{ code: 'mindspace_read_unavailable' },
|
||||
);
|
||||
}
|
||||
const { html: content } = await readWorkspaceHtml({
|
||||
userId: user.id,
|
||||
relativePath: normalized,
|
||||
});
|
||||
|
||||
const page = await ensureWorkspaceHtmlPageForPlaza({
|
||||
userId: user.id,
|
||||
|
||||
Reference in New Issue
Block a user