a tool for shared writing and social publishing
0
fork

Configure Feed

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

use cover image in publishing initial bsky post

+31 -10
+31 -10
app/[leaflet_id]/publish/publishBskyPost.ts
··· 16 16 getMicroLinkOgImage, 17 17 getWebpageImage, 18 18 } from "src/utils/getMicroLinkOgImage"; 19 + import { fetchAtprotoBlob } from "app/api/atproto_images/route"; 19 20 20 21 export async function publishPostToBsky(args: { 21 22 text: string; ··· 34 35 let agent = new AtpBaseClient( 35 36 credentialSession.fetchHandler.bind(credentialSession), 36 37 ); 37 - let newPostUrl = args.url; 38 - let preview_image = await getWebpageImage(newPostUrl, { 39 - width: 1400, 40 - height: 733, 41 - noCache: true, 42 - }); 38 + 39 + // Get image binary - prefer cover image, fall back to screenshot 40 + let imageBinary: Blob | null = null; 41 + 42 + if (args.document_record.coverImage) { 43 + let cid = 44 + (args.document_record.coverImage.ref as unknown as { $link: string })[ 45 + "$link" 46 + ] || args.document_record.coverImage.ref.toString(); 47 + 48 + let coverImageResponse = await fetchAtprotoBlob(identity.atp_did, cid); 49 + if (coverImageResponse) { 50 + imageBinary = await coverImageResponse.blob(); 51 + } 52 + } 53 + 54 + // Fall back to screenshot if no cover image or fetch failed 55 + if (!imageBinary) { 56 + let preview_image = await getWebpageImage(args.url, { 57 + width: 1400, 58 + height: 733, 59 + noCache: true, 60 + }); 61 + imageBinary = await preview_image.blob(); 62 + } 43 63 44 - let binary = await preview_image.blob(); 45 - let resized_preview_image = await sharp(await binary.arrayBuffer()) 64 + // Resize and upload 65 + let resizedImage = await sharp(await imageBinary.arrayBuffer()) 46 66 .resize({ 47 67 width: 1200, 68 + height: 630, 48 69 fit: "cover", 49 70 }) 50 71 .webp({ quality: 85 }) 51 72 .toBuffer(); 52 73 53 - let blob = await agent.com.atproto.repo.uploadBlob(resized_preview_image, { 54 - headers: { "Content-Type": binary.type }, 74 + let blob = await agent.com.atproto.repo.uploadBlob(resizedImage, { 75 + headers: { "Content-Type": "image/webp" }, 55 76 }); 56 77 let bsky = new BskyAgent(credentialSession); 57 78 let post = await bsky.app.bsky.feed.post.create(