this repo has no description
7
fork

Configure Feed

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

just about done

+39 -24
+39 -24
Index.html
··· 39 39 <script> 40 40 41 41 const constellationEndpoint = 'https://constellation.microcosm.blue'; 42 + const likesCollection = 'app.bsky.feed.like'; 43 + const repostsCollection = 'app.bsky.feed.repost'; 42 44 43 45 async function callConstellationEndpoint(target, collection, path, cursor = null) { 44 46 try { ··· 61 63 } 62 64 } 63 65 64 - function isValidHttpUrl(string) { 65 - let url; 66 - try { 67 - url = new URL(string); 68 - } catch (_) { 69 - return false; 70 - } 71 - return url.protocol === "http:" || url.protocol === "https:"; 72 - } 73 - 74 66 document.addEventListener('alpine:init', () => { 75 67 Alpine.data('giveaway', () => ({ 76 68 //Form input ··· 83 75 error: '', 84 76 loading: false, 85 77 winners: [], 78 + participants: 0, 86 79 showResults: false, 87 80 88 81 validateCheckBoxes(event) { ··· 141 134 // Determine which collections to fetch based on user selection 142 135 const collections = []; 143 136 if (this.likes_only || this.likes_and_reposts) { 144 - collections.push('app.bsky.feed.like'); 137 + collections.push(likesCollection); 145 138 } 146 139 if (this.reposts_only || this.likes_and_reposts) { 147 - collections.push('app.bsky.feed.repost'); 140 + collections.push(repostsCollection); 148 141 } 149 142 150 143 // Path to extract the subject URI ··· 152 145 153 146 // Fetch data for each collection 154 147 const results = []; 155 - let cursor = null; 156 148 for (const collection of collections) { 157 149 console.log(`Fetching ${collection} data...`); 158 - const response = await callConstellationEndpoint(atUri, collection, path); 159 - console.log(`${collection} response:`, response); 160 - if (response && response.linking_dids) { 161 - cursor = response.cursor; 162 - results.push(...response.linking_dids); 163 - } 150 + let cursor = null; 151 + let pageCount = 1; 152 + 153 + do { 154 + console.log(`Fetching ${collection} data, page ${pageCount}${cursor ? ' with cursor' : ''}...`); 155 + const response = await callConstellationEndpoint(atUri, collection, path, cursor); 156 + console.log(`${collection} response (page ${pageCount}):`, response); 157 + 158 + if (response && response.linking_dids) { 159 + let dids = response.linking_dids.map(x => ({ 160 + collection: collection, 161 + did: x 162 + })) 163 + results.push(...dids); 164 + cursor = response.cursor; 165 + pageCount++; 166 + } else { 167 + cursor = null; 168 + } 169 + } while (cursor); 170 + 171 + console.log(`Completed fetching ${collection} data, total pages: ${pageCount - 1}`); 164 172 } 165 173 166 - // Remove duplicates if fetching both likes and reposts 167 - const uniqueDids = [...new Set(results)]; 168 - console.log('Unique DIDs:', uniqueDids); 174 + 175 + let uniqueDids = []; 176 + if (this.likes_only || this.reposts_only) { 177 + uniqueDids = results.map(x => x.did); 178 + } 179 + if (this.likes_and_reposts) { 180 + const likesDids = results.filter(x => x.collection === likesCollection).map(x => x.did); 181 + const repostsDids = results.filter(x => x.collection === repostsCollection).map(x => x.did); 182 + uniqueDids = likesDids.filter(did => repostsDids.includes(did)); 183 + } 169 184 185 + this.participants = uniqueDids.length; 170 186 // Select winners 171 187 if (uniqueDids.length === 0) { 172 188 this.error = 'No participants found for this post'; ··· 183 199 uniqueDids.splice(randomIndex, 1); 184 200 } 185 201 186 - console.log('Winners:', this.winners); 187 202 this.showResults = true; 188 203 189 204 } catch (error) { ··· 265 280 <!-- Results Section --> 266 281 <div x-show="showResults" class="mt-6 p-4 bg-base-200 rounded-lg"> 267 282 <h3 class="text-xl font-bold mb-2">🎉 Winners 🎉</h3> 268 - <p class="mb-2">Total participants: <span x-text="winners.length"></span></p> 283 + <p class="mb-2">Total participants: <span x-text="participants"></span></p> 269 284 <ul class="list-disc pl-5"> 270 285 <template x-for="winner in winners"> 271 286 <li class="mb-1">