diff --git a/server/src/database/migrations/1733357722729-Remove-default-arr-servers.ts b/server/src/database/migrations/1733357722729-Remove-default-arr-servers.ts new file mode 100644 index 00000000..d4241d85 --- /dev/null +++ b/server/src/database/migrations/1733357722729-Remove-default-arr-servers.ts @@ -0,0 +1,58 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class RemoveDefaultArrServers1733357722729 + implements MigrationInterface +{ + name = 'RemoveDefaultArrServers1733357722729'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + CREATE TABLE "temporary_sonarr_settings" ( + "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, + "serverName" varchar NOT NULL, + "url" varchar, + "apiKey" varchar + ) + `); + await queryRunner.query(` + INSERT INTO "temporary_sonarr_settings"("id", "serverName", "url", "apiKey") + SELECT "id", + "serverName", + "url", + "apiKey" + FROM "sonarr_settings" + `); + await queryRunner.query(` + DROP TABLE "sonarr_settings" + `); + await queryRunner.query(` + ALTER TABLE "temporary_sonarr_settings" + RENAME TO "sonarr_settings" + `); + await queryRunner.query(` + CREATE TABLE "temporary_radarr_settings" ( + "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, + "serverName" varchar NOT NULL, + "url" varchar, + "apiKey" varchar + ) + `); + await queryRunner.query(` + INSERT INTO "temporary_radarr_settings"("id", "serverName", "url", "apiKey") + SELECT "id", + "serverName", + "url", + "apiKey" + FROM "radarr_settings" + `); + await queryRunner.query(` + DROP TABLE "radarr_settings" + `); + await queryRunner.query(` + ALTER TABLE "temporary_radarr_settings" + RENAME TO "radarr_settings" + `); + } + + public async down(queryRunner: QueryRunner): Promise {} +} diff --git a/server/src/modules/api/plex-api/plex-api.service.ts b/server/src/modules/api/plex-api/plex-api.service.ts index dad8e489..724200bc 100644 --- a/server/src/modules/api/plex-api/plex-api.service.ts +++ b/server/src/modules/api/plex-api/plex-api.service.ts @@ -443,13 +443,13 @@ export class PlexApiService { } public async deleteMediaFromDisk(plexId: number | string): Promise { - this.logger.log( - `[Plex] Removed media with ID ${plexId} from Plex library.`, - ); try { await this.plexClient.deleteQuery({ uri: `/library/metadata/${plexId}`, }); + this.logger.log( + `[Plex] Removed media with ID ${plexId} from Plex library.`, + ); } catch (e) { this.logger.warn('Something went wrong while removing media from Plex.', { label: 'Plex API', diff --git a/server/src/modules/settings/dto's/radarr-setting.dto.ts b/server/src/modules/settings/dto's/radarr-setting.dto.ts index d6586c28..1c0ebd56 100644 --- a/server/src/modules/settings/dto's/radarr-setting.dto.ts +++ b/server/src/modules/settings/dto's/radarr-setting.dto.ts @@ -8,8 +8,6 @@ export type RadarrSettingDto = { url: string; apiKey: string; - - isDefault: boolean; }; export type RadarrSettingRawDto = Omit; diff --git a/server/src/modules/settings/dto's/sonarr-setting.dto.ts b/server/src/modules/settings/dto's/sonarr-setting.dto.ts index 74ea6510..8ede6d05 100644 --- a/server/src/modules/settings/dto's/sonarr-setting.dto.ts +++ b/server/src/modules/settings/dto's/sonarr-setting.dto.ts @@ -8,8 +8,6 @@ export type SonarrSettingDto = { url: string; apiKey: string; - - isDefault: boolean; }; export type SonarrSettingRawDto = Omit; diff --git a/server/src/modules/settings/entities/radarr_settings.entities.ts b/server/src/modules/settings/entities/radarr_settings.entities.ts index 6fd7382f..ea7e036a 100644 --- a/server/src/modules/settings/entities/radarr_settings.entities.ts +++ b/server/src/modules/settings/entities/radarr_settings.entities.ts @@ -15,9 +15,6 @@ export class RadarrSettings { @Column({ nullable: true }) apiKey: string; - @Column({ default: false }) - isDefault: boolean; - @OneToMany(() => Collection, (collection) => collection.radarrSettings) collections: Collection[]; } diff --git a/server/src/modules/settings/entities/sonarr_settings.entities.ts b/server/src/modules/settings/entities/sonarr_settings.entities.ts index 7c877808..640aa5ea 100644 --- a/server/src/modules/settings/entities/sonarr_settings.entities.ts +++ b/server/src/modules/settings/entities/sonarr_settings.entities.ts @@ -15,9 +15,6 @@ export class SonarrSettings { @Column({ nullable: true }) apiKey: string; - @Column({ default: false }) - isDefault: boolean; - @OneToMany(() => Collection, (collection) => collection.sonarrSettings) collections: Collection[]; } diff --git a/server/src/modules/settings/settings.service.ts b/server/src/modules/settings/settings.service.ts index 35115bc5..ca99bf52 100644 --- a/server/src/modules/settings/settings.service.ts +++ b/server/src/modules/settings/settings.service.ts @@ -1,7 +1,7 @@ import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { randomUUID } from 'crypto'; -import { Not, Repository } from 'typeorm'; +import { Repository } from 'typeorm'; import { isValidCron } from 'cron-validator'; import { BasicResponseDto } from '../api/external-api/dto/basic-response.dto'; import { OverseerrApiService } from '../api/overseerr-api/overseerr-api.service'; @@ -154,25 +154,15 @@ export class SettingsService implements SettingDto { try { settings.url = settings.url.toLowerCase(); - return this.radarrSettingsRepo.manager.transaction(async (manager) => { - if (settings.isDefault) { - await manager - .withRepository(this.radarrSettingsRepo) - .update({ isDefault: true }, { isDefault: false }); - } - - const savedSetting = await manager - .withRepository(this.radarrSettingsRepo) - .save(settings); + const savedSetting = await this.radarrSettingsRepo.save(settings); - this.logger.log('Radarr setting added'); - return { - data: savedSetting, - status: 'OK', - code: 1, - message: 'Success', - }; - }); + this.logger.log('Radarr setting added'); + return { + data: savedSetting, + status: 'OK', + code: 1, + message: 'Success', + }; } catch (e) { this.logger.error('Error while adding Radarr setting: ', e); return { status: 'NOK', code: 0, message: 'Failure' }; @@ -185,33 +175,16 @@ export class SettingsService implements SettingDto { try { settings.url = settings.url.toLowerCase(); - const data = await this.radarrSettingsRepo.manager.transaction( - async (manager) => { - const settingsDb = await manager - .withRepository(this.radarrSettingsRepo) - .findOne({ - where: { id: settings.id }, - }); - - const data = { - ...settingsDb, - ...settings, - }; - - await manager.withRepository(this.radarrSettingsRepo).save(data); - - if (settings.isDefault) { - await manager - .withRepository(this.radarrSettingsRepo) - .update( - { isDefault: true, id: Not(settings.id) }, - { isDefault: false }, - ); - } + const settingsDb = await this.radarrSettingsRepo.findOne({ + where: { id: settings.id }, + }); - return data; - }, - ); + const data = { + ...settingsDb, + ...settings, + }; + + await this.radarrSettingsRepo.save(data); this.servarr.deleteCachedRadarrApiClient(settings.id); this.logger.log('Radarr settings updated'); @@ -284,25 +257,15 @@ export class SettingsService implements SettingDto { try { settings.url = settings.url.toLowerCase(); - return this.sonarrSettingsRepo.manager.transaction(async (manager) => { - if (settings.isDefault) { - await manager - .withRepository(this.sonarrSettingsRepo) - .update({ isDefault: true }, { isDefault: false }); - } - - const savedSetting = await manager - .withRepository(this.sonarrSettingsRepo) - .save(settings); + const savedSetting = await this.sonarrSettingsRepo.save(settings); - this.logger.log('Sonarr setting added'); - return { - data: savedSetting, - status: 'OK', - code: 1, - message: 'Success', - }; - }); + this.logger.log('Sonarr setting added'); + return { + data: savedSetting, + status: 'OK', + code: 1, + message: 'Success', + }; } catch (e) { this.logger.error('Error while adding Sonarr setting: ', e); return { status: 'NOK', code: 0, message: 'Failure' }; @@ -315,33 +278,16 @@ export class SettingsService implements SettingDto { try { settings.url = settings.url.toLowerCase(); - const data = await this.sonarrSettingsRepo.manager.transaction( - async (manager) => { - const settingsDb = await manager - .withRepository(this.sonarrSettingsRepo) - .findOne({ - where: { id: settings.id }, - }); - - const data = { - ...settingsDb, - ...settings, - }; - - await manager.withRepository(this.sonarrSettingsRepo).save(data); - - if (settings.isDefault) { - await manager - .withRepository(this.sonarrSettingsRepo) - .update( - { isDefault: true, id: Not(settings.id) }, - { isDefault: false }, - ); - } + const settingsDb = await this.sonarrSettingsRepo.findOne({ + where: { id: settings.id }, + }); - return data; - }, - ); + const data = { + ...settingsDb, + ...settings, + }; + + await this.sonarrSettingsRepo.save(data); this.servarr.deleteCachedSonarrApiClient(settings.id); diff --git a/ui/src/components/Rules/RuleGroup/AddModal/ArrAction/index.tsx b/ui/src/components/Rules/RuleGroup/AddModal/ArrAction/index.tsx index b8a518df..7613f4d2 100644 --- a/ui/src/components/Rules/RuleGroup/AddModal/ArrAction/index.tsx +++ b/ui/src/components/Rules/RuleGroup/AddModal/ArrAction/index.tsx @@ -8,9 +8,9 @@ type ArrType = 'Radarr' | 'Sonarr' interface ArrActionProps { type: ArrType arrAction?: number - settingId?: number + settingId?: number | null // null for when the user has selected 'None', undefined for when this is a new rule options?: Option[] - onUpdate: (value: number, settingId?: number) => void + onUpdate: (value: number, settingId?: number | null) => void } interface Option { @@ -19,14 +19,15 @@ interface Option { } const ArrAction = (props: ArrActionProps) => { - const [prevType, setPrevType] = useState(props.type) + const selectedSetting = + props.settingId === undefined ? '-1' : (props.settingId?.toString() ?? '') const [settings, setSettings] = useState<(IRadarrSetting | ISonarrSetting)[]>( [], ) const [loading, setLoading] = useState(true) const action = props.arrAction ? props.arrAction : 0 - const handleSelectedSettingIdChange = (id?: number) => { + const handleSelectedSettingIdChange = (id?: number | null) => { props.onUpdate(action, id) } @@ -40,19 +41,15 @@ const ArrAction = (props: ArrActionProps) => { const settingsResponse = await GetApiHandler( `/settings/${type.toLowerCase()}`, ) - setPrevType(type) setSettings(settingsResponse) setLoading(false) - if (!props.settingId || type != prevType) { - if (settingsResponse.length > 0) { - const defaultServer = settingsResponse.find((s) => s.isDefault) - handleSelectedSettingIdChange( - defaultServer ? defaultServer.id : settingsResponse[0]?.id, - ) - } else { - handleSelectedSettingIdChange(undefined) - } + // The selected server does not exist anymore (old client data potentially) so deselect + if ( + props.settingId && + settingsResponse.find((x) => x.id === props.settingId) == null + ) { + handleSelectedSettingIdChange(undefined) } } @@ -81,18 +78,24 @@ const ArrAction = (props: ArrActionProps) => {
setIsDefault(e.target.checked)} - /> -
-
-
-