random changes
This commit is contained in:
1 parent
5008940c59
commit
d06a21097f
7 files changed
+27
-61
No files matched your search
@@ -46,7 +46,7 @@ Entry.belongsToMany(UserCollection, {
|
|||||||
foreignKey: 'entry_id',
|
foreignKey: 'entry_id',
|
||||||
otherKey: 'user_collection_id',
|
otherKey: 'user_collection_id',
|
||||||
onDelete: 'CASCADE',
|
onDelete: 'CASCADE',
|
||||||
as: 'userCollections',
|
as: 'collections',
|
||||||
});
|
});
|
||||||
|
|
||||||
UserCollection.belongsToMany(Entry, {
|
UserCollection.belongsToMany(Entry, {
|
||||||
@@ -86,8 +86,8 @@ EntryGenre.belongsTo(Genre, { foreignKey: 'genre_id', as: 'genre' });
|
|||||||
|
|
||||||
|
|
||||||
// * ENTRY & MEDIA - ONE TO MANY
|
// * ENTRY & MEDIA - ONE TO MANY
|
||||||
Entry.hasMany(Media, { foreignKey: 'entry_id', as: 'medias', onDelete: 'CASCADE', });
|
Entry.hasMany(Media, { foreignKey: 'entryId', as: 'medias', onDelete: 'CASCADE', });
|
||||||
Media.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
Media.belongsTo(Entry, { foreignKey: 'entryId', as: 'entry' });
|
||||||
|
|
||||||
// * ENTRY & SEASON - ONE TO MANY
|
// * ENTRY & SEASON - ONE TO MANY
|
||||||
Entry.hasMany(Season, { foreignKey: 'entry_id', as: 'seasons', onDelete: 'CASCADE', });
|
Entry.hasMany(Season, { foreignKey: 'entry_id', as: 'seasons', onDelete: 'CASCADE', });
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ UserCollectionEntry.afterDestroy(async (instance, options) => {
|
|||||||
name: sequelize.literal('name')
|
name: sequelize.literal('name')
|
||||||
}
|
}
|
||||||
|
|
||||||
// ? updating collection poster
|
|
||||||
const collectionsEntries = await UserCollectionEntry.findAll({
|
const collectionsEntries = await UserCollectionEntry.findAll({
|
||||||
where: {
|
where: {
|
||||||
user_collection_id: instance.user_collection_id
|
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
|
// ? remove the poster if the collection is empty now
|
||||||
if (collectionsEntries.length == 0) {
|
if (collectionsEntries.length == 0) {
|
||||||
updates.poster = null;
|
updates.poster = null;
|
||||||
} else {
|
} else {
|
||||||
// todo add is customPoster field
|
// ? replace poster it belonged to the removed entry
|
||||||
if (userCollection.poster_path == entry.poster_path) {
|
// if (userCollection.poster_path == entry.poster_path) {
|
||||||
updates.poster_path = collectionsEntries[0].entry.poster_path;
|
// updates.poster_path = collectionsEntries[0].entry.poster_path;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// ? updating order, only if the removed entry isn't placed at the end
|
// ? updating order, only if the removed entry isn't placed at the end
|
||||||
|
|||||||
+11
-11
@@ -6,9 +6,9 @@ const Entry = sequelize.define("entry",
|
|||||||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||||
|
|
||||||
title: { type: DataTypes.STRING(100) },
|
title: { type: DataTypes.STRING(100) },
|
||||||
original_title: { type: DataTypes.STRING(100) },
|
original_title: { type: DataTypes.STRING(100), field: 'original_title' },
|
||||||
release_date: { type: DataTypes.DATE },
|
release_date: { type: DataTypes.DATE, field: 'release_date' },
|
||||||
release_status: { type: DataTypes.STRING(50) },
|
release_status: { type: DataTypes.STRING(50), field: 'release_status' },
|
||||||
runtime: { type: DataTypes.INTEGER },
|
runtime: { type: DataTypes.INTEGER },
|
||||||
|
|
||||||
tagline: { type: DataTypes.STRING(200) },
|
tagline: { type: DataTypes.STRING(200) },
|
||||||
@@ -16,23 +16,23 @@ const Entry = sequelize.define("entry",
|
|||||||
country: { type: DataTypes.STRING(30) },
|
country: { type: DataTypes.STRING(30) },
|
||||||
|
|
||||||
certification: { type: DataTypes.INTEGER },
|
certification: { type: DataTypes.INTEGER },
|
||||||
network_studio: { type: DataTypes.STRING(40) },
|
network_studio: { type: DataTypes.STRING(40), field: 'network_studio' },
|
||||||
collection_id: { type: DataTypes.INTEGER },
|
collection_id: { type: DataTypes.INTEGER, field: 'collection_id' },
|
||||||
max_cast: { type: DataTypes.INTEGER, defaultValue: 10 },
|
max_cast: { type: DataTypes.INTEGER, field: 'max_cast', defaultValue: 10 },
|
||||||
|
|
||||||
watchlist: { type: DataTypes.BOOLEAN, defaultValue: false },
|
watchlist: { type: DataTypes.BOOLEAN, defaultValue: false },
|
||||||
favorit: { type: DataTypes.BOOLEAN, defaultValue: false },
|
favorit: { type: DataTypes.BOOLEAN, defaultValue: false },
|
||||||
hidden: { type: DataTypes.BOOLEAN, defaultValue: false },
|
hidden: { type: DataTypes.BOOLEAN, defaultValue: false },
|
||||||
note: { type: DataTypes.STRING(2000) },
|
note: { type: DataTypes.STRING(2000) },
|
||||||
|
|
||||||
is_tvseries: { type: DataTypes.BOOLEAN },
|
is_tvseries: { type: DataTypes.BOOLEAN, field: 'is_tvseries' },
|
||||||
status: { type: DataTypes.STRING(20) },
|
status: { type: DataTypes.STRING(20) },
|
||||||
|
|
||||||
poster_path: { type: DataTypes.STRING(200) },
|
poster_path: { type: DataTypes.STRING(200), field: 'poster_path' },
|
||||||
banner_path: { type: DataTypes.STRING(200) },
|
banner_path: { type: DataTypes.STRING(200), field: 'banner_path' },
|
||||||
|
|
||||||
date_first_seen: { type: DataTypes.DATEONLY },
|
date_first_seen: { type: DataTypes.DATEONLY, field: 'date_first_seen' },
|
||||||
date_last_seen: { type: DataTypes.DATEONLY },
|
date_last_seen: { type: DataTypes.DATEONLY, field: 'date_last_seen' },
|
||||||
|
|
||||||
last_fetch: { type: DataTypes.DATEONLY },
|
last_fetch: { type: DataTypes.DATEONLY },
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-39
@@ -2,8 +2,6 @@ const express = require('express');
|
|||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
const routes = require('./routes/routes.js');
|
const routes = require('./routes/routes.js');
|
||||||
const sequelize = require('./db/database.js');
|
const sequelize = require('./db/database.js');
|
||||||
const path = require('path');
|
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
@@ -14,6 +12,7 @@ const killerRouter = require('./routes/killer.routes.js');
|
|||||||
const errorHandler = require('./middleware/errorHandler');
|
const errorHandler = require('./middleware/errorHandler');
|
||||||
const { getSettings } = require('./services/settingsService.js');
|
const { getSettings } = require('./services/settingsService.js');
|
||||||
const { logToFile } = require('./services/logService.js');
|
const { logToFile } = require('./services/logService.js');
|
||||||
|
const { generatePreview } = require('./services/mediaService.js');
|
||||||
|
|
||||||
// ? variables
|
// ? variables
|
||||||
let settings = getSettings()
|
let settings = getSettings()
|
||||||
@@ -38,43 +37,6 @@ app.use((req, res, next) => {
|
|||||||
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
|
// ? other api routes
|
||||||
app.use('/api/v1', routes);
|
app.use('/api/v1', routes);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const EntrySeen = require("../models/EntrySeen");
|
|||||||
const Episode = require("../models/Episode");
|
const Episode = require("../models/Episode");
|
||||||
const EpisodeSeen = require("../models/EpisodeSeen");
|
const EpisodeSeen = require("../models/EpisodeSeen");
|
||||||
const Season = require("../models/Season");
|
const Season = require("../models/Season");
|
||||||
const { saveEntry } = require("./entryService");
|
const { saveEntry } = require("./models-services/entryService");
|
||||||
const { fetchEntryData } = require("./tmdbService");
|
const { fetchEntryData } = require("./tmdbService");
|
||||||
|
|
||||||
async function bulkImportMovies(movies) {
|
async function bulkImportMovies(movies) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// logService.js
|
// logService.js
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
const moment = require('../utils/moment');
|
||||||
|
|
||||||
// Convert fs.writeFile to a promise-based function
|
// Convert fs.writeFile to a promise-based function
|
||||||
const writeFile = util.promisify(fs.writeFile);
|
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
|
// Asynchronous function to append a message to the log file
|
||||||
async function logToFile(message) {
|
async function logToFile(message) {
|
||||||
try {
|
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) {
|
} catch (err) {
|
||||||
console.error("Failed to write to log file:", err);
|
console.error("Failed to write to log file:", err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const entryPicturesUpload = multer({
|
|||||||
multer.diskStorage({
|
multer.diskStorage({
|
||||||
destination: function (req, file, cb) {
|
destination: function (req, file, cb) {
|
||||||
let folder = 'posters';
|
let folder = 'posters';
|
||||||
if (file.fieldname == 'banner') folder = 'backdrops';
|
if (file.fieldname == 'backdrop') folder = 'backdrops';
|
||||||
if (file.fieldname == 'logo') folder = 'logos';
|
if (file.fieldname == 'logo') folder = 'logos';
|
||||||
|
|
||||||
const settings = getSettings();
|
const settings = getSettings();
|
||||||
|
|||||||
Reference in new issue
Block a user