diff --git a/server/server-config/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt b/server/server-config/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt index c2e5fe21f..a922334f9 100644 --- a/server/server-config/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt +++ b/server/server-config/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt @@ -290,7 +290,7 @@ class ServerConfig( @Suppress("UNCHECKED_CAST") (it.unwrapped() as? List) ?.map { - if (it.contains("github")) { + if (it.contains("github.com")) { it.replace(repoMatchRegex) { "https://raw.githubusercontent.com/${it.groupValues[2]}/${it.groupValues[3]}/" + (it.groupValues.getOrNull(4)?.ifBlank { null } ?: "repo") + @@ -304,7 +304,7 @@ class ServerConfig( }, ), readMigrated = { extensionStores.value }, - setMigrated = { extensionStores.value = it }, + setMigrated = { extensionStores.value = (extensionStores.value + it).distinct() }, typeInfo = SettingsRegistry.PartialTypeInfo( specificType = "List", @@ -1118,7 +1118,7 @@ class ServerConfig( val extensionStores: MutableStateFlow> by ListSetting( protoNumber = 97, group = SettingGroup.EXTENSION, - privacySafe = false, + privacySafe = true, defaultValue = emptyList(), itemValidator = { url -> if (url.isNotEmpty()) { @@ -1128,11 +1128,7 @@ class ServerConfig( } }, itemToValidValue = { url -> - if (url.isNotEmpty()) { - url - } else { - null - } + url.ifEmpty { null } }, typeInfo = SettingsRegistry.PartialTypeInfo( diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/ExtensionStoreService.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/ExtensionStoreService.kt index 2eac26d5e..80be16f25 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/ExtensionStoreService.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/ExtensionStoreService.kt @@ -134,7 +134,7 @@ object ExtensionStoreService { transaction { ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl eq oldIndexUrl } } - syncDbToPrefs() + syncDbToPrefs(oldIndexUrl) } store } catch (e: Exception) { @@ -144,7 +144,7 @@ object ExtensionStoreService { } } - fun syncDbToPrefs() { + fun syncDbToPrefs(keepRemoved: String? = null) { val dbStores = transaction { ExtensionStoreTable @@ -154,8 +154,8 @@ object ExtensionStoreService { } val currentPrefs = serverConfig.extensionStores.value.toSet() - val toAdd = dbStores - currentPrefs - val toRemove = currentPrefs - dbStores + val toAdd = (dbStores - currentPrefs - keepRemoved).filterNotNull() + val toRemove = (currentPrefs - dbStores + keepRemoved).filterNotNull() if (toAdd.isNotEmpty()) { serverConfig.extensionStores.value = (serverConfig.extensionStores.value + toAdd).distinct() @@ -180,6 +180,12 @@ object ExtensionStoreService { try { val store = fetch(url) upsert(store) + if (store.indexUrl != url) { + transaction { + ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl eq url } + } + syncDbToPrefs(url) + } } catch (e: Exception) { logger.warn(e) { "Failed to sync preference store '$url' to database" } } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt index ea77725a4..a14fb27eb 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt @@ -525,6 +525,7 @@ fun applicationSetup() { serverConfig.extensionStores, { _ -> ExtensionStoreService.syncPrefsToDb() + ExtensionStoreService.syncDbToPrefs() }, ignoreInitialValue = false, )