e2fa572e84
- Add swarm node registry with discovery, gossip, and timeline synchronization - Implement database schema for swarm nodes, seeds, and sync logs with proper indexing - Create swarm API endpoints for node discovery, gossip protocol, timeline sharing, and announcements - Add content moderation features with NSFW flagging and muted nodes support - Implement user settings pages for content filtering and node moderation - Add background scheduler for automated swarm synchronization and node health checks - Create .well-known endpoint for swarm protocol discovery - Remove legacy bot-cron.ts in favor of integrated scheduler system - Add user account NSFW preferences and age verification tracking - Update database schema with swarm-related tables and user moderation fields - Enhance post and user components to support federated content display - Add instrumentation for monitoring swarm operations and node health
78 lines
2.1 KiB
TypeScript
78 lines
2.1 KiB
TypeScript
/**
|
|
* Well-Known Synapsis Swarm Endpoint
|
|
*
|
|
* GET /.well-known/synapsis-swarm
|
|
*
|
|
* Returns information about this node and the swarm it knows about.
|
|
* This is a standardized discovery endpoint that other nodes can use
|
|
* to find and join the swarm.
|
|
*/
|
|
|
|
import { NextResponse } from 'next/server';
|
|
import { buildAnnouncement } from '@/lib/swarm/discovery';
|
|
import { getActiveSwarmNodes, getSwarmStats, getSeedNodes } from '@/lib/swarm/registry';
|
|
|
|
export async function GET(request: Request) {
|
|
try {
|
|
const { searchParams } = new URL(request.url);
|
|
const includeNodes = searchParams.get('nodes') !== 'false';
|
|
const limit = Math.min(parseInt(searchParams.get('limit') || '50'), 200);
|
|
|
|
const announcement = await buildAnnouncement();
|
|
const stats = await getSwarmStats();
|
|
const seeds = await getSeedNodes();
|
|
|
|
const response: {
|
|
// This node's info
|
|
node: {
|
|
domain: string;
|
|
name: string;
|
|
description?: string;
|
|
publicKey: string;
|
|
softwareVersion: string;
|
|
capabilities: string[];
|
|
};
|
|
// Swarm metadata
|
|
swarm: {
|
|
totalNodes: number;
|
|
activeNodes: number;
|
|
totalUsers: number;
|
|
totalPosts: number;
|
|
seeds: string[];
|
|
};
|
|
// Known nodes (optional)
|
|
nodes?: Awaited<ReturnType<typeof getActiveSwarmNodes>>;
|
|
} = {
|
|
node: {
|
|
domain: announcement.domain,
|
|
name: announcement.name,
|
|
description: announcement.description,
|
|
publicKey: announcement.publicKey,
|
|
softwareVersion: announcement.softwareVersion,
|
|
capabilities: announcement.capabilities,
|
|
},
|
|
swarm: {
|
|
...stats,
|
|
seeds,
|
|
},
|
|
};
|
|
|
|
if (includeNodes) {
|
|
response.nodes = await getActiveSwarmNodes(limit);
|
|
}
|
|
|
|
return NextResponse.json(response, {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Cache-Control': 'public, max-age=300', // Cache for 5 minutes
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error('Synapsis swarm well-known error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch swarm info' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|