mirror of
https://github.com/sct/overseerr.git
synced 2025-12-31 01:55:53 +01:00
* fix: use fs/promises for settings This PR switches from synchronous operations with the 'fs' module to asynchronous operations with the 'fs/promises' module. It also corrects a small error with hostname migration. * fix: add missing merge function of default and current config * refactor: add more logs to migration
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import JellyfinAPI from '@server/api/jellyfin';
|
|
import { MediaServerType } from '@server/constants/server';
|
|
import { getRepository } from '@server/datasource';
|
|
import { User } from '@server/entity/User';
|
|
import type { AllSettings } from '@server/lib/settings';
|
|
import { getHostname } from '@server/utils/getHostname';
|
|
|
|
const migrateApiTokens = async (settings: any): Promise<AllSettings> => {
|
|
const mediaServerType = settings.main.mediaServerType;
|
|
if (
|
|
!settings.jellyfin.apiKey &&
|
|
(mediaServerType === MediaServerType.JELLYFIN ||
|
|
mediaServerType === MediaServerType.EMBY)
|
|
) {
|
|
const userRepository = getRepository(User);
|
|
const admin = await userRepository.findOne({
|
|
where: { id: 1 },
|
|
select: ['id', 'jellyfinAuthToken', 'jellyfinUserId', 'jellyfinDeviceId'],
|
|
order: { id: 'ASC' },
|
|
});
|
|
if (!admin) {
|
|
return settings;
|
|
}
|
|
const jellyfinClient = new JellyfinAPI(
|
|
getHostname(settings.jellyfin),
|
|
admin.jellyfinAuthToken,
|
|
admin.jellyfinDeviceId
|
|
);
|
|
jellyfinClient.setUserId(admin.jellyfinUserId ?? '');
|
|
try {
|
|
const apiKey = await jellyfinClient.createApiToken('Jellyseerr');
|
|
settings.jellyfin.apiKey = apiKey;
|
|
} catch {
|
|
throw new Error(
|
|
"Failed to create Jellyfin API token from admin account. Please check your network configuration or edit your settings.json by adding an 'apiKey' field inside of the 'jellyfin' section to fix this issue."
|
|
);
|
|
}
|
|
}
|
|
return settings;
|
|
};
|
|
|
|
export default migrateApiTokens;
|