Normalize to double quotes across all files with Prettier
This commit is contained in:
1 parent
73bff72cec
commit
a5659cf4c8
190 files changed
+9523
-8859
No files matched your search
@@ -1,5 +1,5 @@
|
||||
const path = require('path');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const path = require("path");
|
||||
const { v4: uuidv4 } = require("uuid");
|
||||
|
||||
const Entry = require("../models/Entry");
|
||||
|
||||
@@ -11,9 +11,9 @@ const tmdbService = require("./tmdbService");
|
||||
const mediaService = require("./mediaService");
|
||||
const mediaDownloaderService = require("./mediaDownloaderService");
|
||||
const mediaOptimizerService = require("./mediaOptimizerService");
|
||||
const Season = require('../models/Season');
|
||||
const storageService = require('./storageService');
|
||||
const Media = require('../models/Media');
|
||||
const Season = require("../models/Season");
|
||||
const storageService = require("./storageService");
|
||||
const Media = require("../models/Media");
|
||||
|
||||
const _configService = configService;
|
||||
const _mediaService = mediaService;
|
||||
@@ -23,7 +23,6 @@ const _mediaDownloaderService = mediaDownloaderService;
|
||||
const _storageService = storageService;
|
||||
|
||||
class MediaManager {
|
||||
|
||||
constructor() {
|
||||
if (!MediaManager.instance) {
|
||||
MediaManager.instance = this;
|
||||
@@ -32,7 +31,6 @@ class MediaManager {
|
||||
}
|
||||
|
||||
async saveMedia(entryId, files) {
|
||||
|
||||
if (!files) {
|
||||
throw new BadRequestError("No media uploaded");
|
||||
}
|
||||
@@ -42,7 +40,9 @@ class MediaManager {
|
||||
throw new NotFoundError("Entry not found");
|
||||
}
|
||||
|
||||
const fileType = ['poster', 'backdrop', 'logo'].find(type => req.files[type]);
|
||||
const fileType = ["poster", "backdrop", "logo"].find(
|
||||
(type) => req.files[type],
|
||||
);
|
||||
|
||||
if (!fileType) {
|
||||
throw new BadRequestError("Invalid media type");
|
||||
@@ -51,31 +51,38 @@ class MediaManager {
|
||||
// * 1 - save the media into database
|
||||
const file = req.files[fileType][0];
|
||||
const createdMedia = await _mediaService.createMedia({
|
||||
mediaable: 'entry',
|
||||
mediaable: "entry",
|
||||
mediaableId: id,
|
||||
type: fileType,
|
||||
path: file.filename,
|
||||
isLocal: true,
|
||||
isSelected: false,
|
||||
isCustom: true
|
||||
isCustom: true,
|
||||
});
|
||||
|
||||
// * 2 - generating low resolution preview
|
||||
_mediaOptimizerService.generatePreviewFiles('entries', fileType + 's', file.filename).then((result) => {
|
||||
const stream = fs.createReadStream(filePath);
|
||||
stream.pipe(res);
|
||||
_mediaOptimizerService
|
||||
.generatePreviewFiles("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);
|
||||
});
|
||||
const msg = `Media Route | Generated Entry Preview`;
|
||||
logToFile(msg);
|
||||
})
|
||||
.catch((err) => {
|
||||
const msg = `Media Route | Error Generating Entry Preview`;
|
||||
logToFile(msg);
|
||||
});
|
||||
|
||||
return createdMedia;
|
||||
}
|
||||
|
||||
async getEntryMedia(tmdb_id, is_tvserie, includes = ['posters', 'logos', 'backdrops']) {
|
||||
async getEntryMedia(
|
||||
tmdb_id,
|
||||
is_tvserie,
|
||||
includes = ["posters", "logos", "backdrops"],
|
||||
) {
|
||||
// Fetching entry media
|
||||
const mediaData = await _tmdbService.fetchEntryMedia(tmdb_id, is_tvserie);
|
||||
if (!mediaData) {
|
||||
@@ -93,28 +100,44 @@ class MediaManager {
|
||||
|
||||
// Handling different media types
|
||||
const mediaTypes = [
|
||||
{ type: 'posters', dir: path.join(dataPath, 'images', 'entries', 'posters') },
|
||||
{ type: 'logos', dir: path.join(dataPath, 'images', 'entries', 'logos') },
|
||||
{ type: 'backdrops', dir: path.join(dataPath, 'images', 'entries', 'backdrops') }
|
||||
{
|
||||
type: "posters",
|
||||
dir: path.join(dataPath, "images", "entries", "posters"),
|
||||
},
|
||||
{ type: "logos", dir: path.join(dataPath, "images", "entries", "logos") },
|
||||
{
|
||||
type: "backdrops",
|
||||
dir: path.join(dataPath, "images", "entries", "backdrops"),
|
||||
},
|
||||
];
|
||||
|
||||
mediaTypes.forEach(({ type, dir }) => {
|
||||
if (!includes.includes(type)) return; // ? the media type is not requested
|
||||
|
||||
if (mediaData[type] && mediaData[type].length) {
|
||||
const selectedMedia = _mediaDownloaderService.findPreferredMedia(mediaData[type]);
|
||||
const selectedMedia = _mediaDownloaderService.findPreferredMedia(
|
||||
mediaData[type],
|
||||
);
|
||||
if (selectedMedia) {
|
||||
_mediaDownloaderService.scheduleDownloads(selectedMedia, type.slice(0, -1), dir, downloadTasks, downloadedImages);
|
||||
_mediaDownloaderService.scheduleDownloads(
|
||||
selectedMedia,
|
||||
type.slice(0, -1),
|
||||
dir,
|
||||
downloadTasks,
|
||||
downloadedImages,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Wait for all downloads to complete
|
||||
await Promise.all(downloadTasks).then(() => {
|
||||
console.log('Downloaded images:', downloadedImages);
|
||||
}).catch(err => {
|
||||
console.error('Error downloading entry images:', err);
|
||||
});
|
||||
await Promise.all(downloadTasks)
|
||||
.then(() => {
|
||||
console.log("Downloaded images:", downloadedImages);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error downloading entry images:", err);
|
||||
});
|
||||
|
||||
return downloadedImages;
|
||||
}
|
||||
@@ -125,23 +148,32 @@ class MediaManager {
|
||||
const file = await _mediaDownloaderService.downloadFile(url);
|
||||
|
||||
const uniqueFilename = uuidv4();
|
||||
const extension = season.poster_path.split('.').pop();
|
||||
const extension = season.poster_path.split(".").pop();
|
||||
const filename = `${uniqueFilename}.${extension}`;
|
||||
|
||||
const dataPath = _configService.getSettings().userDataPath;
|
||||
const fullFilePath = path.join(dataPath, 'images', 'seasons', 'posters', filename)
|
||||
const fullFilePath = path.join(
|
||||
dataPath,
|
||||
"images",
|
||||
"seasons",
|
||||
"posters",
|
||||
filename,
|
||||
);
|
||||
|
||||
_storageService.storeFile(file, fullFilePath).then(async () => {
|
||||
await Media.create({
|
||||
mediaable: 'season',
|
||||
mediaableId: season.id,
|
||||
type: 'poster',
|
||||
path: filename,
|
||||
isLocal: true,
|
||||
isSelected: true
|
||||
});
|
||||
console.log(`File created for season: ${filename}`);
|
||||
}).catch();
|
||||
_storageService
|
||||
.storeFile(file, fullFilePath)
|
||||
.then(async () => {
|
||||
await Media.create({
|
||||
mediaable: "season",
|
||||
mediaableId: season.id,
|
||||
type: "poster",
|
||||
path: filename,
|
||||
isLocal: true,
|
||||
isSelected: true,
|
||||
});
|
||||
console.log(`File created for season: ${filename}`);
|
||||
})
|
||||
.catch();
|
||||
}
|
||||
|
||||
async getEpisodenMedia(episode) {
|
||||
@@ -150,25 +182,33 @@ class MediaManager {
|
||||
const file = await _mediaDownloaderService.downloadFile(url);
|
||||
|
||||
const uniqueFilename = uuidv4();
|
||||
const extension = episode.still_path.split('.').pop();
|
||||
const extension = episode.still_path.split(".").pop();
|
||||
const filename = `${uniqueFilename}.${extension}`;
|
||||
|
||||
const dataPath = _configService.getSettings().userDataPath;
|
||||
const fullFilePath = path.join(dataPath, 'images', 'episodes', 'stills', filename)
|
||||
const fullFilePath = path.join(
|
||||
dataPath,
|
||||
"images",
|
||||
"episodes",
|
||||
"stills",
|
||||
filename,
|
||||
);
|
||||
|
||||
_storageService.storeFile(file, fullFilePath).then(async () => {
|
||||
await Media.create({
|
||||
mediaable: 'episode',
|
||||
mediaableId: episode.id,
|
||||
type: 'still',
|
||||
path: filename,
|
||||
isLocal: true,
|
||||
isSelected: true
|
||||
});
|
||||
console.log(`File created for episode: ${filename}`);
|
||||
}).catch();
|
||||
_storageService
|
||||
.storeFile(file, fullFilePath)
|
||||
.then(async () => {
|
||||
await Media.create({
|
||||
mediaable: "episode",
|
||||
mediaableId: episode.id,
|
||||
type: "still",
|
||||
path: filename,
|
||||
isLocal: true,
|
||||
isSelected: true,
|
||||
});
|
||||
console.log(`File created for episode: ${filename}`);
|
||||
})
|
||||
.catch();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = new MediaManager();
|
||||
Reference in new issue
Block a user