- add download of episode media function
- serving of episodes/seasons files
- pulling seasons/episodes media on entry create
- maintenance for seasons/episodes media
This commit is contained in:
X4Lo committed 2025-04-01 23:53:25 +00:00
1 parent 534572775f
commit 4e20c5320b
6 files changed
+58 -31

No files matched your search

+12 -21
View File
@@ -39,7 +39,8 @@ class MaintenanceService {
'collection;poster': path.join(dataPath, 'images', 'collections', 'posters'),
'collection;backdrop': path.join(dataPath, 'images', 'collections', 'backdrops'),
'season;poster': path.join(dataPath, 'images', 'seasons', 'posters')
'season;poster': path.join(dataPath, 'images', 'seasons', 'posters'),
'episode;still': path.join(dataPath, 'images', 'episodes', 'stills')
};
let missingFiles = [];
@@ -56,7 +57,8 @@ class MaintenanceService {
let removed = {
'posters': 0,
'logos': 0,
'backdrops': 0
'backdrops': 0,
'stills': 0,
};
// if (missingFiles.length == 0)
@@ -83,20 +85,11 @@ class MaintenanceService {
// Getting the userDataPath to store the images
const dataPath = _configService.getMediaFolder();
// ? Getting the path of all media files and putting them in an array
// const allMedia = (await Media.findAll()).map(m => {
// if (m.mediaable == 'entry')
// return path.join(dataPath, 'images', 'entries', m.type + 's', m.path)
// else if (m.mediaable == 'collection')
// return path.join(dataPath, 'images', 'collections', m.type + 's', m.path)
// });
// ? Getting the name (without extention) of all media in database
const allMedia = (await Media.findAll()).map(m => {
return m.path.split('.')[0]
});
// ? Loop trough the files of the images folder and check
// ? if a file doesnt exist in the allMedia array and mark it to delete
const mediaTypeFolder = {
@@ -107,14 +100,16 @@ class MaintenanceService {
'collection;poster': path.join(dataPath, 'images', 'collections', 'posters'),
'collection;backdrop': path.join(dataPath, 'images', 'collections', 'backdrops'),
'season;poster': path.join(dataPath, 'images', 'seasons', 'posters')
'season;poster': path.join(dataPath, 'images', 'seasons', 'posters'),
'episode;still': path.join(dataPath, 'images', 'episodes', 'stills')
};
// * counter
let removed = {
'posters': 0,
'logos': 0,
'backdrops': 0
'backdrops': 0,
'stills': 0,
};
// Iterate over each media type directory and check for orphan files
@@ -127,13 +122,6 @@ class MaintenanceService {
// Check each file in the directory
for (let file of files) {
const filePath = path.join(directory, file);
// // Check if the constructed file path exists in the allMedia array
// // ? this step also takes into account preview files, by removing '_preview'
// // ? and verifying if the file path is in database
// const hasJpgFormat = allMedia.includes(filePath.replace("_preview.jpg", ".jpg"));
// const hasPngFormat = allMedia.includes(filePath.replace("_preview.jpg", ".png"));
// const hasGifFormat = allMedia.includes(filePath.replace("_preview.jpg", ".gif"));
// preparing the file name
const fileName = file.split('.')[0].replace("_preview", "");
@@ -142,7 +130,10 @@ class MaintenanceService {
// if the file isn't in database even on other extentions then delete it
if (!isInDatabase) {
removed[folderType.split(';')[1] + 's']++; // Increment the count of removed files
if (!dry) await fsPromises.unlink(filePath);
if (!dry) {
const b = path.join(directory, file);
await fsPromises.unlink(filePath);
}
}
}
} catch (err) {