feat: add Nimbus Editor with Unsplash integration
- Integrated Unsplash API for image search functionality with environment configuration - Added new Nimbus Editor page component with navigation from sidebar and mobile drawer - Enhanced TOC with highlight animation for editor heading navigation - Improved CDK overlay z-index hierarchy for proper menu layering - Removed obsolete logging validation script
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import express from 'express';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Simple proxy to Unsplash Search API.
|
||||
// Requires UNSPLASH_ACCESS_KEY in environment; returns 501 if missing.
|
||||
router.get('/search', async (req, res) => {
|
||||
try {
|
||||
const ACCESS_KEY = process.env.UNSPLASH_ACCESS_KEY;
|
||||
if (!ACCESS_KEY) {
|
||||
return res.status(501).json({ error: 'unsplash_disabled' });
|
||||
}
|
||||
const q = String(req.query.q || '').trim();
|
||||
const perPage = Math.min(50, Math.max(1, Number(req.query.perPage || 24)));
|
||||
if (!q) return res.json({ results: [] });
|
||||
|
||||
const url = new URL('https://api.unsplash.com/search/photos');
|
||||
url.searchParams.set('query', q);
|
||||
url.searchParams.set('per_page', String(perPage));
|
||||
url.searchParams.set('client_id', ACCESS_KEY);
|
||||
// Prefer landscape/small for editor usage
|
||||
url.searchParams.set('orientation', 'landscape');
|
||||
|
||||
const upstream = await fetch(url.toString(), { headers: { 'Accept-Version': 'v1' } });
|
||||
if (!upstream.ok) {
|
||||
const text = await upstream.text().catch(() => '');
|
||||
return res.status(502).json({ error: 'unsplash_upstream_error', status: upstream.status, message: text });
|
||||
}
|
||||
const json = await upstream.json();
|
||||
// Map minimal fields used by the client
|
||||
const results = Array.isArray(json?.results) ? json.results.map((r) => ({
|
||||
id: r.id,
|
||||
alt_description: r.alt_description || null,
|
||||
urls: r.urls,
|
||||
links: r.links,
|
||||
user: r.user ? { name: r.user.name } : undefined,
|
||||
})) : [];
|
||||
return res.json({ results });
|
||||
} catch (e) {
|
||||
console.error('[Unsplash] proxy error', e);
|
||||
return res.status(500).json({ error: 'internal_error' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user