aggregate more source

This commit is contained in:
2025-05-17 20:46:23 +02:00
parent 820cc6f209
commit 459b455fee
6 changed files with 422 additions and 52 deletions

View File

@ -1,25 +1,42 @@
const express = require('express');
const cors = require('cors');
const cinecheck = require('./cinecheck-adapter');
const cinecheck = require('./aggregators/cinecheck-adapter');
const commonsense = require('./aggregators/commonsense-adapter');
const filmages = require('./aggregators/filmages-adapter'); // New
const { mergeResults } = require('./merge');
const app = express();
app.use(cors());
app.get('/search', async (req, res) => {
const q = req.query.q;
if (!q) return res.status(400).json({ error: "Missing query" });
if (!q) {
// Gilfoyle: "A search query without a query. Bold."
return res.status(400).json({ error: "Missing query. Astounding." });
}
try {
const results = await cinecheck.searchMovies(q);
// Enrichir chaque film avec la classification (en parallèle, le minimum pour survivre)
const enriched = await Promise.all(results.map(async m => {
const details = await cinecheck.getMovieClassification(m.link);
return { ...m, ...details };
}));
res.json(enriched);
// Mike: "Run 'em all. See what sticks."
const [cine, cs, fa] = await Promise.all([
cinecheck.searchAndEnrich(q).catch(e => { console.error('Cinecheck failed:', e.message); return []; }),
commonsense.searchAndEnrich(q).catch(e => { console.error('Commonsense failed:', e.message); return []; }),
filmages.searchAndEnrich(q).catch(e => { console.error('Filmages failed:', e.message); return []; })
]);
if (!cine.length && !cs.length && !fa.length) {
// Gilfoyle: "Zero results. Is this a surprise to anyone?"
}
const merged = mergeResults([cine, cs, fa]);
res.json(merged);
} catch (e) {
res.status(500).json({ error: e.message });
// Mike: "Something went sideways. Happens."
console.error('General search error:', e);
res.status(500).json({ error: e.message || "Server had a moment." });
}
});
app.listen(3000, () => {
console.log('Backend prêt. http://localhost:3000');
const PORT = 3000;
app.listen(PORT, () => {
// Gilfoyle: "It's listening. Don't get excited."
console.log(`Backend multi-agrégateurs opérationnel sur http://localhost:${PORT}. Ne me remerciez pas.`);
});