This commit is contained in:
2026-01-18 16:48:29 +09:00
parent 16d9463156
commit 28bf34c1bf
14 changed files with 53 additions and 402 deletions

View File

@@ -245,38 +245,41 @@ export async function getRecord(did: string, collection: string, rkey: string):
// Constants for search
const SEARCH_TIMEOUT_MS = 5000
const MAX_SEARCH_LENGTH = 20
// Get current network config
export async function getCurrentNetwork(): Promise<{ plc: string; bsky: string; web: string }> {
const config = await getConfig()
const networks = await getNetworks()
const networkKey = config.network || 'bsky.social'
const network = networks[networkKey]
return {
plc: network?.plc || 'https://plc.directory',
bsky: network?.bsky || 'https://public.api.bsky.app',
web: network?.web || 'https://bsky.app'
}
}
// Get search endpoint for current network
async function getSearchEndpoint(): Promise<string> {
const network = await getCurrentNetwork()
return network.bsky
}
// Search posts that link to a URL
export async function searchPostsForUrl(url: string): Promise<SearchPost[]> {
// Use public.api.bsky.app for search
const endpoint = 'https://public.api.bsky.app'
// Use current network's endpoint for search
const endpoint = await getSearchEndpoint()
// Extract search-friendly patterns from URL
// Note: Search API doesn't index paths well, so search by domain and filter client-side
const searchQueries: string[] = []
try {
const urlObj = new URL(url)
const pathWithDomain = urlObj.host + urlObj.pathname.replace(/\/$/, '')
// Limit length for search
if (pathWithDomain.length <= MAX_SEARCH_LENGTH) {
searchQueries.push(pathWithDomain)
} else {
// Truncate to max length
searchQueries.push(pathWithDomain.slice(0, MAX_SEARCH_LENGTH))
}
// Also try shorter path
const pathParts = urlObj.pathname.split('/').filter(Boolean)
if (pathParts.length >= 1) {
const shortPath = urlObj.host + '/' + pathParts[0]
if (shortPath.length <= MAX_SEARCH_LENGTH) {
searchQueries.push(shortPath)
}
}
// Search by domain only (paths with / don't return results)
searchQueries.push(urlObj.host)
} catch {
searchQueries.push(url.slice(0, MAX_SEARCH_LENGTH))
searchQueries.push(url)
}
const allPosts: SearchPost[] = []