fix(cli): more consistent labeling in movie/show download prompt

This commit is contained in:
Cory Dransfeldt 2025-06-14 18:52:08 -07:00
parent b316c58b1a
commit a27c18101b
No known key found for this signature in database
5 changed files with 25 additions and 21 deletions

View file

@ -8,7 +8,12 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
const rootDir = path.resolve(__dirname, '..');
const CACHE_DIR = path.join(rootDir, '.cache');
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'];
dotenv.config({ path: path.resolve(__dirname, '..', '..', '.env') });
@ -61,20 +66,19 @@ export const initConfig = async () => {
config.mediaPaths = {};
for (const mediaType of MEDIA_TYPES) {
config.mediaPaths[mediaType] = {};
for (const { key, label, folder } of MEDIA_TYPES) {
config.mediaPaths[key] = {};
for (const assetType of ASSET_TYPES) {
const mediaFolder = `${mediaType}s`;
const assetFolder = assetType === 'poster' ? '' : `/${assetType}s`;
const defaultPath = `Media assets/${mediaFolder}${assetFolder}`.replace(/\/$/, '');
const defaultPath = `Media assets/${folder}${assetFolder}`.replace(/\/$/, '');
let subpath = defaultPath;
if (customize) {
const response = await inquirer.prompt([
{
name: 'subpath',
message: `Subpath for ${mediaType}/${assetType} (relative to storage root):`,
message: `Subpath for ${label}/${assetType} (relative to storage root):`,
default: defaultPath
}
]);
@ -82,7 +86,7 @@ export const initConfig = async () => {
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 () => {
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);
}
@ -180,7 +184,6 @@ const fetchGlobals = async () => {
if (!POSTGREST_URL || !POSTGREST_API_KEY) {
console.warn('⚠️ Missing POSTGREST_URL or POSTGREST_API_KEY in env, skipping globals fetch.');
return {};
}
@ -196,11 +199,9 @@ const fetchGlobals = async () => {
if (!res.ok) throw new Error(await res.text());
const data = await res.json();
return data[0] || {};
} catch (err) {
console.error('❌ Error fetching globals:', err.message);
return {};
}
};

View file

@ -3,7 +3,7 @@ import path from 'path';
import https from 'https';
import inquirer from 'inquirer';
import { fileURLToPath } from 'url';
import { loadConfig } from './config.js';
import { loadConfig, MEDIA_TYPES } from './config.js';
import { sanitizeMediaString } from './sanitize.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@ -51,8 +51,11 @@ export const downloadWatchingImages = async () => {
const { mediaType } = await inquirer.prompt({
type: 'list',
name: 'mediaType',
message: 'Movie or a show?',
choices: Object.keys(config.mediaPaths)
message: 'Movie or a tv show?',
choices: MEDIA_TYPES.map(({ key, label }) => ({
name: label,
value: key
}))
});
const { tmdbId } = await inquirer.prompt({
name: 'tmdbId',
@ -241,7 +244,7 @@ export const downloadAsset = async () => {
type: 'list',
name: 'type',
message: 'What type of asset are you downloading?',
choices: ['movie/show', 'artist', 'album', 'book']
choices: ['movie/tv show', 'artist', 'album', 'book']
});
if (type === 'artist') {

View file

@ -70,7 +70,7 @@ export const runJobsMenu = async () => {
]
},
{
name: '📽 Import movie or show',
name: '📽 Import a movie or tv show',
type: 'curl',
apiUrl: `${config.url}/api/watching-import.php`,
tokenEnvVar: 'WATCHING_IMPORT_TOKEN',
@ -86,8 +86,8 @@ export const runJobsMenu = async () => {
{
type: 'list',
name: 'media_type',
message: 'Is this a movie or a show?',
choices: ['movie', 'show']
message: 'Is this a movie or tv show?',
choices: ['movie', 'tv']
}
]
},