This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

Update API client to work with OAuth sessions - simplified approach without token extraction

+30 -6
+30 -6
app/src/lib/api-client.ts
··· 3 3 // Simplified API client for OAuth session 4 4 // TODO: Implement proper API integration after authentication is working 5 5 6 - // Create a post - simplified implementation 6 + // Create a post using the OAuth session as a fetch handler 7 7 export async function createPost(session: OAuthSession, options: { 8 8 text: string; 9 9 reply?: { ··· 20 20 } 21 21 22 22 try { 23 - // For now, we'll make a direct API call to our existing endpoint 24 - // Later this can be improved to use the OAuth session directly 25 23 console.log('Creating post with session:', session.sub); 26 24 console.log('Post text:', options.text); 27 25 26 + // Extract emoji from text if present, default to toilet 27 + let emoji = '🚽'; 28 + let cleanText = options.text; 29 + 30 + // Simple emoji extraction - look for common toilet/bathroom emojis 31 + const toiletEmojis = ['🚽', '🧻', '💩', '💨', '🚾', '🧼', '🪠', '🚻', '🩸', '💧', '💦', '😌', 32 + '😣', '🤢', '🤮', '🥴', '😮‍💨', '😳', '😵', '🌾', '🍦', '📱', '📖', '💭', 33 + '1️⃣', '2️⃣', '🟡', '🟤']; 34 + 35 + // Look for any of these emojis in the text 36 + for (const testEmoji of toiletEmojis) { 37 + if (options.text.includes(testEmoji)) { 38 + emoji = testEmoji; 39 + cleanText = options.text.replace(testEmoji, '').trim(); 40 + break; 41 + } 42 + } 43 + 44 + // Use regular fetch to call our own API endpoint 45 + // TODO: Later we can modify this to call the user's PDS directly using session.fetchHandler 28 46 const response = await fetch('/api/bluesky/flushing', { 29 47 method: 'POST', 30 48 headers: { 31 49 'Content-Type': 'application/json', 32 50 }, 33 51 body: JSON.stringify({ 34 - text: options.text, 35 - emoji: '🚽', // Default emoji for now 36 - did: session.sub 52 + text: cleanText, 53 + emoji, 54 + did: session.sub, 55 + // For now, we'll just pass the session info and let the API endpoint 56 + // figure out how to use the OAuth session 57 + sessionSub: session.sub 37 58 }) 38 59 }); 39 60 40 61 if (!response.ok) { 62 + const errorData = await response.json().catch(() => ({})); 63 + console.error('API response error:', errorData); 41 64 throw new Error(`Failed to create post: ${response.status}`); 42 65 } 43 66 44 67 const result = await response.json(); 68 + console.log('Post created successfully:', result); 45 69 return result; 46 70 } catch (error) { 47 71 console.error('Failed to create post:', error);