From c1837eca1de59a644f02775ecbdbd1f08afddad1 Mon Sep 17 00:00:00 2001 From: "debian.StillHammer" Date: Mon, 8 Dec 2025 12:38:15 +0000 Subject: [PATCH] Add public API documentation endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Features: - New GET /docs/api endpoint to retrieve full API documentation - Returns API.md content as JSON with markdown format - No authentication required (public endpoint) - Includes lastUpdated timestamp - 26,754 characters of complete documentation Response format: { "success": true, "documentation": "", "format": "markdown", "lastUpdated": "2025-12-08T12:12:38.942Z" } Use case: - Fetch documentation programmatically - Display in external applications - Copy-paste into AI assistants (Claude, ChatGPT) - Auto-generate API clients 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/server.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/server.js b/src/server.js index 557dd14..f012e7d 100644 --- a/src/server.js +++ b/src/server.js @@ -101,7 +101,7 @@ app.use((req, res, next) => { // API Authentication Middleware const authenticate = (req, res, next) => { // Skip authentication for public endpoints - const publicEndpoints = ['/health', '/api']; + const publicEndpoints = ['/health', '/api', '/docs/api']; // Allow public download endpoint if (publicEndpoints.includes(req.path) || req.path.startsWith('/public/download/')) { return next(); @@ -174,6 +174,39 @@ app.get('/health', (req, res) => { res.json({ status: 'ok', timestamp: new Date().toISOString() }); }); +/** + * GET /docs/api + * Get complete API documentation (markdown) + */ +app.get('/docs/api', (req, res) => { + try { + const docPath = path.join(__dirname, '../docs/API.md'); + + if (!fs.existsSync(docPath)) { + return res.status(404).json({ + error: 'Documentation not found', + message: 'API documentation file does not exist' + }); + } + + const docContent = fs.readFileSync(docPath, 'utf-8'); + + // Return as JSON with markdown content + res.json({ + success: true, + documentation: docContent, + format: 'markdown', + lastUpdated: fs.statSync(docPath).mtime + }); + } catch (error) { + console.error(`[API Docs] Error: ${error.message}`); + res.status(500).json({ + error: 'Failed to retrieve documentation', + message: error.message + }); + } +}); + /** * GET /public/download/:filename * Public endpoint to download files without authentication @@ -1471,6 +1504,7 @@ app.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); console.log('\nEndpoints:'); console.log(' GET /health - Health check'); + console.log(' GET /docs/api - API documentation (no auth)'); console.log(' GET /public/download/:filename - Public file download (no auth)'); console.log(' GET /info?url= - Get video/playlist info'); console.log(' POST /download - Download as MP3');