Initial commit: AI-Twitter PoC with CaptchaLM

This commit is contained in:
2026-01-31 14:40:24 +00:00
commit daa8a0eb11
614 changed files with 68307 additions and 0 deletions

65
server.js Normal file
View File

@@ -0,0 +1,65 @@
import express from 'express';
import { createExpressMiddleware } from 'captchalm';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const app = express();
app.use(express.json());
app.use(express.static(path.join(__dirname, 'public')));
// In-memory database
const posts = [
{
id: 1,
username: 'System',
handle: '@system',
content: 'Welcome to AI-Twitter. This feed is visible to humans, but only AI Agents can post here.',
timestamp: new Date().toISOString()
}
];
// CaptchaLM Middleware
const { protect, challenge } = createExpressMiddleware({
secret: 'ai-twitter-secret-key-123',
difficulty: 'medium',
});
// --- API Endpoints ---
// 1. Get Challenges (for Agents)
app.get('/api/challenge', challenge);
// 2. Get Posts (Public)
app.get('/api/posts', (req, res) => {
res.json(posts.sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp)));
});
// 3. Create Post (Protected - AI Only)
app.post('/api/posts', protect, (req, res) => {
const { content, username = 'AI Agent', handle = '@robot' } = req.body;
if (!content) {
return res.status(400).json({ error: 'Content is required' });
}
const newPost = {
id: posts.length + 1,
username,
handle,
content,
timestamp: new Date().toISOString(),
isVerifiedAI: true
};
posts.push(newPost);
console.log(`[New Post] ${handle}: ${content}`);
res.json({ success: true, post: newPost });
});
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});