fix: MindSpace remote sync, thumbnail fallback, and Plaza URL guards

Ensure page sync runs via pageSyncService in remote mode, fall back to
workspace HTML when storage assets are missing, and prevent production
Portal from linking to loopback Plaza URLs baked in at build time.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-07-05 07:57:04 +08:00
parent 4781bbc156
commit d3239ff292
20 changed files with 646 additions and 58 deletions
+43
View File
@@ -0,0 +1,43 @@
export const DEFAULT_PLAZA_PUBLIC_BASE = 'https://plaza.tkmind.cn';
export const DEFAULT_LOCAL_PLAZA_PUBLIC_BASE = 'http://127.0.0.1:3001';
export function isLocalSiteHost(hostname) {
const host = String(hostname ?? '').trim().toLowerCase();
return !host || host === 'localhost' || host === '127.0.0.1' || host.endsWith('.localhost');
}
export function isLoopbackPublicBase(base) {
const value = String(base ?? '').trim();
if (!value) return false;
return (
/^https?:\/\/127\.0\.0\.1(?::\d+)?(?:\/|$)/i.test(value) ||
/^https?:\/\/localhost(?::\d+)?(?:\/|$)/i.test(value)
);
}
export function resolvePlazaPublicBase({
configuredBase = '',
dev = false,
hostname = '',
} = {}) {
const configured = String(configuredBase ?? '').trim().replace(/\/$/, '');
const localHost = isLocalSiteHost(hostname);
if (configured) {
if (!localHost && !dev && isLoopbackPublicBase(configured)) {
return DEFAULT_PLAZA_PUBLIC_BASE;
}
return configured;
}
if (dev || localHost) {
return DEFAULT_LOCAL_PLAZA_PUBLIC_BASE;
}
return DEFAULT_PLAZA_PUBLIC_BASE;
}
export function resolvePlazaHomePath(base) {
return `${String(base ?? '').replace(/\/$/, '')}/plaza`;
}
export function resolvePlazaPostPath(base, postId) {
return `${String(base ?? '').replace(/\/$/, '')}/plaza/p/${encodeURIComponent(postId)}`;
}
+16 -16
View File
@@ -1,3 +1,9 @@
import {
resolvePlazaHomePath,
resolvePlazaPostPath,
resolvePlazaPublicBase,
} from './public-site-bases.mjs';
export function resolvePublicPageUrl(publicUrl: string): string {
const value = String(publicUrl ?? '').trim();
if (!value) return value;
@@ -7,26 +13,20 @@ export function resolvePublicPageUrl(publicUrl: string): string {
return `${window.location.origin}/${value.replace(/^\/+/, '')}`;
}
function resolvedPlazaBase(): string {
return resolvePlazaPublicBase({
configuredBase: import.meta.env.VITE_PLAZA_BASE,
dev: import.meta.env.DEV,
hostname: typeof window !== 'undefined' ? window.location.hostname : '',
});
}
export function resolvePlazaPostUrl(postId: string): string {
const configured = String(import.meta.env.VITE_PLAZA_BASE ?? '').trim();
if (configured) {
return `${configured.replace(/\/$/, '')}/plaza/p/${encodeURIComponent(postId)}`;
}
if (import.meta.env.DEV) {
return `http://127.0.0.1:3001/plaza/p/${encodeURIComponent(postId)}`;
}
return `${window.location.origin}/plaza/p/${encodeURIComponent(postId)}`;
return resolvePlazaPostPath(resolvedPlazaBase(), postId);
}
export function resolvePlazaHomeUrl(): string {
const configured = String(import.meta.env.VITE_PLAZA_BASE ?? '').trim();
if (configured) {
return `${configured.replace(/\/$/, '')}/plaza`;
}
if (import.meta.env.DEV) {
return 'http://127.0.0.1:3001/plaza';
}
return `${window.location.origin}/plaza`;
return resolvePlazaHomePath(resolvedPlazaBase());
}
export function resolveMindSpaceHomeUrl(): string {