hensei-web/pages/api/preview/[shortcode].tsx
Justin Edmund a02a6c70aa
Jedmund/image embeds 2 (#424)
## Component Refactors:
- Updated `CharacterHovercard` to improve over mastery and awakening
section logic.
- Refactored `CharacterModal` to streamline state management (rings,
awakening, perpetuity) and object preparation.
- Adjusted `CharacterUnit` for consistent over mastery handling.
- Simplified `AwakeningSelectWithInput` to use awakening slug values and
improve error handling.
- Updated `RingSelect` to refine ring value syncing and index logic.
- Modified `Party` and `PartyHead` to ensure consistent over mastery
processing and proper preview URL construction.
- Updated `WeaponModal` to align awakening value handling with the new
slug-based approach.

## Styling and Configuration:
- Improved grid layout and styling in the `WeaponRep` SCSS module.
- Updated `next.config.js` rewrite rules to support new preview and
character routes.
- Added a new API endpoint (`pages/api/preview/[shortcode].tsx`) for
fetching party preview images.

## Type Definitions:
- Refined types in `types/GridCharacter.d.ts` and `types/index.d.ts` to
reflect updated structures for rings, over mastery, and awakening.
2025-02-09 22:54:15 -08:00

33 lines
931 B
TypeScript

import type { NextApiRequest, NextApiResponse } from 'next'
import axios from 'axios'
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const { shortcode } = req.query
if (!shortcode || Array.isArray(shortcode)) {
return res.status(400).json({ error: 'Invalid shortcode' })
}
try {
const response = await axios({
method: 'GET',
url: `${process.env.NEXT_PUBLIC_SIERO_API_URL}/parties/${shortcode}/preview`,
responseType: 'arraybuffer',
headers: {
Accept: 'image/png',
},
})
// Set correct content type and caching headers
res.setHeader('Content-Type', 'image/png')
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable')
return res.send(response.data)
} catch (error) {
console.error('Error fetching preview:', error)
return res.status(500).json({ error: 'Failed to fetch preview' })
}
}