81 lines
2.5 KiB
JavaScript
81 lines
2.5 KiB
JavaScript
const express = require('express');
|
|
const peopleRouter = express.Router();
|
|
const { peoplePicturesUpload } = require('../services/mutlerStorageLocations');
|
|
const mediaOptimizerService = require('../services/mediaOptimizerService');
|
|
const peopleController = require('../controllers/peopleController');
|
|
|
|
// ! /people
|
|
|
|
// ! TMDB PROXY ROUTES (must be before /:id to avoid matching)
|
|
peopleRouter.get('/tmdb/popular', peopleController.getTmdbPopularPeople);
|
|
peopleRouter.get('/tmdb/search', peopleController.searchTmdbPeople);
|
|
peopleRouter.get('/tmdb/preview/:tmdbId', peopleController.getTmdbPersonPreview);
|
|
|
|
// Get all people
|
|
peopleRouter.get('/', peopleController.getAllPeople);
|
|
|
|
// Get popular people
|
|
peopleRouter.get('/popular', peopleController.getPopularPeople);
|
|
|
|
// Search people
|
|
peopleRouter.get('/search', peopleController.searchPeople);
|
|
|
|
// Get person by ID
|
|
peopleRouter.get('/:id', peopleController.getPersonById);
|
|
|
|
// Get person credits (from DB)
|
|
peopleRouter.get('/:id/credits', peopleController.getPersonCredits);
|
|
|
|
// Get person TMDB filmography (all TMDB credits including non-library entries)
|
|
peopleRouter.get('/:id/tmdb-filmography', peopleController.getPersonTmdbFilmography);
|
|
|
|
// Create a new person
|
|
peopleRouter.post('/', peopleController.createPerson);
|
|
|
|
// Fetch and save person from TMDB
|
|
peopleRouter.post('/fetch', peopleController.fetchAndSavePersonByTmdbId);
|
|
|
|
// Update a person
|
|
peopleRouter.put('/:id', peopleController.updatePerson);
|
|
|
|
// Refresh person data from TMDB
|
|
peopleRouter.put('/:id/refresh', peopleController.refreshPerson);
|
|
|
|
// Delete a person
|
|
peopleRouter.delete('/:id', peopleController.deletePerson);
|
|
|
|
// Person media upload handler
|
|
const upload = peoplePicturesUpload.fields([
|
|
{ name: 'profile', maxCount: 1 }
|
|
]);
|
|
|
|
// Upload person profile picture
|
|
peopleRouter.post('/:id/media', upload, async (req, res) => {
|
|
try {
|
|
const personId = req.params.id;
|
|
let result = { success: true, files: [] };
|
|
|
|
// Handle profile picture
|
|
if (req.files.profile) {
|
|
const profileFile = req.files.profile[0];
|
|
const filePath = profileFile.path;
|
|
const fileName = profileFile.filename;
|
|
|
|
// Generate preview for profile picture
|
|
const previewPath = await mediaOptimizerService.doGeneratePreview('people', 'profiles', fileName);
|
|
|
|
result.files.push({
|
|
type: 'profile',
|
|
original: fileName,
|
|
preview: previewPath ? path.basename(previewPath) : null
|
|
});
|
|
}
|
|
|
|
res.status(200).json(result);
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
});
|
|
|
|
module.exports = peopleRouter;
|