chore(*): use prettier for formatting

This commit is contained in:
Cory Dransfeldt 2025-06-14 16:43:12 -07:00
parent 6c659fe1d0
commit 029caaaa9e
No known key found for this signature in database
73 changed files with 1390 additions and 794 deletions

View file

@ -8,7 +8,7 @@ export const addBlockedRobot = async () => {
initDirectusClient(config);
const robots = await searchItems('robots', '/');
let rootRobot = robots.find(r => r.path === '/');
let rootRobot = robots.find((r) => r.path === '/');
if (!rootRobot) {
console.log(' No robots entry for `/` found. Creating one...');
@ -23,7 +23,7 @@ export const addBlockedRobot = async () => {
const { userAgent } = await inquirer.prompt({
name: 'userAgent',
message: '🤖 Enter the user-agent string to block:',
validate: input => !!input || 'User-agent cannot be empty'
validate: (input) => !!input || 'User-agent cannot be empty'
});
const createdAgent = await createItem('user_agents', {

View file

@ -1,6 +1,12 @@
import inquirer from 'inquirer';
import { loadConfig } from '../config.js';
import { initDirectusClient, getDirectusClient, searchItems, createItem, updateItem } from '../directus/client.js';
import {
initDirectusClient,
getDirectusClient,
searchItems,
createItem,
updateItem
} from '../directus/client.js';
export const addEpisodeToShow = async () => {
const config = await loadConfig();
@ -10,7 +16,7 @@ export const addEpisodeToShow = async () => {
const directus = getDirectusClient();
const showResults = await inquirer.prompt({
name: 'query',
message: 'Search for a show:',
message: 'Search for a show:'
});
const matches = await searchItems('shows', showResults.query);
@ -24,34 +30,35 @@ export const addEpisodeToShow = async () => {
type: 'list',
name: 'showId',
message: 'Select a show:',
choices: matches.map(s => ({
choices: matches.map((s) => ({
name: s.title || s.name || s.id,
value: s.id,
})),
value: s.id
}))
});
const { season_number, episode_number, plays } = await inquirer.prompt([
{
name: 'season_number',
message: 'Season number:',
validate: val => !isNaN(val),
validate: (val) => !isNaN(val)
},
{
name: 'episode_number',
message: 'Episode number:',
validate: val => !isNaN(val),
validate: (val) => !isNaN(val)
},
{
name: 'plays',
message: 'Play count:',
default: 0,
validate: val => !isNaN(val),
},
validate: (val) => !isNaN(val)
}
]);
const existing = await searchItems('episodes', `${season_number} ${episode_number}`);
const match = existing.find(e =>
Number(e.season_number) === Number(season_number) &&
Number(e.episode_number) === Number(episode_number) &&
e.show === showId
const match = existing.find(
(e) =>
Number(e.season_number) === Number(season_number) &&
Number(e.episode_number) === Number(episode_number) &&
e.show === showId
);
if (match) {
@ -59,7 +66,7 @@ export const addEpisodeToShow = async () => {
type: 'confirm',
name: 'update',
message: `Episode exists. Update play count from ${match.plays ?? 0} to ${plays}?`,
default: true,
default: true
});
if (update) {
@ -74,7 +81,7 @@ export const addEpisodeToShow = async () => {
season_number: Number(season_number),
episode_number: Number(episode_number),
plays: Number(plays),
show: showId,
show: showId
});
console.log(`📺 Created episode S${season_number}E${episode_number}`);

View file

@ -12,12 +12,12 @@ export const addLinkToShare = async () => {
{
name: 'title',
message: '📝 Title for the link:',
validate: input => !!input || 'Title is required'
validate: (input) => !!input || 'Title is required'
},
{
name: 'link',
message: '🔗 URL to share:',
validate: input => input.startsWith('http') || 'Must be a valid URL'
validate: (input) => input.startsWith('http') || 'Must be a valid URL'
},
{
name: 'description',
@ -26,7 +26,7 @@ export const addLinkToShare = async () => {
},
{
name: 'authorQuery',
message: '👤 Search for an author:',
message: '👤 Search for an author:'
}
]);
@ -38,13 +38,17 @@ export const addLinkToShare = async () => {
type: 'confirm',
name: 'shouldCreate',
message: '❌ No authors found. Do you want to create a new one?',
default: true,
default: true
});
if (!shouldCreate) return;
const { name, url, mastodon, rss, json, newsletter, blogroll } = await inquirer.prompt([
{ name: 'name', message: '👤 Author name:', validate: input => !!input || 'Name is required' },
{
name: 'name',
message: '👤 Author name:',
validate: (input) => !!input || 'Name is required'
},
{ name: 'url', message: '🔗 URL (optional):', default: '' },
{ name: 'mastodon', message: '🐘 Mastodon handle (optional):', default: '' },
{ name: 'rss', message: '📡 RSS feed (optional):', default: '' },
@ -69,13 +73,13 @@ export const addLinkToShare = async () => {
type: 'list',
name: 'author',
message: 'Select an author:',
choices: authorMatches.map(a => {
choices: authorMatches.map((a) => {
const cleanUrl = removeUrlProtocol(a.url);
const display = cleanUrl ? `${a.name} (${cleanUrl})` : a.name;
return {
name: display,
value: a.id,
value: a.id
};
})
});
@ -88,7 +92,7 @@ export const addLinkToShare = async () => {
while (true) {
const { query } = await inquirer.prompt({
name: 'query',
message: '🏷 Search for tags (or leave blank to finish):',
message: '🏷 Search for tags (or leave blank to finish):'
});
const trimmedQuery = query.trim();
@ -106,7 +110,7 @@ export const addLinkToShare = async () => {
type: 'checkbox',
name: 'selected',
message: '✔ Select tags to add:',
choices: tags.map(tag => ({ name: tag.name, value: tag.id }))
choices: tags.map((tag) => ({ name: tag.name, value: tag.id }))
});
tagIds.push(...selected);
@ -115,7 +119,7 @@ export const addLinkToShare = async () => {
type: 'confirm',
name: 'again',
message: 'Search and select more tags?',
default: false,
default: false
});
if (!again) break;
@ -126,7 +130,7 @@ export const addLinkToShare = async () => {
link,
description,
author,
link_tags: tagIds.map(tagId => ({ tags_id: tagId })),
link_tags: tagIds.map((tagId) => ({ tags_id: tagId })),
date: new Date().toISOString()
});

View file

@ -18,34 +18,36 @@ export const addPost = async () => {
initDirectusClient(config);
const { title, description, content, featured } = await inquirer.prompt([{
name: 'title',
message: '📝 Title:',
validate: input => !!input || 'Title is required'
},
{
name: 'description',
message: '🗒 Description:',
default: ''
},
{
name: 'content',
message: '📄 Content:',
default: ''
},
{
type: 'confirm',
name: 'featured',
message: '⭐ Featured?',
default: false
}]);
const { title, description, content, featured } = await inquirer.prompt([
{
name: 'title',
message: '📝 Title:',
validate: (input) => !!input || 'Title is required'
},
{
name: 'description',
message: '🗒 Description:',
default: ''
},
{
name: 'content',
message: '📄 Content:',
default: ''
},
{
type: 'confirm',
name: 'featured',
message: '⭐ Featured?',
default: false
}
]);
let tagIds = [];
while (true) {
const { query } = await inquirer.prompt({
name: 'query',
message: '🏷 Search for tags (or leave blank to finish):',
message: '🏷 Search for tags (or leave blank to finish):'
});
const trimmedQuery = query.trim();
@ -63,7 +65,7 @@ export const addPost = async () => {
type: 'checkbox',
name: 'selected',
message: '✔ Select tags to add:',
choices: tags.map(tag => ({ name: tag.name, value: tag.id }))
choices: tags.map((tag) => ({ name: tag.name, value: tag.id }))
});
tagIds.push(...selected);
@ -72,7 +74,7 @@ export const addPost = async () => {
type: 'confirm',
name: 'again',
message: 'Search and select more tags?',
default: false,
default: false
});
if (!again) break;
@ -113,7 +115,7 @@ export const addPost = async () => {
type: 'list',
name: 'itemId',
message: `Select an item from ${collection}:`,
choices: results.map(item => ({
choices: results.map((item) => ({
name: item.title || item.name || item.id,
value: item.id
}))
@ -161,13 +163,16 @@ export const addPost = async () => {
type: 'checkbox',
name: 'selected',
message: `✔ Select ${mediaType} to associate:`,
choices: matches.map(m => ({
choices: matches.map((m) => ({
name: m.name_string || m.title || m.name || m.label || m.id,
value: m.id
}))
});
if (selected.length) associatedMediaPayload[`${mediaType}`] = selected.map(id => ({ [`${mediaType}_id`]: id }));
if (selected.length)
associatedMediaPayload[`${mediaType}`] = selected.map((id) => ({
[`${mediaType}_id`]: id
}));
}
}
@ -178,7 +183,7 @@ export const addPost = async () => {
content,
featured,
date: new Date().toISOString(),
post_tags: tagIds.map(tagId => ({ tags_id: tagId })),
post_tags: tagIds.map((tagId) => ({ tags_id: tagId })),
blocks: selectedBlocks,
...associatedMediaPayload
};

View file

@ -10,7 +10,7 @@ const TASKS = [
{ name: '🔗 Add link to share', handler: addLinkToShare },
{ name: ' Add episode to show', handler: addEpisodeToShow },
{ name: '📚 Update reading progress', handler: updateReadingProgress },
{ name: '🤖 Block robot', handler: addBlockedRobot },
{ name: '🤖 Block robot', handler: addBlockedRobot }
];
export const runTasksMenu = async () => {
@ -19,7 +19,7 @@ export const runTasksMenu = async () => {
type: 'list',
name: 'task',
message: 'Select a task to perform:',
choices: TASKS.map(t => ({ name: t.name, value: t.handler }))
choices: TASKS.map((t) => ({ name: t.name, value: t.handler }))
}
]);

View file

@ -19,7 +19,7 @@ export const updateReadingProgress = async () => {
type: 'list',
name: 'bookId',
message: '📚 Select a book to update progress:',
choices: readingBooks.map(book => {
choices: readingBooks.map((book) => {
const title = book.title || book.name || `Book #${book.id}`;
const progress = book.progress ?? 0;
@ -32,10 +32,10 @@ export const updateReadingProgress = async () => {
const { progress } = await inquirer.prompt({
name: 'progress',
message: '📕 New progress percentage (0100):',
validate: input => {
validate: (input) => {
const num = Number(input);
return !isNaN(num) && num >= 0 && num <= 100 || 'Enter a number from 0 to 100';
return (!isNaN(num) && num >= 0 && num <= 100) || 'Enter a number from 0 to 100';
}
});