Add homepage-integration API endpoint
New GET /api/v1/homepage-integration endpoint exposes library stats (totalEntries, library, libraryMovies, librarySeries, watchlist, watchlistMovies, watchlistSeries, collections, favorits).
This commit is contained in:
1 parent
ec9498cac0
commit
63aca7e7b8
4 files changed
+106
-34
No files matched your search
@@ -0,0 +1,62 @@
|
||||
const Entry = require("../models/Entry");
|
||||
const Collection = require("../models/Collection");
|
||||
const { Op } = require("sequelize");
|
||||
|
||||
class HomepageIntegrationController {
|
||||
constructor() {
|
||||
if (!HomepageIntegrationController.instance) {
|
||||
HomepageIntegrationController.instance = this;
|
||||
}
|
||||
return HomepageIntegrationController.instance;
|
||||
}
|
||||
|
||||
async getStats(req, res) {
|
||||
try {
|
||||
const notSeries = { is_tvseries: { [Op.or]: [false, null] } };
|
||||
const isSeries = { is_tvseries: true };
|
||||
|
||||
const [
|
||||
totalEntries,
|
||||
library,
|
||||
libraryMovies,
|
||||
librarySeries,
|
||||
watchlist,
|
||||
watchlistMovies,
|
||||
watchlistSeries,
|
||||
collections,
|
||||
favorits,
|
||||
] = await Promise.all([
|
||||
Entry.count(),
|
||||
Entry.count({ where: { watchlist: { [Op.or]: [false, null] } } }),
|
||||
Entry.count({
|
||||
where: { watchlist: { [Op.or]: [false, null] }, ...notSeries },
|
||||
}),
|
||||
Entry.count({
|
||||
where: { watchlist: { [Op.or]: [false, null] }, ...isSeries },
|
||||
}),
|
||||
Entry.count({ where: { watchlist: true } }),
|
||||
Entry.count({ where: { watchlist: true, ...notSeries } }),
|
||||
Entry.count({ where: { watchlist: true, ...isSeries } }),
|
||||
Collection.count(),
|
||||
Entry.count({ where: { favorit: true } }),
|
||||
]);
|
||||
|
||||
return res.status(200).json({
|
||||
totalEntries,
|
||||
library,
|
||||
libraryMovies,
|
||||
librarySeries,
|
||||
watchlist,
|
||||
watchlistMovies,
|
||||
watchlistSeries,
|
||||
collections,
|
||||
favorits,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Homepage integration error:", error);
|
||||
return res.status(500).json({ error: "Failed to fetch library stats" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new HomepageIntegrationController();
|
||||
Reference in new issue
Block a user