mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2026-01-01 04:08:45 -05:00
fix(api): add a migration script to rename *arr tags with spaces (#1946)
* fix(api): add a migration script to rename *arr tags with spaces This PR adds a migration script that will run at the startup of the app to remove the spaces from the *arr tags of Jellyseerr. fix #1897 re #1913 re https://github.com/Radarr/Radarr/issues/11251 * fix: add error message to logs
This commit is contained in:
@@ -198,6 +198,25 @@ class ServarrBase<QueueItemAppendT> extends ExternalAPI {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public renameTag = async ({
|
||||||
|
id,
|
||||||
|
label,
|
||||||
|
}: {
|
||||||
|
id: number;
|
||||||
|
label: string;
|
||||||
|
}): Promise<Tag> => {
|
||||||
|
try {
|
||||||
|
const response = await this.axios.put<Tag>(`/tag/${id}`, {
|
||||||
|
id,
|
||||||
|
label,
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(`[${this.apiName}] Failed to rename tag: ${e.message}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
async refreshMonitoredDownloads(): Promise<void> {
|
async refreshMonitoredDownloads(): Promise<void> {
|
||||||
await this.runCommand('RefreshMonitoredDownloads', {});
|
await this.runCommand('RefreshMonitoredDownloads', {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -363,6 +363,7 @@ export interface AllSettings {
|
|||||||
jobs: Record<JobId, JobSettings>;
|
jobs: Record<JobId, JobSettings>;
|
||||||
network: NetworkSettings;
|
network: NetworkSettings;
|
||||||
metadataSettings: MetadataSettings;
|
metadataSettings: MetadataSettings;
|
||||||
|
migrations: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const SETTINGS_PATH = process.env.CONFIG_DIRECTORY
|
const SETTINGS_PATH = process.env.CONFIG_DIRECTORY
|
||||||
@@ -593,6 +594,7 @@ class Settings {
|
|||||||
forceMaxTtl: -1,
|
forceMaxTtl: -1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
migrations: [],
|
||||||
};
|
};
|
||||||
if (initialSettings) {
|
if (initialSettings) {
|
||||||
this.data = merge(this.data, initialSettings);
|
this.data = merge(this.data, initialSettings);
|
||||||
@@ -722,6 +724,14 @@ class Settings {
|
|||||||
this.data.network = data;
|
this.data.network = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get migrations(): string[] {
|
||||||
|
return this.data.migrations;
|
||||||
|
}
|
||||||
|
|
||||||
|
set migrations(data: string[]) {
|
||||||
|
this.data.migrations = data;
|
||||||
|
}
|
||||||
|
|
||||||
get clientId(): string {
|
get clientId(): string {
|
||||||
return this.data.clientId;
|
return this.data.clientId;
|
||||||
}
|
}
|
||||||
|
|||||||
93
server/lib/settings/migrations/0007_migrate_arr_tags.ts
Normal file
93
server/lib/settings/migrations/0007_migrate_arr_tags.ts
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import RadarrAPI from '@server/api/servarr/radarr';
|
||||||
|
import SonarrAPI from '@server/api/servarr/sonarr';
|
||||||
|
import { getRepository } from '@server/datasource';
|
||||||
|
import { User } from '@server/entity/User';
|
||||||
|
import type { AllSettings } from '@server/lib/settings';
|
||||||
|
|
||||||
|
const migrationArrTags = async (settings: any): Promise<AllSettings> => {
|
||||||
|
if (
|
||||||
|
Array.isArray(settings.migrations) &&
|
||||||
|
settings.migrations.includes('0007_migrate_arr_tags')
|
||||||
|
) {
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
const userRepository = getRepository(User);
|
||||||
|
const users = await userRepository.find({
|
||||||
|
select: ['id'],
|
||||||
|
});
|
||||||
|
|
||||||
|
let errorOccurred = false;
|
||||||
|
|
||||||
|
for (const radarrSettings of settings.radarr || []) {
|
||||||
|
if (!radarrSettings.tagRequests) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const radarr = new RadarrAPI({
|
||||||
|
apiKey: radarrSettings.apiKey,
|
||||||
|
url: RadarrAPI.buildUrl(radarrSettings, '/api/v3'),
|
||||||
|
});
|
||||||
|
const radarrTags = await radarr.getTags();
|
||||||
|
for (const user of users) {
|
||||||
|
const userTag = radarrTags.find((v) =>
|
||||||
|
v.label.startsWith(user.id + ' - ')
|
||||||
|
);
|
||||||
|
if (!userTag) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
await radarr.renameTag({
|
||||||
|
id: userTag.id,
|
||||||
|
label: userTag.label.replace(`${user.id} - `, `${user.id}-`),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
`Unable to rename Radarr tags to the new format. Please check your Radarr connection settings for the instance "${radarrSettings.name}".`,
|
||||||
|
error.message
|
||||||
|
);
|
||||||
|
errorOccurred = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const sonarrSettings of settings.sonarr || []) {
|
||||||
|
if (!sonarrSettings.tagRequests) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const sonarr = new SonarrAPI({
|
||||||
|
apiKey: sonarrSettings.apiKey,
|
||||||
|
url: SonarrAPI.buildUrl(sonarrSettings, '/api/v3'),
|
||||||
|
});
|
||||||
|
const sonarrTags = await sonarr.getTags();
|
||||||
|
for (const user of users) {
|
||||||
|
const userTag = sonarrTags.find((v) =>
|
||||||
|
v.label.startsWith(user.id + ' - ')
|
||||||
|
);
|
||||||
|
if (!userTag) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
await sonarr.renameTag({
|
||||||
|
id: userTag.id,
|
||||||
|
label: userTag.label.replace(`${user.id} - `, `${user.id}-`),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
`Unable to rename Sonarr tags to the new format. Please check your Sonarr connection settings for the instance "${sonarrSettings.name}".`,
|
||||||
|
error.message
|
||||||
|
);
|
||||||
|
errorOccurred = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!errorOccurred) {
|
||||||
|
if (!Array.isArray(settings.migrations)) {
|
||||||
|
settings.migrations = [];
|
||||||
|
}
|
||||||
|
settings.migrations.push('0007_migrate_arr_tags');
|
||||||
|
}
|
||||||
|
return settings;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default migrationArrTags;
|
||||||
Reference in New Issue
Block a user