| 21 | } |
| 22 | |
| 23 | export function parseCcshareId(input: string): string | null { |
| 24 | const trimmed = input.trim() |
| 25 | if (!trimmed) { |
| 26 | return null |
| 27 | } |
| 28 | |
| 29 | const directMatch = trimmed.match(CCSHARE_ID_RE) |
| 30 | if (directMatch) { |
| 31 | return directMatch[0]! |
| 32 | } |
| 33 | |
| 34 | try { |
| 35 | const url = new URL(trimmed) |
| 36 | if ( |
| 37 | (url.hostname === 'go' || |
| 38 | url.hostname.startsWith('go.') || |
| 39 | url.hostname.endsWith('.anthropic.com') || |
| 40 | url.hostname === 'claude.ai' || |
| 41 | url.hostname.endsWith('.claude.ai')) && |
| 42 | url.pathname.startsWith('/ccshare/') |
| 43 | ) { |
| 44 | const candidate = decodeURIComponent( |
| 45 | url.pathname.slice('/ccshare/'.length).split('/')[0] ?? '', |
| 46 | ) |
| 47 | if (CCSHARE_ID_RE.test(candidate)) { |
| 48 | return candidate |
| 49 | } |
| 50 | } |
| 51 | } catch { |
| 52 | // Fall through to shortlink-without-scheme parsing. |
| 53 | } |
| 54 | |
| 55 | const shortlinkMatch = trimmed.match( |
| 56 | /^(?:go(?:\.[^/\s]+)?|claude\.ai)\/ccshare\/([^/?#]+)\/?(?:[?#].*)?$/i, |
| 57 | ) |
| 58 | if (shortlinkMatch?.[1] && CCSHARE_ID_RE.test(shortlinkMatch[1])) { |
| 59 | return shortlinkMatch[1] |
| 60 | } |
| 61 | |
| 62 | return null |
| 63 | } |
| 64 | |
| 65 | export async function loadCcshare(ccshareId: string): Promise<LogOption> { |
| 66 | if (!CCSHARE_ID_RE.test(ccshareId)) { |