Initial commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function GET() {
|
||||
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
|
||||
const nodeName = process.env.NEXT_PUBLIC_NODE_NAME || 'Synapsis Node';
|
||||
const nodeDescription = process.env.NEXT_PUBLIC_NODE_DESCRIPTION || 'A Synapsis federated social network node';
|
||||
|
||||
return NextResponse.json({
|
||||
links: [
|
||||
{
|
||||
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.1',
|
||||
href: `https://${nodeDomain}/nodeinfo/2.1`,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { db, handleRegistry } from '@/db';
|
||||
import { desc, eq, gt } from 'drizzle-orm';
|
||||
import { normalizeHandle } from '@/lib/federation/handles';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
if (!db) {
|
||||
return NextResponse.json({ handles: [] });
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const handleParam = searchParams.get('handle');
|
||||
const sinceParam = searchParams.get('since');
|
||||
const limit = Math.min(parseInt(searchParams.get('limit') || '100'), 500);
|
||||
|
||||
if (handleParam) {
|
||||
const cleanHandle = normalizeHandle(handleParam);
|
||||
const entry = await db.query.handleRegistry.findFirst({
|
||||
where: eq(handleRegistry.handle, cleanHandle),
|
||||
});
|
||||
|
||||
if (!entry) {
|
||||
return NextResponse.json({ handles: [] });
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
handles: [{
|
||||
handle: entry.handle,
|
||||
did: entry.did,
|
||||
nodeDomain: entry.nodeDomain,
|
||||
updatedAt: entry.updatedAt,
|
||||
}],
|
||||
});
|
||||
}
|
||||
|
||||
const sinceDate = sinceParam ? new Date(sinceParam) : null;
|
||||
const entries = await db.query.handleRegistry.findMany({
|
||||
where: sinceDate ? gt(handleRegistry.updatedAt, sinceDate) : undefined,
|
||||
orderBy: [desc(handleRegistry.updatedAt)],
|
||||
limit,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
handles: entries.map((entry) => ({
|
||||
handle: entry.handle,
|
||||
did: entry.did,
|
||||
nodeDomain: entry.nodeDomain,
|
||||
updatedAt: entry.updatedAt,
|
||||
})),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Handle export error:', error);
|
||||
return NextResponse.json({ error: 'Failed to export handles' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* 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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { db, users } from '@/db';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { generateWebFingerResponse, parseWebFingerResource } from '@/lib/activitypub/webfinger';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const resource = searchParams.get('resource');
|
||||
|
||||
if (!resource) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Missing resource parameter' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const parsed = parseWebFingerResource(resource);
|
||||
|
||||
if (!parsed) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Invalid resource format' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
|
||||
|
||||
// Check if this is our domain
|
||||
if (parsed.domain !== nodeDomain && parsed.domain !== nodeDomain.replace(/:\d+$/, '')) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Resource not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
// Find the user
|
||||
const user = await db.query.users.findFirst({
|
||||
where: eq(users.handle, parsed.handle.toLowerCase()),
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
return NextResponse.json(
|
||||
{ error: 'User not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
const response = generateWebFingerResponse(user.handle, nodeDomain);
|
||||
|
||||
return NextResponse.json(response, {
|
||||
headers: {
|
||||
'Content-Type': 'application/jrd+json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user