refact update
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { AtpAgent } from '@atproto/api'
|
||||
import type { Profile, BlogPost, NetworkConfig } from '../types.js'
|
||||
import { FALLBACK_PLCS, FALLBACK_BSKY_ENDPOINTS, SEARCH_TIMEOUT_MS } from './constants.js'
|
||||
|
||||
const agents: Map<string, AtpAgent> = new Map()
|
||||
|
||||
@@ -24,18 +25,6 @@ export function getAgent(service: string): AtpAgent {
|
||||
return agents.get(service)!
|
||||
}
|
||||
|
||||
// Fallback PLC directories
|
||||
const FALLBACK_PLCS = [
|
||||
'https://plc.directory',
|
||||
'https://plc.syu.is',
|
||||
]
|
||||
|
||||
// Fallback endpoints for handle/profile resolution
|
||||
const FALLBACK_ENDPOINTS = [
|
||||
'https://public.api.bsky.app',
|
||||
'https://bsky.syu.is',
|
||||
]
|
||||
|
||||
export async function resolvePds(did: string): Promise<string> {
|
||||
// Try current PLC first, then fallbacks
|
||||
const plcs = [getPlc(), ...FALLBACK_PLCS.filter(p => p !== getPlc())]
|
||||
@@ -64,7 +53,7 @@ export async function resolveHandle(handle: string): Promise<string> {
|
||||
return res.data.did
|
||||
} catch {
|
||||
// Try fallback endpoints
|
||||
for (const endpoint of FALLBACK_ENDPOINTS) {
|
||||
for (const endpoint of FALLBACK_BSKY_ENDPOINTS) {
|
||||
if (endpoint === getBsky()) continue // Skip if same as current
|
||||
try {
|
||||
const agent = getAgent(endpoint)
|
||||
@@ -80,7 +69,7 @@ export async function resolveHandle(handle: string): Promise<string> {
|
||||
|
||||
export async function getProfile(actor: string): Promise<Profile> {
|
||||
// Try current network first
|
||||
const endpoints = [getBsky(), ...FALLBACK_ENDPOINTS.filter(e => e !== getBsky())]
|
||||
const endpoints = [getBsky(), ...FALLBACK_BSKY_ENDPOINTS.filter(e => e !== getBsky())]
|
||||
|
||||
for (const endpoint of endpoints) {
|
||||
try {
|
||||
@@ -273,7 +262,7 @@ export async function searchPostsForUrl(url: string): Promise<any[]> {
|
||||
searchQueries.map(async query => {
|
||||
try {
|
||||
const controller = new AbortController()
|
||||
const timeoutId = setTimeout(() => controller.abort(), 5000) // 5s timeout
|
||||
const timeoutId = setTimeout(() => controller.abort(), SEARCH_TIMEOUT_MS)
|
||||
|
||||
const res = await fetch(
|
||||
`${endpoint}/xrpc/app.bsky.feed.searchPosts?q=${encodeURIComponent(query)}&limit=20`,
|
||||
|
||||
Reference in New Issue
Block a user