ea6c49f046
支持全部页面分页/多选/删除/分享,删除时可选移除广场帖并清理工作区附件;修复并发同步重复创建页面,并补齐预览下载链接重写与 iframe 下载权限。 Co-authored-by: Cursor <cursoragent@cursor.com>
61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
export function resolvePublicPageUrl(publicUrl: string): string {
|
|
const value = String(publicUrl ?? '').trim();
|
|
if (!value) return value;
|
|
if (/^https?:\/\//i.test(value)) return value;
|
|
if (value.startsWith('//')) return `${window.location.protocol}${value}`;
|
|
if (value.startsWith('/')) return `${window.location.origin}${value}`;
|
|
return `${window.location.origin}/${value.replace(/^\/+/, '')}`;
|
|
}
|
|
|
|
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)}`;
|
|
}
|
|
|
|
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`;
|
|
}
|
|
|
|
export function resolveMindSpaceHomeUrl(): string {
|
|
const configured = String(import.meta.env.VITE_MINDSPACE_BASE ?? '').trim();
|
|
if (configured) {
|
|
return `${configured.replace(/\/$/, '')}/space`;
|
|
}
|
|
return `${window.location.origin}/space`;
|
|
}
|
|
|
|
/** 已发布页面的独立访问链接(非空间内编辑路由)。未发布时返回 null。 */
|
|
export function resolveMindSpacePagePublicViewUrl(page: {
|
|
publicationUrl?: string | null;
|
|
}): string | null {
|
|
const value = String(page.publicationUrl ?? '').trim();
|
|
if (!value) return null;
|
|
return resolvePublicPageUrl(value);
|
|
}
|
|
|
|
/** @deprecated 使用 resolveMindSpacePagePublicViewUrl */
|
|
export const resolveMindSpacePageViewUrl = resolveMindSpacePagePublicViewUrl;
|
|
|
|
/** 未发布时供本人查看的预览链接(需登录,不可对外分享)。 */
|
|
export function resolveMindSpacePageOwnerPreviewUrl(page: {
|
|
id: string;
|
|
versionNo?: number;
|
|
updatedAt?: number;
|
|
}): string {
|
|
const version = page.versionNo ?? page.updatedAt ?? Date.now();
|
|
return `${window.location.origin}/api/mindspace/v1/pages/${encodeURIComponent(page.id)}/preview?v=${version}`;
|
|
}
|