Spaces:
Paused
Paused
| import { Hono } from 'hono'; | |
| import { config } from '../config'; | |
| import { cache } from '../services/cache'; | |
| const fullImageApp = new Hono(); | |
| // Full image endpoint - matches Next.js /api/full-image | |
| fullImageApp.get('/', async (c) => { | |
| try { | |
| const docId = c.req.query('docId'); | |
| if (!docId) { | |
| return c.json({ error: 'docId is required' }, 400); | |
| } | |
| // Check cache | |
| const cacheKey = `fullimage:${docId}`; | |
| const cachedImage = cache.get<{ base64_image: string }>(cacheKey); | |
| if (cachedImage) { | |
| c.header('X-Cache', 'HIT'); | |
| return c.json(cachedImage); | |
| } | |
| // Proxy to backend | |
| const imageUrl = `${config.backendUrl}/full_image?doc_id=${encodeURIComponent(docId)}`; | |
| const response = await fetch(imageUrl); | |
| if (!response.ok) { | |
| throw new Error(`Backend returned ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| // Cache for 24 hours | |
| cache.set(cacheKey, data, 86400); | |
| c.header('X-Cache', 'MISS'); | |
| return c.json(data); | |
| } catch (error) { | |
| console.error('Full image error:', error); | |
| return c.json({ | |
| error: 'Failed to fetch image', | |
| message: error instanceof Error ? error.message : 'Unknown error' | |
| }, 500); | |
| } | |
| }); | |
| export { fullImageApp }; |