From 7d65a6e2648309c7dfc0e47d842dbde534a0532c Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 12 May 2024 00:44:46 +0300 Subject: [PATCH] Add content manager config notice --- src/endpoints/content-manager.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/endpoints/content-manager.js b/src/endpoints/content-manager.js index d5aec6d17..a2a81615e 100644 --- a/src/endpoints/content-manager.js +++ b/src/endpoints/content-manager.js @@ -3,7 +3,7 @@ const path = require('path'); const express = require('express'); const fetch = require('node-fetch').default; const sanitize = require('sanitize-filename'); -const { getConfigValue } = require('../util'); +const { getConfigValue, color } = require('../util'); const { jsonParser } = require('../express-common'); const writeFileAtomicSync = require('write-file-atomic').sync; const contentDirectory = path.join(process.cwd(), 'default/content'); @@ -94,8 +94,11 @@ function getDefaultPresetFile(filename) { * @param {ContentItem[]} contentIndex Content index * @param {import('../users').UserDirectoryList} directories User directories * @param {string[]} forceCategories List of categories to force check (even if content check is skipped) + * @returns {Promise} Whether any content was added */ async function seedContentForUser(contentIndex, directories, forceCategories) { + let anyContentAdded = false; + if (!fs.existsSync(directories.root)) { fs.mkdirSync(directories.root, { recursive: true }); } @@ -134,9 +137,11 @@ async function seedContentForUser(contentIndex, directories, forceCategories) { fs.cpSync(contentPath, targetPath, { recursive: true, force: false }); console.log(`Content file ${contentItem.filename} copied to ${contentTarget}`); + anyContentAdded = true; } writeFileAtomicSync(contentLogPath, contentLog.join('\n')); + return anyContentAdded; } /** @@ -147,15 +152,27 @@ async function seedContentForUser(contentIndex, directories, forceCategories) { */ async function checkForNewContent(directoriesList, forceCategories = []) { try { - if (getConfigValue('skipContentCheck', false) && forceCategories?.length === 0) { + const contentCheckSkip = getConfigValue('skipContentCheck', false); + if (contentCheckSkip && forceCategories?.length === 0) { return; } const contentIndexText = fs.readFileSync(contentIndexPath, 'utf8'); const contentIndex = JSON.parse(contentIndexText); + let anyContentAdded = false; for (const directories of directoriesList) { - await seedContentForUser(contentIndex, directories, forceCategories); + const seedResult = await seedContentForUser(contentIndex, directories, forceCategories); + + if (seedResult) { + anyContentAdded = true; + } + } + + if (anyContentAdded && !contentCheckSkip && forceCategories?.length === 0) { + console.log(); + console.log(`${color.blue('If you don\'t want to receive content updates in the future, set')} ${color.yellow('skipContentCheck')} ${color.blue('to true in the config.yaml file.')}`); + console.log(); } } catch (err) { console.log('Content check failed', err);