chore(*): use prettier for formatting
This commit is contained in:
parent
6c659fe1d0
commit
029caaaa9e
73 changed files with 1390 additions and 794 deletions
|
@ -7,17 +7,22 @@ import { loadConfig } from './config.js';
|
|||
import { sanitizeMediaString } from './sanitize.js';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const downloadImage = (url, dest) => new Promise((resolve, reject) => {
|
||||
const file = fs.createWriteStream(dest);
|
||||
const downloadImage = (url, dest) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const file = fs.createWriteStream(dest);
|
||||
|
||||
https.get(url, response => {
|
||||
if (response.statusCode !== 200) return reject(new Error(`Failed to download. Status: ${response.statusCode}`));
|
||||
https
|
||||
.get(url, (response) => {
|
||||
if (response.statusCode !== 200)
|
||||
return reject(new Error(`Failed to download. Status: ${response.statusCode}`));
|
||||
|
||||
response.pipe(file);
|
||||
file.on('finish', () => file.close(resolve));
|
||||
}).on('error', reject);
|
||||
});
|
||||
const isValidTMDBUrl = (val) => /^https:\/\/image\.tmdb\.org\/t\/p\//.test(val) || '❌ Must be a valid TMDB image url';
|
||||
response.pipe(file);
|
||||
file.on('finish', () => file.close(resolve));
|
||||
})
|
||||
.on('error', reject);
|
||||
});
|
||||
const isValidTMDBUrl = (val) =>
|
||||
/^https:\/\/image\.tmdb\.org\/t\/p\//.test(val) || '❌ Must be a valid TMDB image url';
|
||||
const overwriteImageDownloadPrompt = async (url, finalPath, fileName) => {
|
||||
await fs.ensureDir(path.dirname(finalPath));
|
||||
|
||||
|
@ -60,25 +65,30 @@ export const downloadWatchingImages = async () => {
|
|||
return;
|
||||
}
|
||||
|
||||
const { posterUrl, backdropUrl } = await inquirer.prompt([{
|
||||
name: 'posterUrl',
|
||||
message: 'Enter the poster url:',
|
||||
validate: (val) => {
|
||||
if (!val) return true;
|
||||
const { posterUrl, backdropUrl } = await inquirer.prompt([
|
||||
{
|
||||
name: 'posterUrl',
|
||||
message: 'Enter the poster url:',
|
||||
validate: (val) => {
|
||||
if (!val) return true;
|
||||
|
||||
return isValidTMDBUrl(val);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'backdropUrl',
|
||||
message: 'Enter the backdrop url:',
|
||||
validate: (val) => {
|
||||
if (!val) return true;
|
||||
return isValidTMDBUrl(val);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'backdropUrl',
|
||||
message: 'Enter the backdrop url:',
|
||||
validate: (val) => {
|
||||
if (!val) return true;
|
||||
|
||||
return isValidTMDBUrl(val);
|
||||
return isValidTMDBUrl(val);
|
||||
}
|
||||
}
|
||||
}]);
|
||||
const types = [{ type: 'poster', url: posterUrl }, { type: 'backdrop', url: backdropUrl }];
|
||||
]);
|
||||
const types = [
|
||||
{ type: 'poster', url: posterUrl },
|
||||
{ type: 'backdrop', url: backdropUrl }
|
||||
];
|
||||
|
||||
for (const { type, url } of types) {
|
||||
if (!url) continue;
|
||||
|
@ -98,7 +108,7 @@ export const downloadWatchingImages = async () => {
|
|||
|
||||
await overwriteImageDownloadPrompt(url, finalPath, fileName);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const downloadArtistImage = async () => {
|
||||
const config = await loadConfig();
|
||||
|
@ -134,7 +144,7 @@ export const downloadArtistImage = async () => {
|
|||
const finalPath = path.join(targetDir, fileName);
|
||||
|
||||
await overwriteImageDownloadPrompt(imageUrl, finalPath, fileName);
|
||||
}
|
||||
};
|
||||
|
||||
export const downloadAlbumImage = async () => {
|
||||
const config = await loadConfig();
|
||||
|
@ -190,7 +200,8 @@ export const downloadBookImage = async () => {
|
|||
const { isbn } = await inquirer.prompt({
|
||||
name: 'isbn',
|
||||
message: 'Enter the ISBN (no spaces):',
|
||||
validate: (val) => /^[a-zA-Z0-9-]+$/.test(val) || 'ISBN must contain only letters, numbers, or hyphens'
|
||||
validate: (val) =>
|
||||
/^[a-zA-Z0-9-]+$/.test(val) || 'ISBN must contain only letters, numbers, or hyphens'
|
||||
});
|
||||
const { bookTitle } = await inquirer.prompt({
|
||||
name: 'bookTitle',
|
||||
|
@ -223,8 +234,7 @@ export const downloadBookImage = async () => {
|
|||
const finalPath = path.join(targetDir, fileName);
|
||||
|
||||
await overwriteImageDownloadPrompt(imageUrl, finalPath, fileName);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export const downloadAsset = async () => {
|
||||
const { type } = await inquirer.prompt({
|
||||
|
@ -243,4 +253,4 @@ export const downloadAsset = async () => {
|
|||
} else {
|
||||
await downloadWatchingImages();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue