From f2b63156d1d4aa903eb261d2c80c059c39d9091b Mon Sep 17 00:00:00 2001 From: Gauthier Date: Thu, 24 Oct 2024 18:13:11 +0200 Subject: [PATCH] feat: add a warning if permissions are missing from config folder (#1030) --- overseerr-api.yml | 3 +++ server/index.ts | 7 +++++++ server/routes/index.ts | 7 ++++++- server/utils/appDataVolume.ts | 11 ++++++++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/overseerr-api.yml b/overseerr-api.yml index 96a4520a7..ef3ccf8b3 100644 --- a/overseerr-api.yml +++ b/overseerr-api.yml @@ -1988,6 +1988,9 @@ paths: appDataPath: type: string example: /app/config + appDataPermissions: + type: boolean + example: true /settings/main: get: summary: Get main settings diff --git a/server/index.ts b/server/index.ts index 965903618..092b93fef 100644 --- a/server/index.ts +++ b/server/index.ts @@ -21,6 +21,7 @@ import clearCookies from '@server/middleware/clearcookies'; import routes from '@server/routes'; import avatarproxy from '@server/routes/avatarproxy'; import imageproxy from '@server/routes/imageproxy'; +import { appDataPermissions } from '@server/utils/appDataVolume'; import { getAppVersion } from '@server/utils/appVersion'; import restartFlag from '@server/utils/restartFlag'; import { getClientIp } from '@supercharge/request-ip'; @@ -51,6 +52,12 @@ const dev = process.env.NODE_ENV !== 'production'; const app = next({ dev }); const handle = app.getRequestHandler(); +if (!appDataPermissions()) { + logger.error( + 'Something went wrong while checking config folder! Please ensure the config folder is set up properly.\nhttps://docs.jellyseerr.dev/getting-started' + ); +} + app .prepare() .then(async () => { diff --git a/server/routes/index.ts b/server/routes/index.ts index c7c8389e0..120e2e86b 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -17,7 +17,11 @@ import { mapProductionCompany } from '@server/models/Movie'; import { mapNetwork } from '@server/models/Tv'; import settingsRoutes from '@server/routes/settings'; import watchlistRoutes from '@server/routes/watchlist'; -import { appDataPath, appDataStatus } from '@server/utils/appDataVolume'; +import { + appDataPath, + appDataPermissions, + appDataStatus, +} from '@server/utils/appDataVolume'; import { getAppVersion, getCommitTag } from '@server/utils/appVersion'; import restartFlag from '@server/utils/restartFlag'; import { isPerson } from '@server/utils/typeHelpers'; @@ -93,6 +97,7 @@ router.get('/status/appdata', (_req, res) => { return res.status(200).json({ appData: appDataStatus(), appDataPath: appDataPath(), + appDataPermissions: appDataPermissions(), }); }); diff --git a/server/utils/appDataVolume.ts b/server/utils/appDataVolume.ts index 73c80b2c5..837f7f669 100644 --- a/server/utils/appDataVolume.ts +++ b/server/utils/appDataVolume.ts @@ -1,4 +1,4 @@ -import { existsSync } from 'fs'; +import { accessSync, existsSync } from 'fs'; import path from 'path'; const CONFIG_PATH = process.env.CONFIG_DIRECTORY @@ -14,3 +14,12 @@ export const appDataStatus = (): boolean => { export const appDataPath = (): string => { return CONFIG_PATH; }; + +export const appDataPermissions = (): boolean => { + try { + accessSync(CONFIG_PATH); + return true; + } catch (err) { + return false; + } +};