Major rework of media handelling, and collections
This commit is contained in:
1 parent
b42e055691
commit
f7cb2bed53
37 files changed
+1120
-411
No files matched your search
@@ -6,7 +6,7 @@ const { fetchEntryData, fetchCollectionData } = require('../services/tmdbService
|
||||
const { saveEntry, refrechEntry, SyncSeriesData } = require('../services/models-services/entryService');
|
||||
const { bulkImportMovies, bulkImportTmdb, bulkImportEpisodes } = require('../services/importerService');
|
||||
const { entryPicturesUpload } = require('../services/mutlerStorageLocations');
|
||||
const { generatePreview } = require('../services/mediaService');
|
||||
const { generatePreview, doGeneratePreview } = require('../services/mediaService');
|
||||
|
||||
const { Sequelize } = require('sequelize');
|
||||
const Entry = require('../models/Entry');
|
||||
@@ -18,6 +18,8 @@ const Season = require('../models/Season');
|
||||
const Media = require('../models/Media');
|
||||
const Episode = require('../models/Episode');
|
||||
const UserCollection = require('../models/Collection');
|
||||
const { upsertOfficialCollection } = require('../services/models-services/collectionService');
|
||||
const { logToFile } = require('../services/logService');
|
||||
|
||||
// ! /entries
|
||||
// * GET - ALL ENTRIES
|
||||
@@ -77,7 +79,12 @@ entryRouter.get('/:id', async (req, res) => {
|
||||
{ model: EntrySeen, as: 'entrySeen' },
|
||||
{ model: Season, as: 'seasons' },
|
||||
{ model: Media, as: 'medias' },
|
||||
{ model: UserCollection, as: 'collections' },
|
||||
{
|
||||
model: UserCollection, as: 'collections',
|
||||
include: [
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
},
|
||||
{
|
||||
model: Genre,
|
||||
as: 'genres',
|
||||
@@ -155,37 +162,7 @@ entryRouter.post('/', async (req, res) => {
|
||||
const entry = await saveEntry(entryData);
|
||||
|
||||
if (entryData.belongs_to_collection) {
|
||||
let collectionData = entryData.belongs_to_collection;
|
||||
|
||||
const [oldCollection, createdCollection] = await UserCollection.findOrCreate({
|
||||
where: { tmdbId: collectionData.id },
|
||||
defaults: {
|
||||
name: collectionData.name,
|
||||
posterPath: collectionData.poster_path,
|
||||
backdropPath: collectionData.backdrop_path,
|
||||
}
|
||||
});
|
||||
|
||||
let userCollection = oldCollection || createdCollection;
|
||||
if (userCollection) {
|
||||
collectionData = await fetchCollectionData(collectionData.id);
|
||||
const partIds = collectionData.parts.map(part => part.id);
|
||||
|
||||
const entries = await Entry.findAll({
|
||||
include: [{
|
||||
model: EntryId,
|
||||
as: 'entryId',
|
||||
where: {
|
||||
tmdb_id: {
|
||||
[Sequelize.Op.in]: partIds
|
||||
}
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
||||
await userCollection.setEntries(entries);
|
||||
await userCollection.update({ description: collectionData.overview })
|
||||
}
|
||||
upsertOfficialCollection(entryData.belongs_to_collection.id);
|
||||
}
|
||||
|
||||
res.status(201).json(entry);
|
||||
@@ -285,7 +262,7 @@ entryRouter.put('/:id', async (req, res) => {
|
||||
});
|
||||
|
||||
// * GET - REQUEST ENTRY REFRECH
|
||||
entryRouter.get('/:id/refrech', async (req, res, next) => {
|
||||
entryRouter.get('/:id/refresh', async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
try {
|
||||
@@ -382,15 +359,25 @@ entryRouter.post('/:id/media', upload, async (req, res) => {
|
||||
});
|
||||
|
||||
// ? generating low resolution preview
|
||||
const fileNameWithoutExt = file.filename.split('.')[0];
|
||||
const originalPath = file.path;
|
||||
// const fileNameWithoutExt = file.filename.split('.')[0];
|
||||
// const originalPath = file.path;
|
||||
|
||||
let previewWidth = 342; // ? poster preview width
|
||||
if (fileType == 'backdrop') previewWidth = 780;
|
||||
if (fileType == 'logo') previewWidth = 300;
|
||||
// let previewWidth = 342; // ? poster preview width
|
||||
// if (fileType == 'backdrop') previewWidth = 780;
|
||||
// if (fileType == 'logo') previewWidth = 300;
|
||||
|
||||
const previewPath = path.join(file.destination, `${fileNameWithoutExt}_preview.jpg`);
|
||||
generatePreview(originalPath, previewPath, previewWidth);
|
||||
// const previewPath = path.join(file.destination, `${fileNameWithoutExt}_preview.jpg`);
|
||||
// generatePreview(originalPath, previewPath, previewWidth);
|
||||
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);
|
||||
}
|
||||
@@ -417,7 +404,7 @@ entryRouter.put('/:entryId/media/:mediaId', upload, async (req, res) => {
|
||||
{ isSelected: false },
|
||||
{
|
||||
where: {
|
||||
entryId: entryId,
|
||||
mediaableId: entryId,
|
||||
type: media.type
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user