diff --git a/server/lib/settings/index.ts b/server/lib/settings/index.ts index 2b614f92..1a344e9e 100644 --- a/server/lib/settings/index.ts +++ b/server/lib/settings/index.ts @@ -81,10 +81,6 @@ export interface DVRSettings { tagRequests: boolean; } -export interface TvdbSettings { - use: boolean; -} - export interface RadarrSettings extends DVRSettings { minimumAvailability: string; } @@ -293,12 +289,12 @@ export interface AllSettings { plex: PlexSettings; jellyfin: JellyfinSettings; tautulli: TautulliSettings; - tvdb: TvdbSettings; radarr: RadarrSettings[]; sonarr: SonarrSettings[]; public: PublicSettings; notifications: NotificationSettings; jobs: Record; + tvdb: boolean; } const SETTINGS_PATH = process.env.CONFIG_DIRECTORY @@ -354,7 +350,7 @@ class Settings { apiKey: '', }, tautulli: {}, - tvdb: { use: false }, + tvdb: false, radarr: [], sonarr: [], public: { @@ -523,11 +519,11 @@ class Settings { this.data.tautulli = data; } - get tvdb(): TvdbSettings { + get tvdb(): boolean { return this.data.tvdb; } - set tvdb(data: TvdbSettings) { + set tvdb(data: boolean) { this.data.tvdb = data; } @@ -697,7 +693,7 @@ export const getSettings = (initialSettings?: AllSettings): Settings => { export const getIndexer = (): TvShowIndexer => { const settings = getSettings(); - if (settings.tvdb?.use) { + if (settings.tvdb) { return new Tvdb(); } else { return new TheMovieDb(); diff --git a/server/routes/settings/tvdb.ts b/server/routes/settings/tvdb.ts index db497be7..2a62f1ed 100644 --- a/server/routes/settings/tvdb.ts +++ b/server/routes/settings/tvdb.ts @@ -1,35 +1,33 @@ import Tvdb from '@server/api/indexer/tvdb'; -import type { TvdbSettings } from '@server/lib/settings'; import { getSettings } from '@server/lib/settings'; import logger from '@server/logger'; import { Router } from 'express'; const tvdbRoutes = Router(); +export interface TvdbSettings { + tvdb: boolean; +} + tvdbRoutes.get('/', (_req, res) => { const settings = getSettings(); - res.status(200).json(settings.tvdb); + res.status(200).json({ + tvdb: settings.tvdb, + }); }); tvdbRoutes.put('/', (req, res) => { const settings = getSettings(); - if (!settings.tvdb) { - settings.tvdb = { - use: false, - }; - } + const body = req.body as TvdbSettings; - const newTvdb = req.body as TvdbSettings; - const tvdb = settings.tvdb; - - tvdb.use = newTvdb.use; - - settings.tvdb = tvdb; + settings.tvdb = body.tvdb ?? settings.tvdb ?? false; settings.save(); - return res.status(200).json(newTvdb); + return res.status(200).json({ + tvdb: settings.tvdb, + }); }); tvdbRoutes.post('/test', async (req, res, next) => { diff --git a/src/components/Settings/SettingsTvdb.tsx b/src/components/Settings/SettingsTvdb.tsx index bf981c0f..4931d306 100644 --- a/src/components/Settings/SettingsTvdb.tsx +++ b/src/components/Settings/SettingsTvdb.tsx @@ -5,7 +5,7 @@ import SettingsBadge from '@app/components/Settings/SettingsBadge'; import globalMessages from '@app/i18n/globalMessages'; import defineMessages from '@app/utils/defineMessages'; import { ArrowDownOnSquareIcon, BeakerIcon } from '@heroicons/react/24/outline'; -import type { TvdbSettings } from '@server/lib/settings'; +import type { TvdbSettings } from '@server/routes/settings/tvdb'; import { Field, Form, Formik } from 'formik'; import { useState } from 'react'; import { useIntl } from 'react-intl'; @@ -42,13 +42,15 @@ const SettingsTvdb = () => { } }; - const saveSettings = async (values: TvdbSettings) => { + const saveSettings = async (value: TvdbSettings) => { const response = await fetch('/api/v1/settings/tvdb', { method: 'PUT', headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify(values), + body: JSON.stringify({ + tvdb: value.tvdb, + }), }); if (!response.ok) { @@ -77,7 +79,7 @@ const SettingsTvdb = () => {
{ try { @@ -93,8 +95,11 @@ const SettingsTvdb = () => { try { await saveSettings({ - use: values.enable || false, + tvdb: values.enable ?? false, }); + if (data) { + data.tvdb = values.enable; + } } catch (e) { addToast('Failed to save Tvdb settings', { appearance: 'error' }); return;