refactor(settings): replace tvdb object to boolean type

This commit is contained in:
TOomaAh
2024-10-29 23:10:35 +01:00
parent 85aeeb084e
commit 3f16176667
3 changed files with 27 additions and 28 deletions

View File

@@ -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<JobId, JobSettings>;
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();

View File

@@ -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) => {

View File

@@ -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 = () => {
<div className="section">
<Formik
initialValues={{
enable: data?.use,
enable: data?.tvdb ?? false,
}}
onSubmit={async (values) => {
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;