feat(*.liquid): apply prettier to liquid templates

- offer to create tag when none is found while adding a link from cli
- fix tag display in search
This commit is contained in:
Cory Dransfeldt 2025-06-16 14:40:54 -07:00
parent 49e21d574e
commit efe701f939
No known key found for this signature in database
112 changed files with 1319 additions and 1134 deletions

View file

@ -1,22 +1,22 @@
import fs from 'fs-extra';
import path from 'path';
import inquirer from 'inquirer';
import { fileURLToPath } from 'url';
import dotenv from 'dotenv';
import fs from "fs-extra";
import path from "path";
import inquirer from "inquirer";
import { fileURLToPath } from "url";
import dotenv from "dotenv";
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 rootDir = path.resolve(__dirname, "..");
const CACHE_DIR = path.join(rootDir, ".cache");
const CONFIG_PATH = path.join(CACHE_DIR, "config.json");
export const MEDIA_TYPES = [
{ key: 'movie', label: 'movie', folder: 'movies' },
{ key: 'show', label: 'tv show', folder: 'shows' }
{ 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") });
export const initConfig = async () => {
const existingConfig = (await fs.pathExists(CONFIG_PATH)) ? await fs.readJson(CONFIG_PATH) : {};
@ -25,8 +25,8 @@ export const initConfig = async () => {
if (config.storageDir) {
const { updateStorage } = await inquirer.prompt([
{
type: 'confirm',
name: 'updateStorage',
type: "confirm",
name: "updateStorage",
message: `Storage directory is already set to "${config.storageDir}". Do you want to update it?`,
default: false
}
@ -35,8 +35,8 @@ export const initConfig = async () => {
if (updateStorage) {
const { storageDir } = await inquirer.prompt([
{
name: 'storageDir',
message: 'Where is your storage root directory?',
name: "storageDir",
message: "Where is your storage root directory?",
validate: fs.pathExists
}
]);
@ -46,8 +46,8 @@ export const initConfig = async () => {
} else {
const { storageDir } = await inquirer.prompt([
{
name: 'storageDir',
message: 'Where is your storage root directory?',
name: "storageDir",
message: "Where is your storage root directory?",
validate: fs.pathExists
}
]);
@ -57,9 +57,9 @@ export const initConfig = async () => {
const { customize } = await inquirer.prompt([
{
type: 'confirm',
name: 'customize',
message: 'Do you want to customize default media paths?',
type: "confirm",
name: "customize",
message: "Do you want to customize default media paths?",
default: false
}
]);
@ -70,14 +70,14 @@ export const initConfig = async () => {
config.mediaPaths[key] = {};
for (const assetType of ASSET_TYPES) {
const assetFolder = assetType === 'poster' ? '' : `/${assetType}s`;
const defaultPath = `Media assets/${folder}${assetFolder}`.replace(/\/$/, '');
const assetFolder = assetType === "poster" ? "" : `/${assetType}s`;
const defaultPath = `Media assets/${folder}${assetFolder}`.replace(/\/$/, "");
let subpath = defaultPath;
if (customize) {
const response = await inquirer.prompt([
{
name: 'subpath',
name: "subpath",
message: `Subpath for ${label}/${assetType} (relative to storage root):`,
default: defaultPath
}
@ -94,43 +94,43 @@ export const initConfig = async () => {
? (
await inquirer.prompt([
{
name: 'artistPath',
message: 'Subpath for artist images (relative to storage root):',
default: 'Media assets/artists'
name: "artistPath",
message: "Subpath for artist images (relative to storage root):",
default: "Media assets/artists"
}
])
).artistPath
: 'Media assets/artists';
: "Media assets/artists";
config.albumPath = customize
? (
await inquirer.prompt([
{
name: 'albumPath',
message: 'Subpath for album images (relative to storage root):',
default: 'Media assets/albums'
name: "albumPath",
message: "Subpath for album images (relative to storage root):",
default: "Media assets/albums"
}
])
).albumPath
: 'Media assets/albums';
: "Media assets/albums";
config.bookPath = customize
? (
await inquirer.prompt([
{
name: 'bookPath',
message: 'Subpath for book images (relative to storage root):',
default: 'Media assets/books'
name: "bookPath",
message: "Subpath for book images (relative to storage root):",
default: "Media assets/books"
}
])
).bookPath
: 'Media assets/books';
: "Media assets/books";
if (config.directus?.apiUrl) {
const { updateApiUrl } = await inquirer.prompt([
{
type: 'confirm',
name: 'updateApiUrl',
type: "confirm",
name: "updateApiUrl",
message: `Directus API URL is already set to "${config.directus.apiUrl}". Do you want to update it?`,
default: false
}
@ -139,9 +139,9 @@ export const initConfig = async () => {
if (updateApiUrl) {
const { apiUrl } = await inquirer.prompt([
{
name: 'apiUrl',
message: 'Enter your Directus instance URL:',
validate: (input) => input.startsWith('http') || 'Must be a valid URL'
name: "apiUrl",
message: "Enter your Directus instance URL:",
validate: (input) => input.startsWith("http") || "Must be a valid URL"
}
]);
@ -150,9 +150,9 @@ export const initConfig = async () => {
} else {
const { apiUrl } = await inquirer.prompt([
{
name: 'apiUrl',
message: 'Enter your Directus URL:',
validate: (input) => input.startsWith('http') || 'Must be a valid URL'
name: "apiUrl",
message: "Enter your Directus URL:",
validate: (input) => input.startsWith("http") || "Must be a valid URL"
}
]);
@ -171,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);
}
@ -183,15 +183,15 @@ const fetchGlobals = async () => {
const POSTGREST_API_KEY = process.env.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 {};
}
try {
const res = await fetch(`${POSTGREST_URL}/optimized_globals?select=*`, {
method: 'GET',
method: "GET",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
Authorization: `Bearer ${POSTGREST_API_KEY}`
}
});
@ -201,7 +201,7 @@ const fetchGlobals = async () => {
const data = await res.json();
return data[0] || {};
} catch (err) {
console.error('❌ Error fetching globals:', err.message);
console.error("❌ Error fetching globals:", err.message);
return {};
}
};