Harden milestone sharing and X publishing

This commit is contained in:
2026-08-14 18:19:55 +02:00
parent d8f7202bf6
commit 4ec70ed30f
8 changed files with 191 additions and 63 deletions

View File

@@ -58,6 +58,22 @@ export type SocialMilestoneCard = {
} | null;
};
export function isCompleteSocialMilestoneCard(value: unknown): value is SocialMilestoneCard {
if (!value || typeof value !== 'object') return false;
const card = value as Partial<SocialMilestoneCard>;
const trend = card.trend;
return card.version === 'milestone-card-v2'
&& typeof card.qrTitle === 'string'
&& typeof card.totalScans === 'number'
&& Number.isFinite(card.totalScans)
&& typeof card.totalUniqueScans === 'number'
&& Number.isFinite(card.totalUniqueScans)
&& Boolean(trend)
&& Array.isArray(trend?.points)
&& trend.points.length >= 2
&& trend.points.every(point => typeof point?.at === 'string' && typeof point?.total === 'number');
}
export function socialLocale(value?: string | null): SocialLocale {
return value === 'de' ? 'de' : 'en';
}