fix(cli): more consistent labeling in movie/show download prompt
This commit is contained in:
parent
b316c58b1a
commit
a27c18101b
5 changed files with 25 additions and 21 deletions
|
@ -8,7 +8,12 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
const rootDir = path.resolve(__dirname, '..');
|
const rootDir = path.resolve(__dirname, '..');
|
||||||
const CACHE_DIR = path.join(rootDir, '.cache');
|
const CACHE_DIR = path.join(rootDir, '.cache');
|
||||||
const CONFIG_PATH = path.join(CACHE_DIR, 'config.json');
|
const CONFIG_PATH = path.join(CACHE_DIR, 'config.json');
|
||||||
const MEDIA_TYPES = ['movie', 'show'];
|
|
||||||
|
export const MEDIA_TYPES = [
|
||||||
|
{ key: 'movie', label: 'movie', folder: 'movies' },
|
||||||
|
{ key: 'show', label: 'tv show', folder: 'shows' }
|
||||||
|
];
|
||||||
|
|
||||||
const ASSET_TYPES = ['poster', 'backdrop'];
|
const ASSET_TYPES = ['poster', 'backdrop'];
|
||||||
|
|
||||||
dotenv.config({ path: path.resolve(__dirname, '..', '..', '.env') });
|
dotenv.config({ path: path.resolve(__dirname, '..', '..', '.env') });
|
||||||
|
@ -61,20 +66,19 @@ export const initConfig = async () => {
|
||||||
|
|
||||||
config.mediaPaths = {};
|
config.mediaPaths = {};
|
||||||
|
|
||||||
for (const mediaType of MEDIA_TYPES) {
|
for (const { key, label, folder } of MEDIA_TYPES) {
|
||||||
config.mediaPaths[mediaType] = {};
|
config.mediaPaths[key] = {};
|
||||||
|
|
||||||
for (const assetType of ASSET_TYPES) {
|
for (const assetType of ASSET_TYPES) {
|
||||||
const mediaFolder = `${mediaType}s`;
|
|
||||||
const assetFolder = assetType === 'poster' ? '' : `/${assetType}s`;
|
const assetFolder = assetType === 'poster' ? '' : `/${assetType}s`;
|
||||||
const defaultPath = `Media assets/${mediaFolder}${assetFolder}`.replace(/\/$/, '');
|
const defaultPath = `Media assets/${folder}${assetFolder}`.replace(/\/$/, '');
|
||||||
let subpath = defaultPath;
|
let subpath = defaultPath;
|
||||||
|
|
||||||
if (customize) {
|
if (customize) {
|
||||||
const response = await inquirer.prompt([
|
const response = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
name: 'subpath',
|
name: 'subpath',
|
||||||
message: `Subpath for ${mediaType}/${assetType} (relative to storage root):`,
|
message: `Subpath for ${label}/${assetType} (relative to storage root):`,
|
||||||
default: defaultPath
|
default: defaultPath
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
@ -82,7 +86,7 @@ export const initConfig = async () => {
|
||||||
subpath = response.subpath;
|
subpath = response.subpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
config.mediaPaths[mediaType][assetType] = subpath;
|
config.mediaPaths[key][assetType] = subpath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +171,7 @@ export const initConfig = async () => {
|
||||||
|
|
||||||
export const loadConfig = async () => {
|
export const loadConfig = async () => {
|
||||||
if (!(await fs.pathExists(CONFIG_PATH))) {
|
if (!(await fs.pathExists(CONFIG_PATH))) {
|
||||||
console.error('❌ Config not found. Run `coryd init` first.');
|
console.error('❌ Config not found. Run \`coryd init\` first.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +184,6 @@ const fetchGlobals = async () => {
|
||||||
|
|
||||||
if (!POSTGREST_URL || !POSTGREST_API_KEY) {
|
if (!POSTGREST_URL || !POSTGREST_API_KEY) {
|
||||||
console.warn('⚠️ Missing POSTGREST_URL or POSTGREST_API_KEY in env, skipping globals fetch.');
|
console.warn('⚠️ Missing POSTGREST_URL or POSTGREST_API_KEY in env, skipping globals fetch.');
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,11 +199,9 @@ const fetchGlobals = async () => {
|
||||||
if (!res.ok) throw new Error(await res.text());
|
if (!res.ok) throw new Error(await res.text());
|
||||||
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
return data[0] || {};
|
return data[0] || {};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('❌ Error fetching globals:', err.message);
|
console.error('❌ Error fetching globals:', err.message);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ import path from 'path';
|
||||||
import https from 'https';
|
import https from 'https';
|
||||||
import inquirer from 'inquirer';
|
import inquirer from 'inquirer';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { loadConfig } from './config.js';
|
import { loadConfig, MEDIA_TYPES } from './config.js';
|
||||||
import { sanitizeMediaString } from './sanitize.js';
|
import { sanitizeMediaString } from './sanitize.js';
|
||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
@ -51,8 +51,11 @@ export const downloadWatchingImages = async () => {
|
||||||
const { mediaType } = await inquirer.prompt({
|
const { mediaType } = await inquirer.prompt({
|
||||||
type: 'list',
|
type: 'list',
|
||||||
name: 'mediaType',
|
name: 'mediaType',
|
||||||
message: 'Movie or a show?',
|
message: 'Movie or a tv show?',
|
||||||
choices: Object.keys(config.mediaPaths)
|
choices: MEDIA_TYPES.map(({ key, label }) => ({
|
||||||
|
name: label,
|
||||||
|
value: key
|
||||||
|
}))
|
||||||
});
|
});
|
||||||
const { tmdbId } = await inquirer.prompt({
|
const { tmdbId } = await inquirer.prompt({
|
||||||
name: 'tmdbId',
|
name: 'tmdbId',
|
||||||
|
@ -241,7 +244,7 @@ export const downloadAsset = async () => {
|
||||||
type: 'list',
|
type: 'list',
|
||||||
name: 'type',
|
name: 'type',
|
||||||
message: 'What type of asset are you downloading?',
|
message: 'What type of asset are you downloading?',
|
||||||
choices: ['movie/show', 'artist', 'album', 'book']
|
choices: ['movie/tv show', 'artist', 'album', 'book']
|
||||||
});
|
});
|
||||||
|
|
||||||
if (type === 'artist') {
|
if (type === 'artist') {
|
||||||
|
|
|
@ -70,7 +70,7 @@ export const runJobsMenu = async () => {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '📽 Import movie or show',
|
name: '📽 Import a movie or tv show',
|
||||||
type: 'curl',
|
type: 'curl',
|
||||||
apiUrl: `${config.url}/api/watching-import.php`,
|
apiUrl: `${config.url}/api/watching-import.php`,
|
||||||
tokenEnvVar: 'WATCHING_IMPORT_TOKEN',
|
tokenEnvVar: 'WATCHING_IMPORT_TOKEN',
|
||||||
|
@ -86,8 +86,8 @@ export const runJobsMenu = async () => {
|
||||||
{
|
{
|
||||||
type: 'list',
|
type: 'list',
|
||||||
name: 'media_type',
|
name: 'media_type',
|
||||||
message: 'Is this a movie or a show?',
|
message: 'Is this a movie or tv show?',
|
||||||
choices: ['movie', 'show']
|
choices: ['movie', 'tv']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
4
cli/package-lock.json
generated
4
cli/package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "coryd",
|
"name": "coryd",
|
||||||
"version": "3.2.5",
|
"version": "3.2.6",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "coryd",
|
"name": "coryd",
|
||||||
"version": "3.2.5",
|
"version": "3.2.6",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@directus/sdk": "^19.1.0",
|
"@directus/sdk": "^19.1.0",
|
||||||
"chalk": "^5.4.1",
|
"chalk": "^5.4.1",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "coryd",
|
"name": "coryd",
|
||||||
"version": "3.2.5",
|
"version": "3.2.6",
|
||||||
"description": "The CLI for my site to handle tasks, run commands or jobs and download things.",
|
"description": "The CLI for my site to handle tasks, run commands or jobs and download things.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue