Backend - Route all TMDB requests through a rate limiter (20 req/s, 8 concurrent) with 429/5xx retries; stop logging the API key - Fetch external ids, certification, keywords, videos, watch providers and alternative titles in the entry details request - Shared entry mapper used by create, refresh, season refresh and importer - New columns on entries, ids, ratings, seasons, episodes and people, with an idempotent startup migration (adds missing columns, widens types) - Fix TV IMDb ids, network country/logo, episode tmdb_id on refresh, and genre/network removal on refresh - Add stale-entries maintenance job (count, start, cancel) and live recommendations endpoint Frontend - Entry page: certification, tagline, creators, in-app trailer, vote count, TV/movie details, network logos, external links, keywords, where to watch, and recommendations - Episode page: directors, writers and guest stars - Settings: TMDB refresh card with live progress
84 lines
2.1 KiB
JavaScript
84 lines
2.1 KiB
JavaScript
const Collection = require("../models/Collection");
|
|
const Entry = require("../models/Entry");
|
|
const EntryId = require("../models/EntryId");
|
|
const EntryRating = require("../models/EntryRating");
|
|
const Genre = require("../models/Genre");
|
|
const Media = require("../models/Media");
|
|
const Network = require("../models/Network");
|
|
const Season = require("../models/Season");
|
|
|
|
class NetworkService {
|
|
constructor() {
|
|
if (!NetworkService.instance) {
|
|
NetworkService.instance = this;
|
|
}
|
|
return NetworkService.instance;
|
|
}
|
|
|
|
async getNetworks() {
|
|
const networks = await Network.findAll({
|
|
include: [
|
|
{
|
|
model: Entry,
|
|
as: "entries",
|
|
include: { model: Media, as: "medias" },
|
|
},
|
|
],
|
|
order: [["name", "ASC"]],
|
|
});
|
|
|
|
return networks;
|
|
}
|
|
|
|
async getNetworkById(id) {
|
|
const network = await Network.findByPk(id, {
|
|
include: [
|
|
{
|
|
model: Entry,
|
|
as: "entries",
|
|
include: [
|
|
{ model: EntryId, as: "entryId" },
|
|
{ model: EntryRating, as: "entryRating" },
|
|
{ model: Season, as: "seasons" },
|
|
{ model: Media, as: "medias" },
|
|
{ model: Genre, as: "genres" },
|
|
],
|
|
},
|
|
],
|
|
});
|
|
|
|
return network;
|
|
}
|
|
|
|
/**
|
|
* Creates the network or refreshes its TMDB fields. TMDB sends snake_case
|
|
* (`origin_country`, `logo_path`); the model attributes are camelCase.
|
|
* @returns {Promise<[Network, boolean]>} same shape as findOrCreate
|
|
*/
|
|
async createOrUpdateNetwork(networkData) {
|
|
const fields = {
|
|
name: networkData.name,
|
|
originCountry: networkData.origin_country || null,
|
|
logoPath: networkData.logo_path || null,
|
|
};
|
|
|
|
const [network, created] = await Network.findOrCreate({
|
|
where: { id: networkData.id },
|
|
defaults: { id: networkData.id, ...fields },
|
|
});
|
|
|
|
if (
|
|
!created &&
|
|
(network.name !== fields.name ||
|
|
network.originCountry !== fields.originCountry ||
|
|
network.logoPath !== fields.logoPath)
|
|
) {
|
|
await network.update(fields);
|
|
}
|
|
|
|
return [network, created];
|
|
}
|
|
}
|
|
|
|
module.exports = new NetworkService();
|