Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214#!/usr/bin/env node
/** * Inspect API Endpoints * * Test painting-related APIs on local or live server. * * Usage: * node inspect-api.mjs --tv * node inspect-api.mjs --painting-code waf * node inspect-api.mjs --media-collection @fifi/painting * node inspect-api.mjs --endpoint /api/custom */
import { config } from 'dotenv';
config();
const AC_API = process.env.AC_API || 'http://localhost:8888';const args = process.argv.slice(2);
async function testEndpoint(path, label) { console.log(`\n๐ Testing: ${label}`); console.log(` ${AC_API}${path}`); console.log('โ'.repeat(70) + '\n'); try { const start = Date.now(); const response = await fetch(`${AC_API}${path}`); const duration = Date.now() - start; console.log(`๐ Response:`); console.log(` Status: ${response.status} ${response.statusText}`); console.log(` Duration: ${duration}ms`); console.log(` Content-Type: ${response.headers.get('content-type')}`); console.log(); if (response.ok) { const data = await response.json(); console.log('โ
Success\n'); console.log('๐ฆ Response Data:'); console.log(JSON.stringify(data, null, 2).split('\n').slice(0, 30).join('\n')); // Show summary based on endpoint if (data.media?.paintings) { console.log(`\n๐ Found ${data.media.paintings.length} paintings`); const withCodes = data.media.paintings.filter(p => p.code).length; console.log(` With codes: ${withCodes}`); } console.log(); return { ok: true, duration, data }; } else { console.log('โ Error Response\n'); const text = await response.text(); console.log(text); console.log(); return { ok: false, duration, error: text }; } } catch (error) { console.error(`โ Error: ${error.message}\n`); return { ok: false, error: error.message }; }}
async function testTV() { const result = await testEndpoint('/api/tv?limit=10', 'TV Feed API'); if (result.ok && result.data?.media?.paintings) { console.log('๐ธ Sample Paintings:\n'); result.data.media.paintings.slice(0, 5).forEach((p, i) => { console.log(` ${i + 1}. ${p.slug}`); console.log(` User: ${p.owner?.handle || p.user}`); console.log(` Code: ${p.code || '(none)'}`); console.log(` URL: ${p.media?.url}`); console.log(); }); }}
async function testPaintingCode(code) { const cleanCode = code.replace('#', ''); await testEndpoint(`/api/painting-code/${cleanCode}`, `Painting Code Lookup: ${code}`);}
async function testMediaCollection(path) { await testEndpoint(`/api/media-collection?for=${path}`, `Media Collection: ${path}`);}
async function testCustomEndpoint(path) { await testEndpoint(path, `Custom Endpoint: ${path}`);}
async function testAll() { console.log('\n๐งช Running All API Tests'); console.log('โ'.repeat(70)); const tests = [ { name: 'TV Feed', fn: () => testTV() }, { name: 'Painting Code (if available)', fn: () => testPaintingCode('waf') }, { name: 'Media Collection', fn: () => testMediaCollection('@fifi/painting') } ]; const results = []; for (const test of tests) { try { const result = await test.fn(); results.push({ name: test.name, success: result?.ok !== false }); } catch (error) { results.push({ name: test.name, success: false }); } } console.log('\nโ'.repeat(70)); console.log('๐ Test Summary:\n'); results.forEach((result, i) => { const icon = result.success ? 'โ
' : 'โ'; console.log(` ${icon} ${result.name}`); }); console.log();}
async function checkHealth() { console.log(`\n๐ฅ Checking API Health`); console.log(` Server: ${AC_API}`); console.log('โ'.repeat(70) + '\n'); const endpoints = [ '/api/tv', '/api/media-collection', '/.netlify/functions/tv', '/.netlify/functions/track-media' ]; console.log('Testing endpoints:\n'); for (const endpoint of endpoints) { try { const start = Date.now(); const response = await fetch(`${AC_API}${endpoint}`); const duration = Date.now() - start; const icon = response.ok ? 'โ
' : 'โ'; console.log(` ${icon} ${endpoint} (${response.status}, ${duration}ms)`); } catch (error) { console.log(` โ ${endpoint} (${error.message})`); } } console.log();}
async function main() { console.log(`\n๐ API Inspector`); console.log(` Target: ${AC_API}`); console.log(` Environment: ${AC_API.includes('localhost') ? 'LOCAL' : 'LIVE'}`); console.log(); try { if (args.includes('--tv')) { await testTV(); } else if (args.includes('--painting-code')) { const codeIndex = args.indexOf('--painting-code'); const code = args[codeIndex + 1]; if (!code) { console.error('โ Error: --painting-code requires a code'); process.exit(1); } await testPaintingCode(code); } else if (args.includes('--media-collection')) { const pathIndex = args.indexOf('--media-collection'); const path = args[pathIndex + 1]; if (!path) { console.error('โ Error: --media-collection requires a path'); process.exit(1); } await testMediaCollection(path); } else if (args.includes('--endpoint')) { const endpointIndex = args.indexOf('--endpoint'); const endpoint = args[endpointIndex + 1]; if (!endpoint) { console.error('โ Error: --endpoint requires a path'); process.exit(1); } await testCustomEndpoint(endpoint); } else if (args.includes('--health')) { await checkHealth(); } else if (args.includes('--all')) { await testAll(); } else { console.log('Usage:'); console.log(' node inspect-api.mjs --tv # Test TV feed'); console.log(' node inspect-api.mjs --painting-code waf # Test code lookup'); console.log(' node inspect-api.mjs --media-collection @fifi/painting'); console.log(' node inspect-api.mjs --endpoint /api/custom # Test custom endpoint'); console.log(' node inspect-api.mjs --health # Check API health'); console.log(' node inspect-api.mjs --all # Run all tests'); console.log(); console.log('Environment:'); console.log(` AC_API=${AC_API}`); console.log(); } } catch (error) { console.error('\n๐ฅ Error:', error.message); process.exit(1); }}
main();