Live video on the AT Protocol

app: throw error if custom thumbnail upload fails

authored by 10xcrazy.horse and committed by Natalie B e08ed036 337ebb24

+47 -45
+47 -45
js/app/features/bluesky/blueskySlice.tsx
··· 64 64 try { 65 65 const thumbnail = await pdsAgent.uploadBlob(customThumbnail); 66 66 if (thumbnail.success) { 67 - console.log("Successfully uploaded custom thumbnail"); 67 + console.log("Successfully uploaded thumbnail"); 68 68 return thumbnail.data.blob; 69 69 } 70 70 } catch (e) { 71 - console.error("Error uploading custom thumbnail:", e); 71 + throw new Error("Error uploading thumbnail: " + e); 72 72 } 73 - } 74 - 75 - // Fallback to server-side thumbnail if client-side capture fails or we're not on web 76 - try { 77 - const thumbnailRes = await fetch( 78 - `${u.protocol}//${u.host}/api/playback/${profile.handle}/stream.png`, 79 - ); 80 - if (!thumbnailRes.ok) { 81 - throw new Error( 82 - `failed to fetch thumbnail (http ${thumbnailRes.status})`, 83 - ); 84 - } 85 - const thumbnailBlob = await thumbnailRes.blob(); 86 - const thumbnail = await pdsAgent.uploadBlob(thumbnailBlob); 87 - if (!thumbnail.success) { 88 - throw new Error("failed to upload thumbnail"); 89 - } 90 - return thumbnail.data.blob; 91 - } catch (e) { 92 - console.error("Error fetching server-side thumbnail:", e); 93 - throw e; 94 73 } 95 74 }; 96 75 ··· 391 370 time: new Date().toISOString(), 392 371 }); 393 372 394 - let thumbnail: BlobRef | null = null; 395 - try { 396 - thumbnail = await uploadThumbnail( 397 - profile.handle, 398 - u, 399 - bluesky.pdsAgent, 400 - profile, 401 - customThumbnail, 402 - ); 403 - } catch (e) { 404 - console.error("uploadThumbnail error", e); 373 + let thumbnail: BlobRef | undefined = undefined; 374 + 375 + if (customThumbnail) { 376 + try { 377 + thumbnail = await uploadThumbnail( 378 + profile.handle, 379 + u, 380 + bluesky.pdsAgent, 381 + profile, 382 + customThumbnail, 383 + ); 384 + } catch (e) { 385 + throw new Error(`Custom thumbnail upload failed ${e}`); 386 + } 387 + } else { 388 + // No custom thumbnail: fetch the server-side image and upload it 389 + try { 390 + const thumbnailRes = await fetch( 391 + `${u.protocol}//${u.host}/api/playback/${profile.handle}/stream.png`, 392 + ); 393 + if (!thumbnailRes.ok) { 394 + throw new Error( 395 + `Failed to fetch thumbnail: ${thumbnailRes.status})`, 396 + ); 397 + } 398 + const thumbnailBlob = await thumbnailRes.blob(); 399 + thumbnail = await uploadThumbnail( 400 + profile.handle, 401 + u, 402 + bluesky.pdsAgent, 403 + profile, 404 + thumbnailBlob, 405 + ); 406 + } catch (e) { 407 + throw new Error(`Thumbnail upload failed ${e}`); 408 + } 405 409 } 406 410 407 411 const linkUrl = `${u.protocol}//${u.host}/${profile.handle}?${params.toString()}`; ··· 433 437 facets, 434 438 createdAt: now.toISOString(), 435 439 }; 436 - if (thumbnail) { 437 - record.embed = { 438 - $type: "app.bsky.embed.external", 439 - external: { 440 - description: text, 441 - thumb: thumbnail, 442 - title: `@${profile.handle} is 🔴LIVE on ${u.host}!`, 443 - uri: linkUrl, 444 - }, 445 - }; 446 - } 440 + record.embed = { 441 + $type: "app.bsky.embed.external", 442 + external: { 443 + description: text, 444 + thumb: thumbnail, 445 + title: `@${profile.handle} is 🔴LIVE on ${u.host}!`, 446 + uri: linkUrl, 447 + }, 448 + }; 447 449 console.log("golivePost record", record); 448 450 return await bluesky.pdsAgent.post(record); 449 451 },