Improve Fetch Extension Store

This commit is contained in:
Syer10
2026-06-17 13:31:15 -04:00
parent 74ade8a3a3
commit 3cf4cf6cf8

View File

@@ -49,18 +49,15 @@ object ExtensionStoreService {
): ExtensionStore { ): ExtensionStore {
var updatedIndexUrl = indexUrl var updatedIndexUrl = indexUrl
return try { return try {
val response = network.client.newCall(GET(indexUrl)).awaitSuccess() network.client.newCall(GET(indexUrl)).awaitSuccess().body.source().use { source ->
response.body
.source()
.use { source ->
try { try {
protoBuf.decodeFromByteArray<NetworkExtensionStore>(source.peek().readByteArray()) protoBuf.decodeFromByteArray<NetworkExtensionStore>(source.peek().readByteArray())
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
logger.debug { "Failed to decode as protobuf, trying JSON" } logger.debug { "Failed to decode as protobuf, trying JSON" }
if (forceV2) throw e
try { try {
json.decodeFromBufferedSource<NetworkExtensionStore>(source.peek()) json.decodeFromBufferedSource<NetworkExtensionStore>(source.peek())
} catch (_: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
if (forceV2) throw e
logger.debug { "Failed to decode as NetworkExtensionStore, trying LegacyExtensionRepo" } logger.debug { "Failed to decode as NetworkExtensionStore, trying LegacyExtensionRepo" }
val legacyIndex = val legacyIndex =
try { try {
@@ -69,7 +66,7 @@ object ExtensionStoreService {
if (!indexUrl.endsWith("/index.min.json")) { if (!indexUrl.endsWith("/index.min.json")) {
throw e throw e
} }
logger.debug { "Retrying with /index.min.json" } logger.debug { "Checking for new repo.json format" }
updatedIndexUrl = indexUrl.replace("/index.min.json", "/repo.json") updatedIndexUrl = indexUrl.replace("/index.min.json", "/repo.json")
network.client.newCall(GET(updatedIndexUrl)).awaitSuccess().body.source().use { network.client.newCall(GET(updatedIndexUrl)).awaitSuccess().body.source().use {
json.decodeFromBufferedSource<NetworkLegacyExtensionRepo>(it) json.decodeFromBufferedSource<NetworkLegacyExtensionRepo>(it)
@@ -82,11 +79,11 @@ object ExtensionStoreService {
legacyIndex legacyIndex
} }
} }
}
}.toExtensionStore(updatedIndexUrl) }.toExtensionStore(updatedIndexUrl)
}
} catch (e: Exception) { } catch (e: Exception) {
if (e is CancellationException) throw e if (e is CancellationException) throw e
logger.debug(e) { "Failed to fetch extension store '$indexUrl'" } logger.error(e) { "Failed to fetch extension store '$indexUrl'" }
throw e throw e
} }
} }