deckhearth/pages/api/public/games/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

30 lines
980 B
JavaScript

import { sql } from '../../../../lib/sql.js';
/**
* Public listing of community-shared custom games. No auth — read-only.
*/
export default async function handler(req, res) {
try {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' });
}
const result = await sql`
SELECT g.id, g.name, g.description, g.updated_at,
COUNT(c.id) AS card_count,
COALESCE(NULLIF(u.username, ''), split_part(u.email, '@', 1)) AS author
FROM custom_games g
JOIN users u ON u.id = g.user_id
LEFT JOIN custom_cards c ON c.custom_game_id = g.id
WHERE g.is_public = true
GROUP BY g.id, u.username, u.email
ORDER BY card_count DESC, g.updated_at DESC
LIMIT 100
`;
return res.status(200).json({ games: result.rows });
} catch (error) {
console.error('Public games API error:', error);
return res.status(500).json({ error: 'Internal server error' });
}
}