Ctrl K
ComunidadGuías…

server/src/routes/announcements.ts

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
import { Router, Request, Response } from 'express';

import logger from '../utils/logger';
import { getAnnouncementsState, refreshAnnouncements, refreshIfDue } from '../services/announcements';

const router = Router();

// GET /api/announcements - Everything the "What's new" panel shows.
// Refreshes the remote feed first when it is due, so a page load a few
// minutes after something is published sees it without a manual refresh.
router.get('/', async (_req: Request, res: Response) => {
  try {
    await refreshIfDue();
    res.json({ success: true, data: getAnnouncementsState() });
  } catch (error) {
    logger.error('Failed to get announcements:', error);
    res.status(500).json({ success: false, error: 'Failed to retrieve announcements' });
  }
});

// POST /api/announcements/refresh - Fetch the remote feed now, then return the state
router.post('/refresh', async (_req: Request, res: Response) => {
  try {
    const result = await refreshAnnouncements(true);
    res.json({ success: true, data: { ...getAnnouncementsState(), refresh: result } });
  } catch (error) {
    logger.error('Failed to refresh announcements:', error);
    res.status(500).json({ success: false, error: 'Failed to refresh announcements' });
  }
});

export default router;