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.
This commit is contained in:
KaiserBh 2023-11-19 04:10:16 +11:00
parent 25285e7b66
commit 383bfc5dde

View File

@ -434,11 +434,21 @@ fun PurgeConfirmationDialog(
@Composable @Composable
private fun getSelfHostPreferences(syncPreferences: SyncPreferences): List<Preference> { private fun getSelfHostPreferences(syncPreferences: SyncPreferences): List<Preference> {
val scope = rememberCoroutineScope()
return listOf( return listOf(
Preference.PreferenceItem.EditTextPreference( Preference.PreferenceItem.EditTextPreference(
title = stringResource(R.string.pref_sync_host), title = stringResource(R.string.pref_sync_host),
subtitle = stringResource(R.string.pref_sync_host_summ), subtitle = stringResource(R.string.pref_sync_host_summ),
pref = syncPreferences.syncHost(), 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( Preference.PreferenceItem.EditTextPreference(
title = stringResource(R.string.pref_sync_api_key), title = stringResource(R.string.pref_sync_api_key),