fix(cli): clean up eager loading bug when initializing cli

This commit is contained in:
Cory Dransfeldt 2025-06-10 18:35:25 -07:00
parent a443868f8b
commit 3d20361355
No known key found for this signature in database
5 changed files with 99 additions and 96 deletions

View file

@ -5,7 +5,8 @@ import { fileURLToPath } from 'url';
import dotenv from 'dotenv';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const CACHE_DIR = path.resolve(__dirname, '..', '.cache');
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'];
const ASSET_TYPES = ['poster', 'backdrop'];
@ -13,10 +14,7 @@ const ASSET_TYPES = ['poster', 'backdrop'];
dotenv.config({ path: path.resolve(__dirname, '..', '..', '.env') });
export const initConfig = async () => {
const existingConfig = await fs.pathExists(CONFIG_PATH)
? await fs.readJson(CONFIG_PATH)
: {};
const existingConfig = await fs.pathExists(CONFIG_PATH) ? await fs.readJson(CONFIG_PATH) : {};
const config = { ...existingConfig };
if (config.storageDir) {
@ -153,7 +151,7 @@ export const loadConfig = async () => {
}
return await fs.readJson(CONFIG_PATH);
}
};
const fetchGlobals = async () => {
const POSTGREST_URL = process.env.POSTGREST_URL;

View file

@ -4,96 +4,96 @@ import { fileURLToPath } from 'url';
import dotenv from 'dotenv';
import { loadConfig } from './config.js';
const config = await loadConfig();
const __dirname = path.dirname(fileURLToPath(import.meta.url));
dotenv.config({ path: path.resolve(__dirname, '..', '..', '.env') });
const JOBS = [
{
name: '🛠 Rebuild site',
type: 'curl',
urlEnvVar: 'SITE_REBUILD_WEBHOOK',
tokenEnvVar: 'DIRECTUS_API_TOKEN',
method: 'GET'
},
{
name: '💿 Scrobble listens from Navidrome',
type: 'curl',
apiUrl: `${config.globals.url}/api/scrobble.php`,
tokenEnvVar: 'NAVIDROME_SCROBBLE_TOKEN',
method: 'POST'
},
{
name: '🎧 Update total plays',
type: 'curl',
urlEnvVar: 'TOTAL_PLAYS_WEBHOOK',
tokenEnvVar: 'DIRECTUS_API_TOKEN',
method: 'GET'
},
{
name: '🐘 Send posts to Mastodon',
type: 'curl',
apiUrl: `${config.globals.url}/api/mastodon.php`,
tokenEnvVar: 'MASTODON_SYNDICATION_TOKEN',
method: 'POST'
},
{
name: '🎤 Import artist from Navidrome',
type: 'curl',
apiUrl: `${config.globals.url}/api/artist-import.php`,
tokenEnvVar: 'ARTIST_IMPORT_TOKEN',
method: 'POST',
paramsPrompt: [{
type: 'input',
name: 'artistId',
message: 'Enter the Navidrome artist ID:',
validate: input => input ? true : 'Artist ID is required'
}]
},
{
name: '📖 Import book',
type: 'curl',
apiUrl: `${config.globals.url}/api/book-import.php`,
tokenEnvVar: 'BOOK_IMPORT_TOKEN',
method: 'POST',
paramsPrompt: [{
type: 'input',
name: 'isbn',
message: 'Enter the book\'s ISBN:',
validate: input => input ? true : 'ISBN is required'
}]
},
{
name: '📽 Import movie or show',
type: 'curl',
apiUrl: `${config.globals.url}/api/watching-import.php`,
tokenEnvVar: 'WATCHING_IMPORT_TOKEN',
method: 'POST',
tokenIncludeInParams: true,
paramsPrompt: [{
type: 'input',
name: 'tmdb_id',
message: 'Enter the TMDB ID:',
validate: (input) =>
/^\d+$/.test(input) ? true : 'Please enter a valid TMDB ID'
export const runJobsMenu = async () => {
const config = await loadConfig();
const JOBS = [
{
name: '🛠 Rebuild site',
type: 'curl',
urlEnvVar: 'SITE_REBUILD_WEBHOOK',
tokenEnvVar: 'DIRECTUS_API_TOKEN',
method: 'GET'
},
{
type: 'list',
name: 'media_type',
message: 'Is this a movie or a show?',
choices: ['movie', 'show']
}]
},
{
name: '📺 Import upcoming TV seasons',
type: 'curl',
apiUrl: `${config.globals.url}/api/seasons-import.php`,
tokenEnvVar: 'SEASONS_IMPORT_TOKEN',
method: 'POST'
}];
name: '💿 Scrobble listens from Navidrome',
type: 'curl',
apiUrl: `${config.globals.url}/api/scrobble.php`,
tokenEnvVar: 'NAVIDROME_SCROBBLE_TOKEN',
method: 'POST'
},
{
name: '🎧 Update total plays',
type: 'curl',
urlEnvVar: 'TOTAL_PLAYS_WEBHOOK',
tokenEnvVar: 'DIRECTUS_API_TOKEN',
method: 'GET'
},
{
name: '🐘 Send posts to Mastodon',
type: 'curl',
apiUrl: `${config.globals.url}/api/mastodon.php`,
tokenEnvVar: 'MASTODON_SYNDICATION_TOKEN',
method: 'POST'
},
{
name: '🎤 Import artist from Navidrome',
type: 'curl',
apiUrl: `${config.globals.url}/api/artist-import.php`,
tokenEnvVar: 'ARTIST_IMPORT_TOKEN',
method: 'POST',
paramsPrompt: [{
type: 'input',
name: 'artistId',
message: 'Enter the Navidrome artist ID:',
validate: input => input ? true : 'Artist ID is required'
}]
},
{
name: '📖 Import book',
type: 'curl',
apiUrl: `${config.globals.url}/api/book-import.php`,
tokenEnvVar: 'BOOK_IMPORT_TOKEN',
method: 'POST',
paramsPrompt: [{
type: 'input',
name: 'isbn',
message: 'Enter the book\'s ISBN:',
validate: input => input ? true : 'ISBN is required'
}]
},
{
name: '📽 Import movie or show',
type: 'curl',
apiUrl: `${config.globals.url}/api/watching-import.php`,
tokenEnvVar: 'WATCHING_IMPORT_TOKEN',
method: 'POST',
tokenIncludeInParams: true,
paramsPrompt: [{
type: 'input',
name: 'tmdb_id',
message: 'Enter the TMDB ID:',
validate: (input) =>
/^\d+$/.test(input) ? true : 'Please enter a valid TMDB ID'
},
{
type: 'list',
name: 'media_type',
message: 'Is this a movie or a show?',
choices: ['movie', 'show']
}]
},
{
name: '📺 Import upcoming TV seasons',
type: 'curl',
apiUrl: `${config.globals.url}/api/seasons-import.php`,
tokenEnvVar: 'SEASONS_IMPORT_TOKEN',
method: 'POST'
}];
export const runJobsMenu = async () => {
const { selectedJob } = await inquirer.prompt([{
type: 'list',
name: 'selectedJob',