Lumen & Gesso / website · lumengesso.com / app / admin / images / page.tsx
| 1 | import { redirect } from 'next/navigation'; |
| 2 | import { getCustomerUser } from '@/app/lib/lumen-auth'; |
| 3 | import { isAdmin } from '@/app/lib/admin'; |
| 4 | import { listImages, deliveryBase, type CfImage } from '@/app/lib/cf-images'; |
| 5 | import { pinterestSetupStatus } from '@/app/lib/pinterest'; |
| 6 | import { CdnBrowser } from './CdnBrowser'; |
| 7 | import { AdminNav } from '../AdminNav'; |
| 8 | |
| 9 | export const dynamic = 'force-dynamic'; |
| 10 | |
| 11 | // Admin-only browser for everything in Cloudflare Images — thumbnails + |
| 12 | // copyable filenames, so the studio can reference an existing render by name. |
| 13 | export default async function AdminImagesPage() { |
| 14 | const user = await getCustomerUser(); |
| 15 | if (!user) redirect('/login?next=/admin/images'); |
| 16 | if (!isAdmin(user.email)) redirect('/orders'); |
| 17 | |
| 18 | let images: CfImage[] = []; |
| 19 | let error: string | null = null; |
| 20 | try { |
| 21 | images = await listImages(); |
| 22 | } catch (e) { |
| 23 | error = e instanceof Error ? e.message : 'Failed to list images'; |
| 24 | } |
| 25 | const pinterestReady = (await pinterestSetupStatus()).ready; |
| 26 | |
| 27 | return ( |
| 28 | <main className="orders"> |
| 29 | <div className="orders__inner" style={{ maxWidth: 1120 }}> |
| 30 | <h1 className="orders__title">Admin · CDN images</h1> |
| 31 | <AdminNav email={user.email!} current="images" /> |
| 32 | {error ? ( |
| 33 | <p style={{ color: 'var(--rose-deep)' }}>Couldn't load images: {error}</p> |
| 34 | ) : ( |
| 35 | <CdnBrowser |
| 36 | images={images} |
| 37 | deliveryBase={deliveryBase()} |
| 38 | pinterestReady={pinterestReady} |
| 39 | /> |
| 40 | )} |
| 41 | </div> |
| 42 | </main> |
| 43 | ); |
| 44 | } |