-
-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(jellyfin): abstract jellyfin hostname, updated ui to reflect…
… it, better validation (#773) * refactor(jellyfinsettings): abstract jellyfin hostname, updated ui to reflect it, better validation This PR refactors and abstracts jellyfin hostname into, jellyfin ip, jellyfin port, jellyfin useSsl, and jellyfin urlBase. This makes it more consistent with how plex settings are stored as well. In addition, this improves validation as validation can be applied seperately to them instead of as one whole regex doing the work to validate the url. UI was updated to reflect this. BREAKING CHANGE: Jellyfin settings now does not include a hostname. Instead it abstracted it to ip, port, useSsl, and urlBase. However, migration of old settings to new settings should work automatically. * refactor: remove console logs and use getHostname and ApiErrorCodes * fix: store req.body jellyfin settings temporarily and store only if valid This should fix the issue where settings are saved even if the url was invalid. Now the settings will only be saved if the url is valid. Sort of like a test connection. * refactor: clean up commented out code * refactor(i18n): extract translation keys * fix(auth): auth failing with jellyfin login is disabled * fix(settings): jellyfin migrations replacing the rest of the settings * fix(settings): jellyfin hostname should be carried out if hostname exists * fix(settings): merging the wrong settings source * refactor(settings): use migrator for dynamic settings migrations * refactor(settingsmigrator): settings migration handler and the migrations * test(cypress): fix cypress tests failing cypress settings were lacking some of the jobs so when the startJobs() is called when the app starts, it was failing to schedule the jobs where their cron timings were not specified in the cypress settings. Therefore, this commit adds those jobs back. In addition, other setting options were added to keep cypress settings consistent with a normal user. * chore(prettierignore): ignore cypress/config/settings.cypress.json as it does not need prettier * chore(prettier): ran formatter on cypress config to fix format check error format check locally passes on this file. However, it fails during the github actions format check. Therefore, json language features formatter was run instead of prettier to see if that fixes the issue. * test(cypress): add only missing jobs to the cypress settings * ci: attempt at trying to get formatter to pass on cypress config json file * refactor: revert the changes brought to try and fix formatter added back the rest of the cypress settings and removed cypress settings from .prettierignore * refactor(settings): better erorr logging when jellyfin connection test fails in settings page
- Loading branch information
1 parent
a9741fa
commit 38ad875
Showing
16 changed files
with
529 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { AllSettings } from '@server/lib/settings'; | ||
|
||
const migrateHostname = (settings: any): AllSettings => { | ||
const oldJellyfinSettings = settings.jellyfin; | ||
if (oldJellyfinSettings && oldJellyfinSettings.hostname) { | ||
const { hostname } = oldJellyfinSettings; | ||
const protocolMatch = hostname.match(/^(https?):\/\//i); | ||
const useSsl = protocolMatch && protocolMatch[1].toLowerCase() === 'https'; | ||
const remainingUrl = hostname.replace(/^(https?):\/\//i, ''); | ||
const urlMatch = remainingUrl.match(/^([^:]+)(:([0-9]+))?(\/.*)?$/); | ||
|
||
delete oldJellyfinSettings.hostname; | ||
if (urlMatch) { | ||
const [, ip, , port, urlBase] = urlMatch; | ||
settings.jellyfin = { | ||
...settings.jellyfin, | ||
ip, | ||
port: port || (useSsl ? 443 : 80), | ||
useSsl, | ||
urlBase: urlBase ? urlBase.replace(/\/$/, '') : '', | ||
}; | ||
} | ||
} | ||
if (settings.jellyfin && settings.jellyfin.hostname) { | ||
delete settings.jellyfin.hostname; | ||
} | ||
return settings; | ||
}; | ||
|
||
export default migrateHostname; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { AllSettings } from '@server/lib/settings'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
const migrationsDir = path.join(__dirname, 'migrations'); | ||
|
||
export const runMigrations = (settings: AllSettings): AllSettings => { | ||
const migrations = fs | ||
.readdirSync(migrationsDir) | ||
.filter((file) => file.endsWith('.js') || file.endsWith('.ts')) | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
.map((file) => require(path.join(migrationsDir, file)).default); | ||
|
||
let migrated = settings; | ||
|
||
for (const migration of migrations) { | ||
migrated = migration(migrated); | ||
} | ||
|
||
return migrated; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.