From 383bfc5ddea200a3b0eba8930110c2e3ba6e74b5 Mon Sep 17 00:00:00 2001 From: KaiserBh Date: Sun, 19 Nov 2023 04:10:16 +1100 Subject: [PATCH] refactor: Make sure to remove trim '/' The host url for syncyomi have to be http://[ip]:[port] or https://[url] if there is trailing whitespace or '/' It will error since the api will be called like this https://example//api/download which then return html instead of json since it tries to go to the page instead of hitting the api. --- .../more/settings/screen/SettingsDataScreen.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt index 9a22457da..21525086e 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt @@ -434,11 +434,21 @@ fun PurgeConfirmationDialog( @Composable private fun getSelfHostPreferences(syncPreferences: SyncPreferences): List { + val scope = rememberCoroutineScope() return listOf( Preference.PreferenceItem.EditTextPreference( title = stringResource(R.string.pref_sync_host), subtitle = stringResource(R.string.pref_sync_host_summ), pref = syncPreferences.syncHost(), + onValueChanged = { newValue -> + scope.launch { + // Trim spaces at the beginning and end, then remove trailing slash if present + val trimmedValue = newValue.trim() + val modifiedValue = trimmedValue.trimEnd { it == '/' } + syncPreferences.syncHost().set(modifiedValue) + } + true + }, ), Preference.PreferenceItem.EditTextPreference( title = stringResource(R.string.pref_sync_api_key),