deckhearth/pages/api/custom-frames/index.js
Randall Stillwell 5b9a278ca2 feat(designer): inline symbol icons, frame textures, community sharing, print sheets
- {CODE} tokens in description/actions/flavor render as inline symbol
  icons (RichText), including inside cost pips
- custom frames gain an optional background texture (upload/replace/
  remove via /api/custom-frames/[id]/texture); renders behind panels
- custom games can be shared to the community (is_public): toggle in the
  game space, public listing at /community/games, read-only game view,
  /api/public/games endpoints (no auth, public rows only)
- /designer/print: multi-card print sheets on US Letter at 300dpi
  (63x88mm cards, 3x3 or 2x2, dashed cut guides, full-sheet PNG export)
- migration 1787711511000
2026-08-24 21:48:52 -05:00

59 lines
2.1 KiB
JavaScript

import { sql } from '../../../lib/sql.js';
import { getUserFromRequest } from '../../../lib/permission-middleware';
import { validatePalette } from '../../../lib/frame-palette.js';
export default async function handler(req, res) {
try {
const user = await getUserFromRequest(req);
if (!user) {
return res.status(401).json({ error: 'Authentication required' });
}
if (req.method === 'GET') {
const result = await sql`
SELECT id, name, palette, texture_url, created_at, updated_at
FROM custom_frames
WHERE user_id = ${user.userId}
ORDER BY name ASC
`;
return res.status(200).json({ frames: result.rows });
}
if (req.method === 'POST') {
const name = typeof req.body?.name === 'string' ? req.body.name.trim() : '';
if (!name || name.length > 100) {
return res.status(400).json({ error: 'Frame name is required (100 characters max)' });
}
const { palette, error } = validatePalette(req.body?.palette);
if (error) {
return res.status(400).json({ error });
}
const textureUrl =
typeof req.body?.texture_url === 'string' && req.body.texture_url.trim()
? req.body.texture_url.trim()
: null;
const clash = await sql`
SELECT id FROM custom_frames
WHERE user_id = ${user.userId} AND lower(name) = ${name.toLowerCase()}
`;
if (clash.rows.length > 0) {
return res.status(409).json({ error: 'You already have a frame with that name' });
}
const inserted = await sql`
INSERT INTO custom_frames (user_id, name, palette, texture_url)
VALUES (${user.userId}, ${name}, ${sql.json(palette)}, ${textureUrl})
RETURNING id, name, palette, texture_url, created_at, updated_at
`;
return res.status(201).json({ frame: inserted.rows[0] });
}
return res.status(405).json({ error: 'Method not allowed' });
} catch (error) {
console.error('Custom frames API error:', error);
return res.status(500).json({ error: 'Internal server error' });
}
}