random changes

This commit is contained in:
X4Lo committed 2024-09-10 19:07:43 +01:00
1 parent 5008940c59
commit d06a21097f
7 files changed
+27 -61

No files matched your search

+3 -3
View File
@@ -46,7 +46,7 @@ Entry.belongsToMany(UserCollection, {
foreignKey: 'entry_id',
otherKey: 'user_collection_id',
onDelete: 'CASCADE',
as: 'userCollections',
as: 'collections',
});
UserCollection.belongsToMany(Entry, {
@@ -86,8 +86,8 @@ EntryGenre.belongsTo(Genre, { foreignKey: 'genre_id', as: 'genre' });
// * ENTRY & MEDIA - ONE TO MANY
Entry.hasMany(Media, { foreignKey: 'entry_id', as: 'medias', onDelete: 'CASCADE', });
Media.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
Entry.hasMany(Media, { foreignKey: 'entryId', as: 'medias', onDelete: 'CASCADE', });
Media.belongsTo(Entry, { foreignKey: 'entryId', as: 'entry' });
// * ENTRY & SEASON - ONE TO MANY
Entry.hasMany(Season, { foreignKey: 'entry_id', as: 'seasons', onDelete: 'CASCADE', });
+5 -5
View File
@@ -81,7 +81,6 @@ UserCollectionEntry.afterDestroy(async (instance, options) => {
name: sequelize.literal('name')
}
// ? updating collection poster
const collectionsEntries = await UserCollectionEntry.findAll({
where: {
user_collection_id: instance.user_collection_id
@@ -91,14 +90,15 @@ UserCollectionEntry.afterDestroy(async (instance, options) => {
]
})
// ? updating collection poster
// ? remove the poster if the collection is empty now
if (collectionsEntries.length == 0) {
updates.poster = null;
} else {
// todo add is customPoster field
if (userCollection.poster_path == entry.poster_path) {
updates.poster_path = collectionsEntries[0].entry.poster_path;
}
// ? replace poster it belonged to the removed entry
// if (userCollection.poster_path == entry.poster_path) {
// updates.poster_path = collectionsEntries[0].entry.poster_path;
// }
}
// ? updating order, only if the removed entry isn't placed at the end
+11 -11
View File
@@ -6,9 +6,9 @@ const Entry = sequelize.define("entry",
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
title: { type: DataTypes.STRING(100) },
original_title: { type: DataTypes.STRING(100) },
release_date: { type: DataTypes.DATE },
release_status: { type: DataTypes.STRING(50) },
original_title: { type: DataTypes.STRING(100), field: 'original_title' },
release_date: { type: DataTypes.DATE, field: 'release_date' },
release_status: { type: DataTypes.STRING(50), field: 'release_status' },
runtime: { type: DataTypes.INTEGER },
tagline: { type: DataTypes.STRING(200) },
@@ -16,23 +16,23 @@ const Entry = sequelize.define("entry",
country: { type: DataTypes.STRING(30) },
certification: { type: DataTypes.INTEGER },
network_studio: { type: DataTypes.STRING(40) },
collection_id: { type: DataTypes.INTEGER },
max_cast: { type: DataTypes.INTEGER, defaultValue: 10 },
network_studio: { type: DataTypes.STRING(40), field: 'network_studio' },
collection_id: { type: DataTypes.INTEGER, field: 'collection_id' },
max_cast: { type: DataTypes.INTEGER, field: 'max_cast', defaultValue: 10 },
watchlist: { type: DataTypes.BOOLEAN, defaultValue: false },
favorit: { type: DataTypes.BOOLEAN, defaultValue: false },
hidden: { type: DataTypes.BOOLEAN, defaultValue: false },
note: { type: DataTypes.STRING(2000) },
is_tvseries: { type: DataTypes.BOOLEAN },
is_tvseries: { type: DataTypes.BOOLEAN, field: 'is_tvseries' },
status: { type: DataTypes.STRING(20) },
poster_path: { type: DataTypes.STRING(200) },
banner_path: { type: DataTypes.STRING(200) },
poster_path: { type: DataTypes.STRING(200), field: 'poster_path' },
banner_path: { type: DataTypes.STRING(200), field: 'banner_path' },
date_first_seen: { type: DataTypes.DATEONLY },
date_last_seen: { type: DataTypes.DATEONLY },
date_first_seen: { type: DataTypes.DATEONLY, field: 'date_first_seen' },
date_last_seen: { type: DataTypes.DATEONLY, field: 'date_last_seen' },
last_fetch: { type: DataTypes.DATEONLY },
}
+1 -39
View File
@@ -2,8 +2,6 @@ const express = require('express');
const bodyParser = require('body-parser');
const routes = require('./routes/routes.js');
const sequelize = require('./db/database.js');
const path = require('path');
const fs = require('fs');
const app = express();
@@ -14,6 +12,7 @@ const killerRouter = require('./routes/killer.routes.js');
const errorHandler = require('./middleware/errorHandler');
const { getSettings } = require('./services/settingsService.js');
const { logToFile } = require('./services/logService.js');
const { generatePreview } = require('./services/mediaService.js');
// ? variables
let settings = getSettings()
@@ -38,43 +37,6 @@ app.use((req, res, next) => {
next();
});
// ? Routes : media access routes
app.use('/api/v1/media/:category/:type/:file', (req, res, next) => {
const category = req.params.category;
const type = req.params.type;
const file = req.params.file;
if (!['entries', 'collections', 'franchises'].includes(category)) {
return res.status(404).send('Not Found');
}
if (!['backdrops', 'posters', 'logos', 'others'].includes(type)) {
return res.status(404).send('Not Found');
}
const settings = getSettings();
const dataPath = settings.userDataPath;
const mediaPath = path.join(dataPath, 'images', category, type);
// const mediaPath = path.join(__dirname, '..', `data/images/${category}/${type}`);
const filePath = path.join(mediaPath, file);
logToFile(filePath)
fs.access(filePath, fs.constants.F_OK, (err) => {
if (err) {
return res.status(404).send('Not Found');
}
const options = {
fallthrough: false, // ! Important: don't call next middleware if file isn't found
};
// express.static(filePath, options)(req, res, next);
// Serve the file using fs.createReadStream
const stream = fs.createReadStream(filePath);
stream.pipe(res);
});
});
// ? other api routes
app.use('/api/v1', routes);
+1 -1
View File
@@ -6,7 +6,7 @@ const EntrySeen = require("../models/EntrySeen");
const Episode = require("../models/Episode");
const EpisodeSeen = require("../models/EpisodeSeen");
const Season = require("../models/Season");
const { saveEntry } = require("./entryService");
const { saveEntry } = require("./models-services/entryService");
const { fetchEntryData } = require("./tmdbService");
async function bulkImportMovies(movies) {
+5 -1
View File
@@ -1,6 +1,7 @@
// logService.js
const fs = require('fs');
const util = require('util');
const moment = require('../utils/moment');
// Convert fs.writeFile to a promise-based function
const writeFile = util.promisify(fs.writeFile);
@@ -20,7 +21,10 @@ fs.open(logFilePath, 'a', (err, fd) => {
// Asynchronous function to append a message to the log file
async function logToFile(message) {
try {
await writeFile(logFilePath, `${message}\n`, { flag: 'a' });
const time = moment().format('YYYY-MM-DD HH:mm:ss')
const formatedMsg = `[${time}] ${message}`;
console.log(formatedMsg);
await writeFile(logFilePath, formatedMsg + '\n', { flag: 'a' });
} catch (err) {
console.error("Failed to write to log file:", err);
}
+1 -1
View File
@@ -9,7 +9,7 @@ const entryPicturesUpload = multer({
multer.diskStorage({
destination: function (req, file, cb) {
let folder = 'posters';
if (file.fieldname == 'banner') folder = 'backdrops';
if (file.fieldname == 'backdrop') folder = 'backdrops';
if (file.fieldname == 'logo') folder = 'logos';
const settings = getSettings();