Something went wrong. Try again.
Atproto AMA app
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112/** * Source integration logic for handling questions and answers from different platforms */
import blueskyLogo from "../../assets/Bluesky_Logo.webp";import standardSiteLogo from "../../assets/standard-site.svg";import { SOURCE_TYPES, type SourceType } from "./shared-schemas";
export type SourceTypeIcon = | { kind: "emoji"; value: string } | { kind: "image"; src: string; alt: string };
/** * Get source type display information */export function getSourceTypeInfo(sourceType: SourceType): { name: string; icon: SourceTypeIcon; color: string; url?: string;} { switch (sourceType) { case SOURCE_TYPES.BLUESKY: return { name: "Bluesky", icon: { kind: "image", src: blueskyLogo, alt: "Bluesky" }, color: "#0085ff", url: "https://bsky.app", }; case SOURCE_TYPES.STANDARD_SITE: return { name: "Standard.site", icon: { kind: "image", src: standardSiteLogo, alt: "Original article" }, color: "#6366f1", url: "https://standard.site", }; case SOURCE_TYPES.MASTODON: return { name: "Mastodon", icon: { kind: "emoji", value: "🐘" }, color: "#6364ff", }; case SOURCE_TYPES.NOSTR: return { name: "Nostr", icon: { kind: "emoji", value: "⚡" }, color: "#f59e0b", }; case SOURCE_TYPES.ASKIMUT: default: return { name: "Askimut", icon: { kind: "emoji", value: "❓" }, color: "#10b981", }; }}
/** * Format source attribution text */export function formatSourceAttribution(sourceType: SourceType, sourceUri?: string): string { if (sourceType === SOURCE_TYPES.ASKIMUT) { return ""; }
if (sourceType === SOURCE_TYPES.STANDARD_SITE) { return "original article"; }
const info = getSourceTypeInfo(sourceType);
if (sourceUri) { return `see on ${info.name.toLowerCase()}`; }
return `Via ${info.name}`;}
/** * Get the original post URL if available */export function getOriginalPostUrl( sourceType: SourceType, sourceUri?: string, _sourceData?: string,): string | null { if (!sourceUri) return null;
switch (sourceType) { case SOURCE_TYPES.BLUESKY: // Convert AT-URI to web URL if (sourceUri.startsWith("at://")) { const parts = sourceUri.replace("at://", "").split("/"); if (parts.length >= 3) { const [did, _collection, rkey] = parts; return `https://bsky.app/profile/${did}/post/${rkey}`; } } return sourceUri;
case SOURCE_TYPES.STANDARD_SITE: if (sourceUri.startsWith("https://")) { return sourceUri; } return null;
default: return sourceUri; }}