Files
Showy/backend/routes/entry.routes.js
T
Mohammed Abad ab20a5e64f feat: multi-page improvements, bug fixes, and new features
Library:
- Exclude hidden entries from all/movies/tv/favorites tabs (only show in hidden tab)

Entry Details:
- Move favorite, mark watched, and more actions to top-right as icon-only buttons with tooltips
- Fix season card play button — marks next unwatched episode as seen

Seasons Page:
- Fix episode watch button (was a TODO stub, now calls createEpisodeSeen)

Episode Page:
- Fix UI not updating after deleting the last watch record — invalidate season episodes query on delete

Dashboard:
- Fix Top Genres 404 — was calling non-existent GET /statistics, now uses /statistics/watch-time
- Fix TopGenresChart genre counting (Genre objects were wrongly cast as strings)
- Add LibraryGrowthChart (cumulative titles added over time)
- Add MediaTypeChart (Movies vs TV Series donut chart)

Home Page:
- Add TrendingSlider hero at top of page with auto-advance, dots, and prev/next nav
- Fix slider prev/next buttons (stable callbacks via ref, plain buttons, reactive library state)
- Add debounce (400ms) to search input
- Add Top Rated section (movies & TV)
- Add Upcoming section (movies)
- Replace inline "More" expand with link to /discover/:category

Discover Page (new):
- Full-page TMDB browser per category (trending/popular/top-rated/upcoming)
- Movie/TV tab toggle
- IntersectionObserver infinite scroll

Calendar:
- Fix large season numbers — use season.season_number instead of season_id (DB primary key)

Backend:
- Add fetchTopRated() and fetchUpcoming() to tmdbService
- Add GET /entries/tmdb/top-rated/:type and /entries/tmdb/upcoming/movie routes
2026-04-02 03:29:54 +01:00

149 lines
4.6 KiB
JavaScript

const express = require('express');
const entryRouter = express.Router();
const { entryPicturesUpload } = require('../services/mutlerStorageLocations');
const Entry = require('../models/Entry');
const Media = require('../models/Media');
const { logToFile } = require('../services/logService');
const entryController = require('../controllers/entryController');
const mediaOptimizerService = require('../services/mediaOptimizerService');
// ! /entries
// ! TMDB PROXY ROUTES (must be before /:id to avoid matching)
entryRouter.get('/tmdb/trending/:type', entryController.getTmdbTrending);
entryRouter.get('/tmdb/popular/:type', entryController.getTmdbPopular);
entryRouter.get('/tmdb/top-rated/:type', entryController.getTmdbTopRated);
entryRouter.get('/tmdb/upcoming/movie', entryController.getTmdbUpcoming);
entryRouter.get('/tmdb/search', entryController.getTmdbSearch);
entryRouter.get('/sync-series', entryController.syncSeries);
entryRouter.get('/', entryController.getAllEntries);
entryRouter.get('/:id', entryController.getEntryById);
entryRouter.post('/', entryController.fetchAndSaveNewEntry);
entryRouter.put('/:id', entryController.updateEntry);
entryRouter.put('/:id/ratings', entryController.updateEntryRatings);
entryRouter.put('/:id/ids', entryController.updateEntryIds);
entryRouter.delete('/:id', entryController.deleteEntry);
entryRouter.get('/:id/seasons', entryController.getEntrySeasons);
entryRouter.put('/:id/refresh', entryController.refrechEntry);
entryRouter.put('/:id/fetch-collection', entryController.fetchEntryCollection);
// ! ENTRY MEDIA
// * POST - ADD NEW ENTRY MEDIA (poster/backdrop/logo)
const upload = entryPicturesUpload.fields([
{ name: 'poster', maxCount: 1 },
{ name: 'backdrop', maxCount: 1 },
{ name: 'logo', maxCount: 1 }
]);
entryRouter.post('/:id/media', upload, async (req, res) => {
const { id } = req.params;
if (!req.files) {
return res.status(400).json({ message: 'No files uploaded' });
}
const entry = await Entry.findByPk(id);
if (!entry) {
return res.status(404).json({ message: 'Entry not found' });
}
// Function to handle media creation based on uploaded file type
const fileType = ['poster', 'backdrop', 'logo'].find(type => req.files[type]);
if (!fileType) {
return res.status(400).json({ message: 'Invalid media type' });
}
const file = req.files[fileType][0];
const createdMedia = await Media.create({
mediaable: 'entry',
mediaableId: id,
type: fileType,
path: file.filename,
isLocal: true,
isSelected: false,
isCustom: true
});
// ? generating low resolution preview
mediaOptimizerService.doGeneratePreview('entries', fileType + 's', file.filename).then((result) => {
const stream = fs.createReadStream(filePath);
stream.pipe(res);
const msg = `Media Route | Generated Entry Preview`
logToFile(msg);
}).catch((err) => {
const msg = `Media Route | Error Generating Entry Preview`
logToFile(msg);
});
return res.status(200).json(createdMedia);
});
// * PUT - SET ENTRY MEDIA AS SELECTED
entryRouter.put('/:entryId/media/:mediaId', upload, async (req, res) => {
const entryId = req.params.entryId;
const mediaId = req.params.mediaId;
const entry = await Entry.findByPk(entryId);
if (!entry) {
return res.status(404).json({ message: 'Entry not found' });
}
const media = await Media.findByPk(mediaId);
if (!media) {
return res.status(404).json({ message: 'Media not found' });
}
// ? setting all other media to not selected
// ? to not have multiple selected media of the same type
await Media.update(
{ isSelected: false },
{
where: {
mediaable: 'entry',
mediaableId: entryId,
type: media.type
}
}
);
const updatedMedia = await media.update({ isSelected: true });
return res.status(200).json(updatedMedia);
});
// * DELETE - DELETE AND ENTRY MEDIA
entryRouter.delete('/:entryId/media/:mediaId', async (req, res) => {
const mediaId = req.params.mediaId;
// ? just before deleting we need to check if the deleted media was the one selected
// ? if so select a new one if there is, then delete
const media = await Media.findByPk(mediaId);
if (media && media.isSelected) {
let otherMedia = await Media.findOne({
where: {
mediaable: 'entry',
mediaableId: media.mediaableId,
type: media.type,
isSelected: false
}
});
// ? if found select the first one
if (otherMedia) {
otherMedia.update({ isSelected: true });
}
}
await Media.destroy({ where: { id: mediaId } })
res.status(200).json();
});
module.exports = entryRouter;