A modified version of Wafrn used on https://wf.jbc.lol (mirror of https://git.jbc.lol/jbcrn/wf.jbc.lol which is a mirror of https://codeberg.org/jbcarreon123/wf.jbc.lol)
1
fork

Configure Feed

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

add embed links to atproto sending

+35 -2
+35 -2
packages/backend/atproto/utils/postToAtproto.ts
··· 11 11 import ffmpeg from 'fluent-ffmpeg' 12 12 import { completeEnvironment } from '../../utils/backendOptions.js' 13 13 import { getPostAndUserFromPostId } from '../../utils/cacheGetters/getPostAndUserFromPostId.js' 14 + import { getLinkPreview } from 'link-preview-js' 15 + import crypto from 'crypto' 16 + import { redisCache } from '../../utils/redis.js' 14 17 15 18 export async function getVideoAspectRatio(fileName: string) { 16 19 return new Promise((resolve, reject) => { ··· 151 154 const textOnlyShortenerLength = 15 152 155 153 156 const tokens = tokenize(postText) 157 + 158 + let res: any; 159 + 154 160 for (const token of tokens) { 155 161 let text = builder.text 156 162 if (token.type === 'link') text += token.text ··· 177 183 break 178 184 } 179 185 180 - if (token.type === 'link') builder.addLink(token.text, token.url) 186 + if (token.type === 'link') { 187 + builder.addLink(token.text, token.url) 188 + if (!res.embed) { 189 + const shasum = crypto.createHash('sha1') 190 + shasum.update(token.url.toLowerCase()) 191 + const urlHash = shasum.digest('hex') 192 + let linkPreview: { url: string; title: string; description: string } | undefined = JSON.parse(await redisCache.get('linkPreviewCache:' + urlHash) ?? '{}') 193 + if (!linkPreview?.title) { 194 + linkPreview = await getLinkPreview(token.url, { 195 + followRedirects: 'follow', 196 + headers: { 'User-Agent': completeEnvironment.instanceUrl } 197 + }) as { url: string; title: string; description: string } | undefined; 198 + await redisCache.set('linkPreviewCache:' + urlHash, JSON.stringify(linkPreview), 'EX', linkPreview ? 3600 * 24 : 300) 199 + } 200 + 201 + if (linkPreview?.title) { 202 + res.embed = { 203 + $type: 'app.bsky.embed.external', 204 + external: { 205 + uri: linkPreview.url, 206 + title: linkPreview.title, 207 + description: linkPreview.description 208 + } 209 + } 210 + } 211 + } 212 + } 181 213 else builder.addText(token.raw) 182 214 } 183 215 postText = builder.text ··· 214 246 } 215 247 216 248 const fullText = processedContent ?? post.content; 217 - let res: any = { 249 + res = { 250 + ...res, 218 251 text: rt.text, 219 252 facets: rt.facets, 220 253 createdAt: new Date(post.createdAt).toISOString(),