Normalize to double quotes across all files with Prettier

This commit is contained in:
X4Lo committed 2026-06-21 22:28:08 +01:00
1 parent 73bff72cec
commit a5659cf4c8
190 files changed
+9523 -8859

No files matched your search

+98 -42
View File
@@ -1,10 +1,10 @@
const path = require('path');
const fs = require('fs');
const { default: axios } = require('axios');
const { v4: uuidv4 } = require('uuid');
const path = require("path");
const fs = require("fs");
const { default: axios } = require("axios");
const { v4: uuidv4 } = require("uuid");
const { logToFile } = require("./logService");
const configService = require('./configService');
const configService = require("./configService");
const _configService = configService;
@@ -27,24 +27,52 @@ class MediaDownloaderService {
const dataPath = _configService.getSettings().userDataPath;
const hasPoster = collection.medias && collection.medias.filter((m) => m.type == 'poster').length != 0;
const hasPoster =
collection.medias &&
collection.medias.filter((m) => m.type == "poster").length != 0;
if (collection.posterPath && !hasPoster) {
const postersDir = path.join(dataPath, 'images', 'collections', 'posters')
this.scheduleDownloads({ file_path: collection.posterPath }, 'poster', postersDir, downloadTasks, downloadedImages);
const postersDir = path.join(
dataPath,
"images",
"collections",
"posters",
);
this.scheduleDownloads(
{ file_path: collection.posterPath },
"poster",
postersDir,
downloadTasks,
downloadedImages,
);
}
const hasBackdrop = collection.medias && collection.medias.filter((m) => m.type == 'backdrop').length != 0;
const hasBackdrop =
collection.medias &&
collection.medias.filter((m) => m.type == "backdrop").length != 0;
if (collection.backdropPath && !hasBackdrop) {
const backdropsDir = path.join(dataPath, 'images', 'collections', 'backdrops')
this.scheduleDownloads({ file_path: collection.backdropPath }, 'backdrop', backdropsDir, downloadTasks, downloadedImages);
const backdropsDir = path.join(
dataPath,
"images",
"collections",
"backdrops",
);
this.scheduleDownloads(
{ file_path: collection.backdropPath },
"backdrop",
backdropsDir,
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;
}
@@ -61,32 +89,56 @@ class MediaDownloaderService {
const dataPath = _configService.getSettings().userDataPath;
// Check if person already has a profile image
const hasProfile = person.medias && person.medias.filter((m) => m.type === 'profile').length !== 0;
const hasProfile =
person.medias &&
person.medias.filter((m) => m.type === "profile").length !== 0;
if (person.profile_path && !hasProfile) {
const profilesDir = path.join(dataPath, 'images', 'peoples', 'profiles');
this.scheduleDownloads({ file_path: person.profile_path }, 'profile', profilesDir, downloadTasks, downloadedImages);
const profilesDir = path.join(dataPath, "images", "peoples", "profiles");
this.scheduleDownloads(
{ file_path: person.profile_path },
"profile",
profilesDir,
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;
}
// Utility to find the preferred media (English if available, otherwise the first one)
findPreferredMedia(mediaArray, preferredLanguage = 'en') {
return mediaArray.find(media => media.iso_639_1 === preferredLanguage && !media.file_path.includes('.svg')) || mediaArray.find(media => !media.file_path.includes('.svg')) || mediaArray[0];
findPreferredMedia(mediaArray, preferredLanguage = "en") {
return (
mediaArray.find(
(media) =>
media.iso_639_1 === preferredLanguage &&
!media.file_path.includes(".svg"),
) ||
mediaArray.find((media) => !media.file_path.includes(".svg")) ||
mediaArray[0]
);
}
// Adjusted scheduleDownloads to accept local arrays
scheduleDownloads(media, mediaType, mediaDir, downloadTasks, downloadedImages) {
scheduleDownloads(
media,
mediaType,
mediaDir,
downloadTasks,
downloadedImages,
) {
const uniqueFilename = uuidv4();
const extension = media.file_path.split('.').pop();
const extension = media.file_path.split(".").pop();
const url = `https://image.tmdb.org/t/p/original${media.file_path}`;
const filename = `${uniqueFilename}.${extension}`;
@@ -96,42 +148,46 @@ class MediaDownloaderService {
downloadTasks.push(
this.downloadImage(url, downloadPath)
.then(() => {
logToFile(`Media Service | downloaded: ${mediaType}, path:${downloadPath} url:${url}`)
downloadedImages.push({ type: mediaType, path: filename })
})
.catch(err => {
logToFile(`Media Service | failed to download: ${mediaType}, path:${downloadPath} url:${url}`)
logToFile(err)
console.error(`Error downloading ${mediaType}:`, err)
logToFile(
`Media Service | downloaded: ${mediaType}, path:${downloadPath} url:${url}`,
);
downloadedImages.push({ type: mediaType, path: filename });
})
.catch((err) => {
logToFile(
`Media Service | failed to download: ${mediaType}, path:${downloadPath} url:${url}`,
);
logToFile(err);
console.error(`Error downloading ${mediaType}:`, err);
}),
);
}
async downloadImage(url, filePath) {
const response = await axios({
url: url,
method: 'GET',
responseType: 'stream'
method: "GET",
responseType: "stream",
});
const writer = fs.createWriteStream(filePath);
response.data.pipe(writer);
return new Promise((resolve, reject) => {
writer.on('finish', resolve);
writer.on('error', reject);
writer.on("finish", resolve);
writer.on("error", reject);
});
}
async downloadFile(url) {
const response = await axios({
url: url,
method: 'GET',
responseType: 'stream'
method: "GET",
responseType: "stream",
});
return response;
}
}
module.exports = new MediaDownloaderService();
module.exports = new MediaDownloaderService();