"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reactionsRoutes = reactionsRoutes; const database_1 = require("../../../config/database"); const auth_1 = require("../middleware/auth"); // Rebranded reaction emojis (6 standard social reactions) const REACTION_EMOJIS = { like: '👍', love: '❤️', laugh: '😂', wow: '😮', sad: '😢', angry: '😠', }; // Format video timestamp as MM:SS or H:MM:SS function formatVideoTime(seconds) { const h = Math.floor(seconds / 3600); const m = Math.floor((seconds % 3600) / 60); const s = seconds % 60; if (h > 0) { return `${h}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`; } return `${m}:${s.toString().padStart(2, '0')}`; } async function reactionsRoutes(fastify) { // Add reaction (authenticated users only) fastify.post('/', { preHandler: auth_1.authenticate, }, async (request, reply) => { const { mediaId, reactionType, videoTimestamp } = request.body; const userId = request.user.id; // Validate reaction type if (!REACTION_EMOJIS[reactionType]) { return reply.code(400).send({ message: 'Invalid reaction type' }); } // Check if video exists const video = await database_1.prisma.video.findUnique({ where: { id: mediaId }, }); if (!video) { return reply.code(404).send({ message: 'Video not found' }); } // Create reaction const reaction = await database_1.prisma.videoReaction.create({ data: { mediaId, userId, reactionType: reactionType, // Cast string to ReactionType enum videoTimestamp, createdAt: new Date(), }, }); return { success: true, reaction: { ...reaction, emoji: REACTION_EMOJIS[reactionType], formattedTime: formatVideoTime(videoTimestamp), }, }; }); // Get reactions fastify.get('/', async (request, reply) => { const { mediaId, userId, limit = '50' } = request.query; const where = {}; // Filter by mediaId if provided if (mediaId) { where.mediaId = parseInt(mediaId); } // Filter by userId if provided if (userId) { where.userId = userId; } const reactions = await database_1.prisma.videoReaction.findMany({ where, orderBy: { createdAt: 'desc', }, take: parseInt(limit), }); // Enhance with emojis and formatted times const enhancedReactions = reactions.map(r => ({ ...r, emoji: REACTION_EMOJIS[r.reactionType] || '❓', formattedTime: formatVideoTime(r.videoTimestamp), })); return { reactions: enhancedReactions, }; }); // Get reaction config (returns available reactions) fastify.get('/config', async (request, reply) => { return { reactions: Object.entries(REACTION_EMOJIS).map(([type, emoji]) => ({ type, emoji, label: type.charAt(0).toUpperCase() + type.slice(1), })), }; }); } //# sourceMappingURL=reactions.routes.js.map