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,19 +1,18 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
const Entry = require('../models/Entry');
|
||||
const Media = require('../models/Media');
|
||||
const Collection = require('../models/Collection');
|
||||
const Entry = require("../models/Entry");
|
||||
const Media = require("../models/Media");
|
||||
const Collection = require("../models/Collection");
|
||||
|
||||
const configService = require('../services/configService.js');
|
||||
const { logToFile } = require('../services/logService');
|
||||
const mediaOptimizerService = require('../services/mediaOptimizerService.js');
|
||||
const asyncWrapper = require('../utils/asyncWrapper');
|
||||
const configService = require("../services/configService.js");
|
||||
const { logToFile } = require("../services/logService");
|
||||
const mediaOptimizerService = require("../services/mediaOptimizerService.js");
|
||||
const asyncWrapper = require("../utils/asyncWrapper");
|
||||
|
||||
const _mediaOptimizerService = mediaOptimizerService;
|
||||
|
||||
class MediaController {
|
||||
|
||||
constructor() {
|
||||
if (!MediaController.instance) {
|
||||
MediaController.instance = this;
|
||||
@@ -21,7 +20,6 @@ class MediaController {
|
||||
return MediaController.instance;
|
||||
}
|
||||
getMedias = asyncWrapper(async (req, res) => {
|
||||
|
||||
const allCustomMedia = await Media.findAll({
|
||||
where: {
|
||||
isCustom: true,
|
||||
@@ -29,15 +27,15 @@ class MediaController {
|
||||
include: [
|
||||
{
|
||||
model: Entry,
|
||||
as: 'entry',
|
||||
required: false // This ensures a LEFT OUTER JOIN
|
||||
as: "entry",
|
||||
required: false, // This ensures a LEFT OUTER JOIN
|
||||
},
|
||||
{
|
||||
model: Collection,
|
||||
as: 'collection',
|
||||
required: false // This ensures a LEFT OUTER JOIN
|
||||
}
|
||||
]
|
||||
as: "collection",
|
||||
required: false, // This ensures a LEFT OUTER JOIN
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
res.status(200).json(allCustomMedia);
|
||||
@@ -46,37 +44,57 @@ class MediaController {
|
||||
getMedia(req, res, next) {
|
||||
const { category, type, size, fileName } = req.params;
|
||||
|
||||
if (!['entries', 'collections', 'franchises', 'seasons', 'episodes', 'peoples'].includes(category)) {
|
||||
return res.status(404).send('Category Not Found');
|
||||
if (
|
||||
![
|
||||
"entries",
|
||||
"collections",
|
||||
"franchises",
|
||||
"seasons",
|
||||
"episodes",
|
||||
"peoples",
|
||||
].includes(category)
|
||||
) {
|
||||
return res.status(404).send("Category Not Found");
|
||||
}
|
||||
|
||||
if (!['backdrops', 'posters', 'logos', 'stills', 'profiles', 'others'].includes(type)) {
|
||||
return res.status(404).send('Type Not Found');
|
||||
if (
|
||||
![
|
||||
"backdrops",
|
||||
"posters",
|
||||
"logos",
|
||||
"stills",
|
||||
"profiles",
|
||||
"others",
|
||||
].includes(type)
|
||||
) {
|
||||
return res.status(404).send("Type Not Found");
|
||||
}
|
||||
|
||||
const settings = configService.getSettings();
|
||||
const dataPath = settings.userDataPath;
|
||||
|
||||
const mediaPath = path.join(dataPath, 'images', category, type);
|
||||
const mediaPath = path.join(dataPath, "images", category, type);
|
||||
// const mediaPath = path.join(__dirname, '..', `data/images/${category}/${type}`);
|
||||
|
||||
// * preparing to serve the preview
|
||||
// ? basicaly im checking if the file requested is a preview file
|
||||
// ? if so I make sure to change the extention to '_preview.jpg' (bcs all previews are jpg)
|
||||
let filePath = path.join(mediaPath, fileName);
|
||||
if (size == 'preview') {
|
||||
const previewFileName = fileName.split('.')[0] + (type == 'logos' ? '_preview.png' : '_preview.jpg')
|
||||
if (size == "preview") {
|
||||
const previewFileName =
|
||||
fileName.split(".")[0] +
|
||||
(type == "logos" ? "_preview.png" : "_preview.jpg");
|
||||
filePath = path.join(mediaPath, previewFileName);
|
||||
}
|
||||
|
||||
fs.access(filePath, fs.constants.F_OK, (err) => {
|
||||
// * generating a preview if it doesn't exist
|
||||
// ? then if the preview doesn't exist I generate a new one
|
||||
// ? by taking the file name and removing '_preview' from it to get
|
||||
// ? by taking the file name and removing '_preview' from it to get
|
||||
// ? the original file name, and starting from that I join it to the media path
|
||||
// ? and generate a preview file, but still return 202 http code since the file
|
||||
// ? is still generating
|
||||
if (err && size == 'preview') {
|
||||
if (err && size == "preview") {
|
||||
// const originalPath = path.join(mediaPath, fileName);
|
||||
// const previewFileName = fileName.split('.')[0] + '_preview.jpg'
|
||||
// const previewPath = path.join(mediaPath, previewFileName);
|
||||
@@ -85,14 +103,17 @@ class MediaController {
|
||||
// if (type == 'backdrops') previewWidth = 780;
|
||||
// if (type == 'logos') previewWidth = 300;
|
||||
|
||||
_mediaOptimizerService.doGeneratePreview(category, type, fileName).then((result) => {
|
||||
const stream = fs.createReadStream(filePath);
|
||||
stream.pipe(res);
|
||||
logToFile(`Media Route | Generated Preview`);
|
||||
}).catch((err) => {
|
||||
logToFile(`Media Route | Error Generating Preview`);
|
||||
logToFile(err);
|
||||
});
|
||||
_mediaOptimizerService
|
||||
.doGeneratePreview(category, type, fileName)
|
||||
.then((result) => {
|
||||
const stream = fs.createReadStream(filePath);
|
||||
stream.pipe(res);
|
||||
logToFile(`Media Route | Generated Preview`);
|
||||
})
|
||||
.catch((err) => {
|
||||
logToFile(`Media Route | Error Generating Preview`);
|
||||
logToFile(err);
|
||||
});
|
||||
// const stream = fs.createReadStream(filePath);
|
||||
// stream.pipe(res);
|
||||
// return res.status(202).send('Preview is still generating. Please try again later.');
|
||||
@@ -108,7 +129,6 @@ class MediaController {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = new MediaController();
|
||||
Reference in new issue
Block a user