// @ts-expect-error virtual file generated by bsky-comments module import { newestPostUrl, newestPostDate } from 'bsky-runtime-discovery-server.mjs' import { BLUESKY_API, postLinksToUrl, type BlueskyFeedResponse } from '#shared/utils/bluesky' export default defineEventHandler(async () => { if (!newestPostUrl) { return { uri: null } } const bskyHandle = useRuntimeConfig().social.networks.bluesky.identifier const searchCutoff = newestPostDate ? new Date(new Date(newestPostDate).getTime() - 24 * 60 * 60 * 1000) : null let cursor: string | undefined // Iterate through feed until we find a match or reach the day before the post do { const response = await $fetch('/xrpc/app.bsky.feed.getAuthorFeed', { baseURL: BLUESKY_API, query: { actor: bskyHandle, limit: 100, cursor, }, }) for (const item of response.feed) { if (item.reason) continue // Check if we've gone past the search cutoff if (searchCutoff) { const postDate = new Date(item.post.record.createdAt) if (postDate < searchCutoff) { return { uri: null } } } if (postLinksToUrl(item.post, newestPostUrl)) { return { uri: item.post.uri } } } cursor = response.cursor } while (cursor) return { uri: null } })