fde6503bdf
Memind CI / Test, build, and release guards (push) Has been cancelled
Enable optional SEO/GEO injection and discovery routes for confirmed public pages while keeping private pages noindex. Add premium page template skills, portal catalog API, template shop UI, and Baidu push gated by memind_adm config. Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import type { PageTemplateCatalogItem, PageTemplateFavoriteResult, PageTemplatePurchaseResult, RechargeOrder } from '../types';
|
|
import { API, ApiError, apiFetch } from './core';
|
|
|
|
export type TemplateCheckoutResult = {
|
|
ok: boolean;
|
|
order?: RechargeOrder & { skillName?: string; label?: string };
|
|
skillName?: string;
|
|
grantedSkills?: string[];
|
|
balanceCents?: number;
|
|
alreadyOwned?: boolean;
|
|
};
|
|
|
|
export async function getPageTemplateCatalog(): Promise<PageTemplateCatalogItem[]> {
|
|
const result = await apiFetch<{ data?: { items?: PageTemplateCatalogItem[] }; items?: PageTemplateCatalogItem[] }>(
|
|
'/mindspace/v1/template-catalog',
|
|
);
|
|
return result.data?.items ?? result.items ?? [];
|
|
}
|
|
|
|
export async function getMyPageTemplates(): Promise<PageTemplateCatalogItem[]> {
|
|
const result = await apiFetch<{ data?: { items?: PageTemplateCatalogItem[] }; items?: PageTemplateCatalogItem[] }>(
|
|
'/mindspace/v1/template-catalog/mine',
|
|
);
|
|
return result.data?.items ?? result.items ?? [];
|
|
}
|
|
|
|
export async function purchasePageTemplate(skillName: string): Promise<PageTemplatePurchaseResult> {
|
|
try {
|
|
const result = await apiFetch<{ data: PageTemplatePurchaseResult }>(
|
|
`/mindspace/v1/template-catalog/${encodeURIComponent(skillName)}/purchase`,
|
|
{ method: 'POST' },
|
|
);
|
|
return result.data;
|
|
} catch (error) {
|
|
if (error instanceof ApiError && error.status === 402) {
|
|
throw error;
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export async function createTemplateWechatCheckout(
|
|
skillName: string,
|
|
payScene: 'native' | 'h5' | 'jsapi',
|
|
): Promise<TemplateCheckoutResult> {
|
|
const result = await apiFetch<{ data: TemplateCheckoutResult }>(
|
|
`/mindspace/v1/template-catalog/${encodeURIComponent(skillName)}/checkout`,
|
|
{
|
|
method: 'POST',
|
|
body: JSON.stringify({ payScene }),
|
|
},
|
|
);
|
|
return result.data;
|
|
}
|
|
|
|
export async function togglePageTemplateFavorite(skillName: string): Promise<PageTemplateFavoriteResult> {
|
|
const result = await apiFetch<{ data: PageTemplateFavoriteResult }>(
|
|
`/mindspace/v1/template-catalog/${encodeURIComponent(skillName)}/favorite`,
|
|
{ method: 'POST' },
|
|
);
|
|
return result.data;
|
|
}
|
|
|
|
export function getTemplatePreviewUrl(skillName: string) {
|
|
return `${API}/mindspace/v1/template-catalog/${encodeURIComponent(skillName)}/preview`;
|
|
}
|
|
|
|
export function formatTemplatePrice(cents: number) {
|
|
if (cents <= 0) return '免费';
|
|
return `¥${(cents / 100).toFixed(cents % 100 === 0 ? 0 : 2)}`;
|
|
}
|
|
|
|
export { API, ApiError };
|