| 32 | const store = new Map<string, StoredShare>(); |
| 33 | |
| 34 | export function createShare( |
| 35 | shareId: string, |
| 36 | params: { |
| 37 | conversation: Conversation; |
| 38 | visibility: ShareVisibility; |
| 39 | password?: string; |
| 40 | expiry: ShareExpiry; |
| 41 | } |
| 42 | ): StoredShare { |
| 43 | const expiryMs = EXPIRY_MS[params.expiry]; |
| 44 | const now = Date.now(); |
| 45 | |
| 46 | const entry: StoredShare = { |
| 47 | id: shareId, |
| 48 | conversationId: params.conversation.id, |
| 49 | conversation: params.conversation, |
| 50 | visibility: params.visibility, |
| 51 | passwordHash: params.password ?? undefined, |
| 52 | expiry: params.expiry, |
| 53 | expiresAt: expiryMs !== null ? now + expiryMs : undefined, |
| 54 | createdAt: now, |
| 55 | }; |
| 56 | |
| 57 | store.set(shareId, entry); |
| 58 | return entry; |
| 59 | } |
| 60 | |
| 61 | export function getShare(shareId: string): StoredShare | null { |
| 62 | const entry = store.get(shareId); |