implemented images maintenance, services + component
This commit is contained in:
1 parent
ba96f540ca
commit
34766ba8e9
13 files changed
+448
-4
No files matched your search
@@ -125,6 +125,8 @@ async function saveEntry(data) {
|
||||
// + end of: seasons & episodes for tv series
|
||||
|
||||
// ? cast
|
||||
|
||||
|
||||
// ? images
|
||||
const downloadedImages = await getEntryMedia(data.id, is_tvseries);
|
||||
console.log(`entry service, downloaded images: `, downloadedImages)
|
||||
@@ -490,9 +492,46 @@ async function refrechEntry(entryId) {
|
||||
// if (!oldEntry.casts || oldEntry.casts.length == 0 || oldEntry.casts.length < oldEntry.max_cast) {
|
||||
// }
|
||||
|
||||
// * Media
|
||||
// * Only fetch if a Poster, Backdrop or a Logo is missing
|
||||
// * Updating Media : Only fetch if a Poster, Backdrop or a Logo is missing
|
||||
let downloadedImages;
|
||||
if (oldEntry.medias.length == 0) {
|
||||
// ? if no media is available, directly get all
|
||||
downloadedImages = await getEntryMedia(data.id, oldEntry.is_tvseries);
|
||||
} else {
|
||||
// ? only get missing media types
|
||||
let availableMedia = {
|
||||
'posters': 0,
|
||||
'logos': 0,
|
||||
'backdrops': 0
|
||||
};
|
||||
|
||||
// ? count media by type
|
||||
for (let i = 0; i < oldEntry.medias.length; i++) {
|
||||
availableMedia[oldEntry.medias[i].type] += 1;
|
||||
}
|
||||
|
||||
// ? if the count of a media type == 0, the add the type to mediaToGet
|
||||
let mediaToGet = [];
|
||||
availableMedia.forEach(({ type, count }) => {
|
||||
if (count == 0) mediaToGet.push(type);
|
||||
});
|
||||
|
||||
if (mediaToGet.length != 0) {
|
||||
downloadedImages = await getEntryMedia(data.id, oldEntry.is_tvseries, mediaToGet);
|
||||
}
|
||||
}
|
||||
|
||||
if (downloadedImages) {
|
||||
for (const image of downloadedImages) {
|
||||
await Media.create({
|
||||
entry_id: oldEntry.id,
|
||||
type: image.type,
|
||||
path: image.path,
|
||||
is_local: true,
|
||||
is_selected: true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// + end of: refrech logic
|
||||
|
||||
|
||||
Reference in new issue
Block a user