Modern Apps git

← Modern-Apps.git

image: one shared HTTP fetcher instead of eight copies

Commit
8565a496a47410964bf60b9f1125fe843191abc5
Author
Vayun Mathur <[email protected]>
When
2026-11-19 15:48 UTC (16 days ago)
Parents
d3f6e39
appstore, fooddelivery, shop, taxi, travel, uniflix, web and
youpipe each carried a ~40-line RemoteImageFetchers object: the
same http(s)-only URL extraction, IO hop and
NetworkClient.execute + status-check, differing only in comments,
web's (equivalent) scheme predicate, and uniflix's TMDB proxy
fallback.

The shared HttpImageFetcher now lives in library/image/fetchers,
with the transport injected so library/image stays permission-free
and no library-to-library edge appears (#884). NetworkClient gains
getBytes(), the bytes-or-throw form each copy re-derived. Apps
register it in one line; uniflix passes TmdbImageUrl.proxyFor as
the fallback. Per-app fetcher tests moved to a library test
covering decline/fetch/fallback/propagation; other apps' tests
call the shared fetcher directly.

Verified: :library:image:testDebugUnitTest (incl. new tests),
:library:network:compileDebugKotlin, compileDevKotlin and unit
test compilation for all eight apps.

Diff

appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt b/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.ktindex 5cd61964e0..2c993164e7 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt@@ -32,7 +32,7 @@ import com.vayunmathur.appstore.data.ExternalLinks import com.vayunmathur.appstore.data.UpdateCheckWorker import com.vayunmathur.appstore.platform.AppStoreViewModel import com.vayunmathur.appstore.platform.AppStoreViewModelFactory-import com.vayunmathur.appstore.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher import com.vayunmathur.library.image.ImageLoader import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle@@ -58,7 +58,7 @@ class MainActivity : MaActivity() {         // pipeline; the fetch function is built here from NetworkClient so no         // library-to-library edge is needed (#884).         ImageLoader.setDefault(-            ImageLoader.Builder(this).remote(RemoteImageFetchers::network).build(),+            ImageLoader.Builder(this).remote { data, _ -> HttpImageFetcher.fetch(data, NetworkClient::getBytes) }.build(),         )          val repository = AppStoreDatabaseRepository.get(this)
appstore/src/main/java/com/vayunmathur/appstore/data/RemoteImageFetchers.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/RemoteImageFetchers.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/RemoteImageFetchers.ktdeleted file mode 100644index 4bb5425111..0000000000--- a/appstore/src/main/java/com/vayunmathur/appstore/data/RemoteImageFetchers.kt+++ /dev/null@@ -1,39 +0,0 @@-package com.vayunmathur.appstore.data--import android.content.Context-import android.net.Uri-import com.vayunmathur.library.image.fetchers.FetchResult-import com.vayunmathur.library.network.NetworkClient-import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.withContext--/**- * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.- *- * Lives here rather than in a library so no library-to-library edge (and no- * leaked permission) is needed: the store declares INTERNET itself, depends on- * both `:library:image` (the `Fetcher` SPI) and `:library:network`- * (`NetworkClient` with the `STANDARD` bundle), and registers this on its- * `ImageLoader` for remote artwork (`iconUrl`). Returns null for non-HTTP data- * so it composes with the pipeline's local fetchers (#884).- */-object RemoteImageFetchers {-    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {-        val url: String = when (data) {-            is String -> data-            is Uri -> {-                val s = data.scheme-                if (s == "http" || s == "https") data.toString() else return null-            }-            else -> return null-        }-        if (!url.startsWith("http://") && !url.startsWith("https://")) return null-        return withContext(Dispatchers.IO) {-            val resp = NetworkClient.execute(url)-            if (!resp.isSuccess) {-                throw java.io.IOException("HTTP ${resp.status} for $url")-            }-            FetchResult.Bytes(resp.bytes)-        }-    }-}
appstore/src/test/java/com/vayunmathur/appstore/util/RemoteImageFetchersTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/util/RemoteImageFetchersTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/util/RemoteImageFetchersTest.ktdeleted file mode 100644index 331d1c380c..0000000000--- a/appstore/src/test/java/com/vayunmathur/appstore/util/RemoteImageFetchersTest.kt+++ /dev/null@@ -1,34 +0,0 @@-package com.vayunmathur.appstore.util-import com.vayunmathur.appstore.data.RemoteImageFetchers--import android.content.Context-import android.net.Uri-import androidx.test.core.app.ApplicationProvider-import kotlin.test.Test-import kotlin.test.assertNull-import kotlinx.coroutines.runBlocking-import org.junit.runner.RunWith-import org.robolectric.RobolectricTestRunner--/**- * The image fetcher's input contract: only http(s) strings and Uris- * are fetched; everything else (null, non-URL values, other schemes)- * is declined with null so the image pipeline shows its fallback.- * (The fetch itself needs the store's network stack and is not- * exercised offline.)- */-@RunWith(RobolectricTestRunner::class)-class RemoteImageFetchersTest {--    private val context: Context get() = ApplicationProvider.getApplicationContext()--    @Test-    fun `non url inputs are declined`() = runBlocking {-        assertNull(RemoteImageFetchers.network(null, context))-        assertNull(RemoteImageFetchers.network(42, context))-        assertNull(RemoteImageFetchers.network("file:///sdcard/icon.png", context))-        assertNull(RemoteImageFetchers.network("content://icons/1", context))-        assertNull(RemoteImageFetchers.network(Uri.parse("file:///sdcard/icon.png"), context))-        assertNull(RemoteImageFetchers.network(Uri.parse("android.resource://x/1"), context))-    }-}
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/RemoteImageFetchers.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/RemoteImageFetchers.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/RemoteImageFetchers.ktdeleted file mode 100644index dd567ab6e3..0000000000--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/RemoteImageFetchers.kt+++ /dev/null@@ -1,39 +0,0 @@-package com.vayunmathur.fooddelivery.data--import android.content.Context-import android.net.Uri-import com.vayunmathur.library.image.fetchers.FetchResult-import com.vayunmathur.library.network.NetworkClient-import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.withContext--/**- * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.- *- * Lives here rather than in a library so no library-to-library edge (and no- * leaked permission) is needed: fooddelivery declares INTERNET itself, depends- * on both `:library:image` (the `Fetcher` SPI) and `:library:network`- * (`NetworkClient` with the `STANDARD` bundle), and registers this on its- * `ImageLoader` for merchant/restaurant photos. Returns null for non-HTTP data- * so it composes with the pipeline's local fetchers (#884).- */-object RemoteImageFetchers {-    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {-        val url: String = when (data) {-            is String -> data-            is Uri -> {-                val s = data.scheme-                if (s == "http" || s == "https") data.toString() else return null-            }-            else -> return null-        }-        if (!url.startsWith("http://") && !url.startsWith("https://")) return null-        return withContext(Dispatchers.IO) {-            val resp = NetworkClient.execute(url)-            if (!resp.isSuccess) {-                throw java.io.IOException("HTTP ${resp.status} for $url")-            }-            FetchResult.Bytes(resp.bytes)-        }-    }-}
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/platform/AppInit.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/platform/AppInit.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/platform/AppInit.ktindex e382c530d5..92530240a3 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/platform/AppInit.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/platform/AppInit.kt@@ -1,7 +1,7 @@ package com.vayunmathur.fooddelivery.platform  import android.content.Context-import com.vayunmathur.fooddelivery.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher import com.vayunmathur.library.image.ImageLoader import com.vayunmathur.library.log.Log import androidx.core.content.edit@@ -42,7 +42,7 @@ object AppInit {         // the fetch function is built here from NetworkClient so no         // library-to-library edge is needed (#884).         ImageLoader.setDefault(-            ImageLoader.Builder(appCtx).remote(RemoteImageFetchers::network).build(),+            ImageLoader.Builder(appCtx).remote { data, _ -> HttpImageFetcher.fetch(data, NetworkClient::getBytes) }.build(),         )         scope.launch {             // Kept in separate try blocks: a trust-bundle failure must not also skip the token
fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow5Test.kt
diff --git a/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow5Test.kt b/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow5Test.ktindex 50c06ee2e9..9b2185a04d 100644--- a/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow5Test.kt+++ b/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow5Test.kt@@ -20,7 +20,8 @@ import com.vayunmathur.fooddelivery.data.CartItem import com.vayunmathur.fooddelivery.data.MenuItem import com.vayunmathur.fooddelivery.data.Modifier import com.vayunmathur.fooddelivery.data.ModifierGroup-import com.vayunmathur.fooddelivery.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher+import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.fooddelivery.data.SavedAddress import com.vayunmathur.fooddelivery.data.SelectedModifier import com.vayunmathur.fooddelivery.platform.AppInit@@ -169,12 +170,12 @@ class FoodFlow5Test {     }      @Test fun remoteImageFetcherSchemeGuards() { runBlocking {-        assertNull(RemoteImageFetchers.network(null, ctx))-        assertNull(RemoteImageFetchers.network(42, ctx))-        assertNull(RemoteImageFetchers.network("ftp://example.com/x.png", ctx))-        assertNull(RemoteImageFetchers.network(Uri.parse("file:///tmp/x.png"), ctx))+        assertNull(HttpImageFetcher.fetch(null, NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(42, NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch("ftp://example.com/x.png", NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(Uri.parse("file:///tmp/x.png"), NetworkClient::getBytes))         // Loopback refusal is deterministic on any machine (no external network).-        val refused = runCatching { RemoteImageFetchers.network("http://127.0.0.1:9/x.png", ctx) }+        val refused = runCatching { HttpImageFetcher.fetch("http://127.0.0.1:9/x.png", NetworkClient::getBytes) }             .exceptionOrNull()         assertTrue(refused is java.io.IOException, "expected loopback refusal, got $refused")     } }
library/image/src/main/java/com/vayunmathur/library/image/ImageLoader.kt
diff --git a/library/image/src/main/java/com/vayunmathur/library/image/ImageLoader.kt b/library/image/src/main/java/com/vayunmathur/library/image/ImageLoader.ktindex 23fd743b3d..cdbfb40ee2 100644--- a/library/image/src/main/java/com/vayunmathur/library/image/ImageLoader.kt+++ b/library/image/src/main/java/com/vayunmathur/library/image/ImageLoader.kt@@ -425,7 +425,7 @@ class ImageLoader private constructor(          *          * ```          * ImageLoader.Builder(context)-         *     .remote { data, _ -> RemoteImageFetchers.network(data) }+         *     .remote { data, _ -> HttpImageFetcher.fetch(data, transport) }          *     .build()          * ```          *
library/image/src/main/java/com/vayunmathur/library/image/fetchers/HttpImageFetcher.kt
diff --git a/library/image/src/main/java/com/vayunmathur/library/image/fetchers/HttpImageFetcher.kt b/library/image/src/main/java/com/vayunmathur/library/image/fetchers/HttpImageFetcher.ktnew file mode 100644index 0000000000..e11d56f3ec--- /dev/null+++ b/library/image/src/main/java/com/vayunmathur/library/image/fetchers/HttpImageFetcher.kt@@ -0,0 +1,60 @@+package com.vayunmathur.library.image.fetchers++import android.net.Uri+import kotlinx.coroutines.CancellationException+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext++/**+ * HTTP(S) source for the shared image pipeline, shared by every app that+ * loads remote artwork.+ *+ * This used to be copied per app as a `RemoteImageFetchers` object (eight+ * near-identical copies, ~40 lines each). The one part that genuinely+ * differs per app is the transport, so it is injected: the app hands in+ * its `NetworkClient` bytes call (it already depends on+ * `:library:network` and declares INTERNET itself), and everything else โ€”+ * which data counts as remote, the IO hop, the fallback retry โ€” lives+ * here. This module stays permission-free: no network code is linked+ * into offline consumers of the pipeline (#884).+ *+ * Returns null for data that is not an http(s) URL so it composes with+ * the pipeline's local fetchers. A failed fetch throws; pass+ * [fallbackUrl] for sources with a mirror/proxy form of the same URL+ * (uniflix's TMDB proxy) and the fallback is tried once before the+ * failure propagates.+ */+object HttpImageFetcher {++    suspend fun fetch(+        data: Any?,+        transport: suspend (String) -> ByteArray,+        fallbackUrl: (String) -> String? = { null },+    ): FetchResult? {+        val url: String = when (data) {+            is String -> data+            is Uri -> {+                val scheme = data.scheme+                if (isHttpScheme(scheme)) data.toString() else return null+            }+            else -> return null+        }+        if (!isHttpUrl(url)) return null+        return withContext(Dispatchers.IO) {+            val bytes = try {+                transport(url)+            } catch (failure: Throwable) {+                if (failure is CancellationException) throw failure+                val fallback = fallbackUrl(url) ?: throw failure+                transport(fallback)+            }+            FetchResult.Bytes(bytes)+        }+    }++    private fun isHttpScheme(scheme: String?): Boolean =+        scheme.equals("http", ignoreCase = true) || scheme.equals("https", ignoreCase = true)++    private fun isHttpUrl(url: String): Boolean =+        url.startsWith("http://", ignoreCase = true) || url.startsWith("https://", ignoreCase = true)+}
library/image/src/test/java/com/vayunmathur/library/image/HttpImageFetcherTest.kt
diff --git a/library/image/src/test/java/com/vayunmathur/library/image/HttpImageFetcherTest.kt b/library/image/src/test/java/com/vayunmathur/library/image/HttpImageFetcherTest.ktnew file mode 100644index 0000000000..c0142b9e99--- /dev/null+++ b/library/image/src/test/java/com/vayunmathur/library/image/HttpImageFetcherTest.kt@@ -0,0 +1,87 @@+package com.vayunmathur.library.image++import android.net.Uri+import com.vayunmathur.library.image.fetchers.FetchResult+import com.vayunmathur.library.image.fetchers.HttpImageFetcher+import kotlinx.coroutines.runBlocking+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import java.io.IOException+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFailsWith+import kotlin.test.assertNull+import kotlin.test.assertTrue++/**+ * The shared HTTP image fetcher's contract (formerly copied into eight+ * apps as `RemoteImageFetchersTest`): only http(s) strings and Uris are+ * fetched, everything else is declined with null, and a failing primary+ * URL is retried once through the fallback form when one is provided.+ */+@RunWith(RobolectricTestRunner::class)+class HttpImageFetcherTest {++    private val unusedTransport: suspend (String) -> ByteArray =+        { throw AssertionError("transport must not be called for declined data: $it") }++    @Test+    fun `non url inputs are declined`() = runBlocking {+        assertNull(HttpImageFetcher.fetch(null, unusedTransport))+        assertNull(HttpImageFetcher.fetch(42, unusedTransport))+        assertNull(HttpImageFetcher.fetch("file:///sdcard/icon.png", unusedTransport))+        assertNull(HttpImageFetcher.fetch("content://icons/1", unusedTransport))+        assertNull(HttpImageFetcher.fetch("ftp://example.com/x.png", unusedTransport))+        assertNull(HttpImageFetcher.fetch("", unusedTransport))+        assertNull(HttpImageFetcher.fetch(Uri.parse("file:///sdcard/icon.png"), unusedTransport))+        assertNull(HttpImageFetcher.fetch(Uri.parse("android.resource://x/1"), unusedTransport))+    }++    @Test+    fun `http string and uri are fetched through the transport`() = runBlocking {+        val seen = mutableListOf<String>()+        val transport: suspend (String) -> ByteArray = { url ->+            seen += url+            byteArrayOf(1, 2, 3)+        }+        val fromString = HttpImageFetcher.fetch("https://example.com/a.png", transport)+        val fromUri = HttpImageFetcher.fetch(Uri.parse("http://example.com/b.png"), transport)+        assertEquals(listOf("https://example.com/a.png", "http://example.com/b.png"), seen)+        assertTrue(fromString is FetchResult.Bytes && fromString.bytes.contentEquals(byteArrayOf(1, 2, 3)))+        assertTrue(fromUri is FetchResult.Bytes)+    }++    @Test+    fun `fallback url is tried once after a primary failure`() = runBlocking {+        val seen = mutableListOf<String>()+        val transport: suspend (String) -> ByteArray = { url ->+            seen += url+            if (url.contains("static")) throw IOException("HTTP 404 for $url")+            byteArrayOf(9)+        }+        val result = HttpImageFetcher.fetch(+            "https://static.example.com/tmdb/w342/x.jpg",+            transport,+        ) { url -> url.replace("static", "proxy") }+        assertEquals(+            listOf(+                "https://static.example.com/tmdb/w342/x.jpg",+                "https://proxy.example.com/tmdb/w342/x.jpg",+            ),+            seen,+        )+        assertTrue(result is FetchResult.Bytes && result.bytes.contentEquals(byteArrayOf(9)))+    }++    @Test+    fun `failure propagates when no fallback applies`() {+        runBlocking {+            assertFailsWith<IOException> {+                HttpImageFetcher.fetch(+                    "https://example.com/x.png",+                    transport = { throw IOException("HTTP 404 for it") },+                )+            }+        }+    }+}
library/network/src/main/java/com/vayunmathur/library/network/NetworkClient.kt
diff --git a/library/network/src/main/java/com/vayunmathur/library/network/NetworkClient.kt b/library/network/src/main/java/com/vayunmathur/library/network/NetworkClient.ktindex 7f1f6d272f..349aafbd3b 100644--- a/library/network/src/main/java/com/vayunmathur/library/network/NetworkClient.kt+++ b/library/network/src/main/java/com/vayunmathur/library/network/NetworkClient.kt@@ -328,6 +328,24 @@ object NetworkClient {         return RawResponse(r.status, r.statusMessage, r.bodyBytes, r.headers, r.finalUrl)     } +    /**+     * GET [url] and return the response body, throwing [java.io.IOException]+     * on a non-success status.+     *+     * The bytes-or-throw shape the image pipeline's shared+     * `HttpImageFetcher` (in `:library:image`) takes as its transport, and+     * what the eight per-app `RemoteImageFetchers` copies each re-derived+     * from [execute]. Kept here so the status-to-exception mapping exists+     * once; callers that need headers or the status itself use [execute].+     */+    suspend fun getBytes(url: String): ByteArray {+        val response = execute(url)+        if (!response.isSuccess) {+            throw java.io.IOException("HTTP ${response.status} for $url")+        }+        return response.bytes+    }+     // ------------------------------------------------------------------     // Streaming variants     // ------------------------------------------------------------------
shop/src/main/java/com/vayunmathur/shop/data/RemoteImageFetchers.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/data/RemoteImageFetchers.kt b/shop/src/main/java/com/vayunmathur/shop/data/RemoteImageFetchers.ktdeleted file mode 100644index 37848cbd8c..0000000000--- a/shop/src/main/java/com/vayunmathur/shop/data/RemoteImageFetchers.kt+++ /dev/null@@ -1,39 +0,0 @@-package com.vayunmathur.shop.data--import android.content.Context-import android.net.Uri-import com.vayunmathur.library.image.fetchers.FetchResult-import com.vayunmathur.library.network.NetworkClient-import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.withContext--/**- * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.- *- * Lives here rather than in a library so no library-to-library edge (and no- * leaked permission) is needed: shop declares INTERNET itself, depends on- * both `:library:image` (the `Fetcher` SPI) and `:library:network`- * (`NetworkClient`), and registers this on its `ImageLoader` for product- * photos. Returns null for non-HTTP data so it composes with the pipeline's- * local fetchers (#884).- */-object RemoteImageFetchers {-    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {-        val url: String = when (data) {-            is String -> data-            is Uri -> {-                val s = data.scheme-                if (s == "http" || s == "https") data.toString() else return null-            }-            else -> return null-        }-        if (!url.startsWith("http://") && !url.startsWith("https://")) return null-        return withContext(Dispatchers.IO) {-            val resp = NetworkClient.execute(url)-            if (!resp.isSuccess) {-                throw java.io.IOException("HTTP ${resp.status} for $url")-            }-            FetchResult.Bytes(resp.bytes)-        }-    }-}
shop/src/main/java/com/vayunmathur/shop/platform/AppInit.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/platform/AppInit.kt b/shop/src/main/java/com/vayunmathur/shop/platform/AppInit.ktindex cef245c87e..b2cbc5c3cf 100644--- a/shop/src/main/java/com/vayunmathur/shop/platform/AppInit.kt+++ b/shop/src/main/java/com/vayunmathur/shop/platform/AppInit.kt@@ -5,7 +5,7 @@ import com.vayunmathur.library.image.ImageLoader import com.vayunmathur.library.log.Log import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle-import com.vayunmathur.shop.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers@@ -35,7 +35,7 @@ object AppInit {         // the fetch function is built here from NetworkClient so no         // library-to-library edge is needed (#884).         ImageLoader.setDefault(-            ImageLoader.Builder(appCtx).remote(RemoteImageFetchers::network).build(),+            ImageLoader.Builder(appCtx).remote { data, _ -> HttpImageFetcher.fetch(data, NetworkClient::getBytes) }.build(),         )         scope.launch {             try {
shop/src/test/java/com/vayunmathur/shop/platform/ShopPlatformCoverageTest.kt
diff --git a/shop/src/test/java/com/vayunmathur/shop/platform/ShopPlatformCoverageTest.kt b/shop/src/test/java/com/vayunmathur/shop/platform/ShopPlatformCoverageTest.ktindex 8a2f42e88c..9bb7039c1b 100644--- a/shop/src/test/java/com/vayunmathur/shop/platform/ShopPlatformCoverageTest.kt+++ b/shop/src/test/java/com/vayunmathur/shop/platform/ShopPlatformCoverageTest.kt@@ -10,7 +10,8 @@ import com.vayunmathur.shop.R import com.vayunmathur.shop.data.Money import com.vayunmathur.shop.data.OrderTracking import com.vayunmathur.shop.data.PlacedOrder-import com.vayunmathur.shop.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher+import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.shop.data.ShopProfile import kotlin.test.BeforeTest import kotlin.test.Test@@ -71,12 +72,12 @@ class ShopPlatformCoverageTest {     }      @Test fun remoteImageFetcherRejectsNonHttpInputs() = runBlocking {-        assertNull(RemoteImageFetchers.network(null, context))-        assertNull(RemoteImageFetchers.network(123, context))-        assertNull(RemoteImageFetchers.network(Uri.parse("file:///tmp/x.png"), context))-        assertNull(RemoteImageFetchers.network(Uri.parse("content://media/1"), context))-        assertNull(RemoteImageFetchers.network("ftp://example.com/x.png", context))-        assertNull(RemoteImageFetchers.network("", context))+        assertNull(HttpImageFetcher.fetch(null, NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(123, NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(Uri.parse("file:///tmp/x.png"), NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(Uri.parse("content://media/1"), NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch("ftp://example.com/x.png", NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch("", NetworkClient::getBytes))         Unit     } 
taxi/src/main/java/com/vayunmathur/taxi/MainActivity.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/MainActivity.kt b/taxi/src/main/java/com/vayunmathur/taxi/MainActivity.ktindex ecba1267ec..7395f8e48f 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/MainActivity.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/MainActivity.kt@@ -14,7 +14,7 @@ import com.vayunmathur.library.network.TrustBundle import com.vayunmathur.library.ui.MaActivity import com.vayunmathur.library.util.IntentLauncher import com.vayunmathur.taxi.data.BookingTrip-import com.vayunmathur.taxi.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher import com.vayunmathur.taxi.intents.RideHandoffContract import com.vayunmathur.taxi.notifications.RideLiveUpdate @@ -46,7 +46,7 @@ class MainActivity : MaActivity() {         // the fetch function is built here from NetworkClient so no         // library-to-library edge is needed (#884).         ImageLoader.setDefault(-            ImageLoader.Builder(this).remote(RemoteImageFetchers::network).build(),+            ImageLoader.Builder(this).remote { data, _ -> HttpImageFetcher.fetch(data, NetworkClient::getBytes) }.build(),         )         intentLauncher = IntentLauncher(this) 
taxi/src/main/java/com/vayunmathur/taxi/data/RemoteImageFetchers.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/data/RemoteImageFetchers.kt b/taxi/src/main/java/com/vayunmathur/taxi/data/RemoteImageFetchers.ktdeleted file mode 100644index ebb6e7df82..0000000000--- a/taxi/src/main/java/com/vayunmathur/taxi/data/RemoteImageFetchers.kt+++ /dev/null@@ -1,39 +0,0 @@-package com.vayunmathur.taxi.data--import android.content.Context-import android.net.Uri-import com.vayunmathur.library.image.fetchers.FetchResult-import com.vayunmathur.library.network.NetworkClient-import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.withContext--/**- * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.- *- * Lives here rather than in a library so no library-to-library edge (and no- * leaked permission) is needed: taxi declares INTERNET itself, depends on- * both `:library:image` (the `Fetcher` SPI) and `:library:network`- * (`NetworkClient` with the `STANDARD` bundle), and registers this on its- * `ImageLoader` for driver photos. Returns null for non-HTTP data so it- * composes with the pipeline's local fetchers (#884).- */-object RemoteImageFetchers {-    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {-        val url: String = when (data) {-            is String -> data-            is Uri -> {-                val s = data.scheme-                if (s == "http" || s == "https") data.toString() else return null-            }-            else -> return null-        }-        if (!url.startsWith("http://") && !url.startsWith("https://")) return null-        return withContext(Dispatchers.IO) {-            val resp = NetworkClient.execute(url)-            if (!resp.isSuccess) {-                throw java.io.IOException("HTTP ${resp.status} for $url")-            }-            FetchResult.Bytes(resp.bytes)-        }-    }-}
taxi/src/test/java/com/vayunmathur/taxi/Y3TaxiCoreTest.kt
diff --git a/taxi/src/test/java/com/vayunmathur/taxi/Y3TaxiCoreTest.kt b/taxi/src/test/java/com/vayunmathur/taxi/Y3TaxiCoreTest.ktindex 1806764dd0..5b21971a0b 100644--- a/taxi/src/test/java/com/vayunmathur/taxi/Y3TaxiCoreTest.kt+++ b/taxi/src/test/java/com/vayunmathur/taxi/Y3TaxiCoreTest.kt@@ -24,7 +24,8 @@ import com.vayunmathur.taxi.data.PaymentMethodsResult import com.vayunmathur.taxi.data.Place import com.vayunmathur.taxi.data.Provider import com.vayunmathur.taxi.data.QuoteResult-import com.vayunmathur.taxi.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher+import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.taxi.data.RideQuote import com.vayunmathur.taxi.data.RideStatusResult import com.vayunmathur.taxi.data.lyft.LyftTokenStore@@ -95,11 +96,11 @@ class Y3TaxiCoreTest {     }      @Test fun remoteImageFetcherRejectsNonHttp() : Unit = runBlocking {-        assertNull(RemoteImageFetchers.network(null, ctx))-        assertNull(RemoteImageFetchers.network(42, ctx))-        assertNull(RemoteImageFetchers.network("ftp://x/y.png", ctx))-        assertNull(RemoteImageFetchers.network(Uri.parse("file:///tmp/x.png"), ctx))-        assertNull(RemoteImageFetchers.network(Uri.parse("content://media/1"), ctx))+        assertNull(HttpImageFetcher.fetch(null, NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(42, NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch("ftp://x/y.png", NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(Uri.parse("file:///tmp/x.png"), NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(Uri.parse("content://media/1"), NetworkClient::getBytes))     }      @Test fun locationProviderWithoutPermission() : Unit = runBlocking {
travel/src/main/java/com/vayunmathur/travel/MainActivity.kt
diff --git a/travel/src/main/java/com/vayunmathur/travel/MainActivity.kt b/travel/src/main/java/com/vayunmathur/travel/MainActivity.ktindex 30ed3bfaf8..ce26806254 100644--- a/travel/src/main/java/com/vayunmathur/travel/MainActivity.kt+++ b/travel/src/main/java/com/vayunmathur/travel/MainActivity.kt@@ -8,7 +8,7 @@ import androidx.compose.runtime.setValue import androidx.lifecycle.lifecycleScope import com.vayunmathur.library.ui.MaActivity import com.vayunmathur.travel.data.TravelRepository-import com.vayunmathur.travel.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher import com.vayunmathur.travel.platform.TravelViewModel import com.vayunmathur.travel.platform.TravelViewModelFactory import com.vayunmathur.travel.platform.pendingTripIds@@ -37,7 +37,7 @@ class MainActivity : MaActivity() {         // pipeline; the fetch function is built here from NetworkClient so no         // library-to-library edge is needed (#884).         ImageLoader.setDefault(-            ImageLoader.Builder(this).remote(RemoteImageFetchers::network).build(),+            ImageLoader.Builder(this).remote { data, _ -> HttpImageFetcher.fetch(data, NetworkClient::getBytes) }.build(),         )          lifecycleScope.launch(Dispatchers.IO) {
travel/src/main/java/com/vayunmathur/travel/data/RemoteImageFetchers.kt
diff --git a/travel/src/main/java/com/vayunmathur/travel/data/RemoteImageFetchers.kt b/travel/src/main/java/com/vayunmathur/travel/data/RemoteImageFetchers.ktdeleted file mode 100644index 0f8ffa3cb3..0000000000--- a/travel/src/main/java/com/vayunmathur/travel/data/RemoteImageFetchers.kt+++ /dev/null@@ -1,39 +0,0 @@-package com.vayunmathur.travel.data--import android.content.Context-import android.net.Uri-import com.vayunmathur.library.image.fetchers.FetchResult-import com.vayunmathur.library.network.NetworkClient-import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.withContext--/**- * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.- *- * Lives here rather than in a library so no library-to-library edge (and no- * leaked permission) is needed: travel declares INTERNET itself, depends on- * both `:library:image` (the `Fetcher` SPI) and `:library:network`- * (`NetworkClient`), and registers this on its `ImageLoader` for destination- * and stay photos. Returns null for non-HTTP data so it composes with the- * pipeline's local fetchers (#884).- */-object RemoteImageFetchers {-    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {-        val url: String = when (data) {-            is String -> data-            is Uri -> {-                val s = data.scheme-                if (s == "http" || s == "https") data.toString() else return null-            }-            else -> return null-        }-        if (!url.startsWith("http://") && !url.startsWith("https://")) return null-        return withContext(Dispatchers.IO) {-            val resp = NetworkClient.execute(url)-            if (!resp.isSuccess) {-                throw java.io.IOException("HTTP ${resp.status} for $url")-            }-            FetchResult.Bytes(resp.bytes)-        }-    }-}
uniflix/src/main/java/com/vayunmathur/uniflix/MainActivity.kt
diff --git a/uniflix/src/main/java/com/vayunmathur/uniflix/MainActivity.kt b/uniflix/src/main/java/com/vayunmathur/uniflix/MainActivity.ktindex db78d8dabd..0e6d194bc5 100644--- a/uniflix/src/main/java/com/vayunmathur/uniflix/MainActivity.kt+++ b/uniflix/src/main/java/com/vayunmathur/uniflix/MainActivity.kt@@ -5,7 +5,8 @@ import com.vayunmathur.library.image.ImageLoader import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle import com.vayunmathur.library.ui.MaActivity-import com.vayunmathur.uniflix.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher+import com.vayunmathur.uniflix.data.TmdbImageUrl  /** Main Activity: a ma activity implementation for main activity. */ class MainActivity : MaActivity() {@@ -17,7 +18,7 @@ class MainActivity : MaActivity() {         // the fetch function is built here from NetworkClient so no         // library-to-library edge is needed (#884).         ImageLoader.setDefault(-            ImageLoader.Builder(this).remote(RemoteImageFetchers::network).build(),+            ImageLoader.Builder(this).remote { data, _ -> HttpImageFetcher.fetch(data, NetworkClient::getBytes, TmdbImageUrl::proxyFor) }.build(),         )     } 
uniflix/src/main/java/com/vayunmathur/uniflix/data/RemoteImageFetchers.kt
diff --git a/uniflix/src/main/java/com/vayunmathur/uniflix/data/RemoteImageFetchers.kt b/uniflix/src/main/java/com/vayunmathur/uniflix/data/RemoteImageFetchers.ktdeleted file mode 100644index dd944978d7..0000000000--- a/uniflix/src/main/java/com/vayunmathur/uniflix/data/RemoteImageFetchers.kt+++ /dev/null@@ -1,46 +0,0 @@-package com.vayunmathur.uniflix.data--import android.content.Context-import android.net.Uri-import com.vayunmathur.library.image.fetchers.FetchResult-import com.vayunmathur.library.network.NetworkClient-import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.withContext--/**- * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.- *- * Lives here rather than in a library so no library-to-library edge (and no- * leaked permission) is needed: uniflix declares INTERNET itself, depends on- * both `:library:image` (the `Fetcher` SPI) and `:library:network`- * (`NetworkClient` with the `STANDARD` bundle), and registers this on its- * `ImageLoader` for catalog/stremio artwork. Returns null for non-HTTP data- * so it composes with the pipeline's local fetchers (#884).- */-object RemoteImageFetchers {-    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {-        val url: String = when (data) {-            is String -> data-            is Uri -> {-                val s = data.scheme-                if (s == "http" || s == "https") data.toString() else return null-            }-            else -> return null-        }-        if (!url.startsWith("http://") && !url.startsWith("https://")) return null-        return withContext(Dispatchers.IO) {-            var resp = runCatching { NetworkClient.execute(url) }-            // TMDB artwork is read from its static R2 copy first; one that does not-            // exist yet (or an unreachable static host) falls back to the image proxy.-            val proxy = TmdbImageUrl.proxyFor(url)-            if (proxy != null && resp.getOrNull()?.isSuccess != true) {-                resp = runCatching { NetworkClient.execute(proxy) }-            }-            val ok = resp.getOrThrow()-            if (!ok.isSuccess) {-                throw java.io.IOException("HTTP ${ok.status} for ${proxy ?: url}")-            }-            FetchResult.Bytes(ok.bytes)-        }-    }-}
uniflix/src/main/java/com/vayunmathur/uniflix/data/TmdbImageUrl.kt
diff --git a/uniflix/src/main/java/com/vayunmathur/uniflix/data/TmdbImageUrl.kt b/uniflix/src/main/java/com/vayunmathur/uniflix/data/TmdbImageUrl.ktindex cc6b462213..acfa20432e 100644--- a/uniflix/src/main/java/com/vayunmathur/uniflix/data/TmdbImageUrl.kt+++ b/uniflix/src/main/java/com/vayunmathur/uniflix/data/TmdbImageUrl.kt@@ -6,7 +6,7 @@ import com.vayunmathur.library.network.StaticMirror  * TMDB artwork โ€” no direct image.tmdb.org. Sizes: w185/w342 cards, w500 search, original hero.  *  * URLs point at the server's static copy on R2 (images are content-addressed, so a copy- * never goes stale); [RemoteImageFetchers] falls back to the self-hosted image proxy+ * never goes stale); the shared image fetcher falls back to the self-hosted image proxy  * ([proxyFor]) when the copy does not exist yet, and the proxy then creates it.  */ object TmdbImageUrl {
uniflix/src/test/java/com/vayunmathur/uniflix/ui/tv/TvPickersAndPrefsTest.kt
diff --git a/uniflix/src/test/java/com/vayunmathur/uniflix/ui/tv/TvPickersAndPrefsTest.kt b/uniflix/src/test/java/com/vayunmathur/uniflix/ui/tv/TvPickersAndPrefsTest.ktindex 902ff03302..80d68c4acb 100644--- a/uniflix/src/test/java/com/vayunmathur/uniflix/ui/tv/TvPickersAndPrefsTest.kt+++ b/uniflix/src/test/java/com/vayunmathur/uniflix/ui/tv/TvPickersAndPrefsTest.kt@@ -10,7 +10,8 @@ import androidx.test.core.app.ApplicationProvider import com.vayunmathur.library.ui.DynamicTheme import com.vayunmathur.uniflix.data.AddonEntity import com.vayunmathur.uniflix.data.AddonPrefs-import com.vayunmathur.uniflix.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher+import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.uniflix.domain.SubtitleTrack import com.vayunmathur.uniflix.platform.AddonRow import kotlin.test.Test@@ -131,12 +132,12 @@ class TvPickersAndPrefsTest {     }      @Test fun remoteFetcherRejectsNonHttpData() = runTest {-        assertNull(RemoteImageFetchers.network(null, context))-        assertNull(RemoteImageFetchers.network(42, context))-        assertNull(RemoteImageFetchers.network("file:///tmp/x.png", context))-        assertNull(RemoteImageFetchers.network(Uri.parse("content://media/1"), context))-        assertNull(RemoteImageFetchers.network(Uri.parse("file:///tmp/x.png"), context))+        assertNull(HttpImageFetcher.fetch(null, NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(42, NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch("file:///tmp/x.png", NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(Uri.parse("content://media/1"), NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(Uri.parse("file:///tmp/x.png"), NetworkClient::getBytes))         // An unreachable https URL fails (throw or IOException), never returns bytes.-        assertTrue(runCatching { RemoteImageFetchers.network("https://addons.invalid/x.png", context) }.isFailure)+        assertTrue(runCatching { HttpImageFetcher.fetch("https://addons.invalid/x.png", NetworkClient::getBytes) }.isFailure)     } }
web/src/main/java/com/vayunmathur/web/MainActivity.kt
diff --git a/web/src/main/java/com/vayunmathur/web/MainActivity.kt b/web/src/main/java/com/vayunmathur/web/MainActivity.ktindex 9f346835e9..f32574a273 100644--- a/web/src/main/java/com/vayunmathur/web/MainActivity.kt+++ b/web/src/main/java/com/vayunmathur/web/MainActivity.kt@@ -18,7 +18,7 @@ import com.vayunmathur.library.network.TrustBundle import com.vayunmathur.library.ui.MaActivity import com.vayunmathur.library.util.OfflineAware import com.vayunmathur.web.data.FaviconStore-import com.vayunmathur.web.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher import com.vayunmathur.web.data.TabThumbnailStore import com.vayunmathur.web.data.WebRepository import com.vayunmathur.web.platform.BrowserTab@@ -47,7 +47,7 @@ class MainActivity : MaActivity() {         // shared image pipeline; the fetch function is built here from         // NetworkClient so no library-to-library edge is needed (#884).         ImageLoader.setDefault(-            ImageLoader.Builder(this).remote(RemoteImageFetchers::network).build(),+            ImageLoader.Builder(this).remote { data, _ -> HttpImageFetcher.fetch(data, NetworkClient::getBytes) }.build(),         )         // Parses ~8 MB of filter lists off the main thread. Shields fail open until it lands.         lifecycleScope.launch { ShieldsEngine.load(applicationContext) }
web/src/main/java/com/vayunmathur/web/data/RemoteImageFetchers.kt
diff --git a/web/src/main/java/com/vayunmathur/web/data/RemoteImageFetchers.kt b/web/src/main/java/com/vayunmathur/web/data/RemoteImageFetchers.ktdeleted file mode 100644index 0ee4d2d5a9..0000000000--- a/web/src/main/java/com/vayunmathur/web/data/RemoteImageFetchers.kt+++ /dev/null@@ -1,41 +0,0 @@-package com.vayunmathur.web.data--import android.content.Context-import android.net.Uri-import com.vayunmathur.library.image.fetchers.FetchResult-import com.vayunmathur.library.network.NetworkClient-import com.vayunmathur.web.platform.BrowserUtils-import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.withContext--/**- * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.- *- * Lives here rather than in a library so no library-to-library edge (and no- * leaked permission) is needed: the browser declares INTERNET itself, depends- * on both `:library:image` (the `Fetcher` SPI) and `:library:network`- * (`NetworkClient` with the `SYSTEM` bundle for user-entered hosts), and- * registers this on its `ImageLoader` for search-result thumbnails and PWA- * icon fetches. Returns null for non-HTTP data so it composes with the- * pipeline's local fetchers (#884).- */-object RemoteImageFetchers {-    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {-        val url: String = when (data) {-            is String -> data-            is Uri -> {-                val s = data.scheme-                if (BrowserUtils.isWebScheme(s)) data.toString() else return null-            }-            else -> return null-        }-        if (!BrowserUtils.isWebUrl(url)) return null-        return withContext(Dispatchers.IO) {-            val resp = NetworkClient.execute(url)-            if (!resp.isSuccess) {-                throw java.io.IOException("HTTP ${resp.status} for $url")-            }-            FetchResult.Bytes(resp.bytes)-        }-    }-}
web/src/test/java/com/vayunmathur/web/ui/MiscDeepTest.kt
diff --git a/web/src/test/java/com/vayunmathur/web/ui/MiscDeepTest.kt b/web/src/test/java/com/vayunmathur/web/ui/MiscDeepTest.ktindex a26a8a2e60..4b26a3dd1f 100644--- a/web/src/test/java/com/vayunmathur/web/ui/MiscDeepTest.kt+++ b/web/src/test/java/com/vayunmathur/web/ui/MiscDeepTest.kt@@ -17,7 +17,8 @@ import com.vayunmathur.web.Route import com.vayunmathur.web.data.FaviconStore import com.vayunmathur.web.data.HistoryEntry import com.vayunmathur.web.data.InstalledSite-import com.vayunmathur.web.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher+import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.web.data.TabThumbnailStore import com.vayunmathur.web.data.WebDatabase import com.vayunmathur.web.platform.TestStores@@ -73,11 +74,11 @@ class MiscDeepTest {     }      @Test fun remoteImageFetcherRejectsNonHttpData() = runBlocking {-        assertNull(RemoteImageFetchers.network(null, context))-        assertNull(RemoteImageFetchers.network(42, context))-        assertNull(RemoteImageFetchers.network("ftp://example.com/x.png", context))-        assertNull(RemoteImageFetchers.network(Uri.parse("file:///tmp/x.png"), context))-        assertNull(RemoteImageFetchers.network(Uri.parse("content://media/1"), context))+        assertNull(HttpImageFetcher.fetch(null, NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(42, NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch("ftp://example.com/x.png", NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(Uri.parse("file:///tmp/x.png"), NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(Uri.parse("content://media/1"), NetworkClient::getBytes))         Unit     } 
youpipe/src/main/java/com/vayunmathur/youpipe/YouPipeApplication.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/YouPipeApplication.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/YouPipeApplication.ktindex be7ed2dd55..13bce4f320 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/YouPipeApplication.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/YouPipeApplication.kt@@ -6,7 +6,7 @@ import com.vayunmathur.library.log.Log import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle import com.vayunmathur.library.util.DataStoreUtils-import com.vayunmathur.youpipe.data.RemoteImageFetchers+import com.vayunmathur.library.image.fetchers.HttpImageFetcher import com.vayunmathur.youpipe.network.MyDownloader import com.vayunmathur.youpipe.network.sabr.LocalDomPoTokenProvider import com.vayunmathur.youpipe.platform.youtubeLocalization@@ -30,7 +30,7 @@ class YouPipeApplication : Application() {         // shared image pipeline; the fetch function is built here from         // NetworkClient so no library-to-library edge is needed (#884).         ImageLoader.setDefault(-            ImageLoader.Builder(this).remote(RemoteImageFetchers::network).build(),+            ImageLoader.Builder(this).remote { data, _ -> HttpImageFetcher.fetch(data, NetworkClient::getBytes) }.build(),         )         appContext = applicationContext         val language = DataStoreUtils.getInstance(this).getString("youtube_language").orEmpty()
youpipe/src/main/java/com/vayunmathur/youpipe/data/RemoteImageFetchers.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/data/RemoteImageFetchers.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/data/RemoteImageFetchers.ktdeleted file mode 100644index 07cfd0d6c1..0000000000--- a/youpipe/src/main/java/com/vayunmathur/youpipe/data/RemoteImageFetchers.kt+++ /dev/null@@ -1,39 +0,0 @@-package com.vayunmathur.youpipe.data--import android.content.Context-import android.net.Uri-import com.vayunmathur.library.image.fetchers.FetchResult-import com.vayunmathur.library.network.NetworkClient-import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.withContext--/**- * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.- *- * Lives here rather than in a library so no library-to-library edge (and no- * leaked permission) is needed: youpipe declares INTERNET itself, depends on- * both `:library:image` (the `Fetcher` SPI) and `:library:network`- * (`NetworkClient`), and registers this on its `ImageLoader` for video- * thumbnails and channel avatars. Returns null for non-HTTP data so it- * composes with the pipeline's local fetchers (#884).- */-object RemoteImageFetchers {-    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {-        val url: String = when (data) {-            is String -> data-            is Uri -> {-                val s = data.scheme-                if (s == "http" || s == "https") data.toString() else return null-            }-            else -> return null-        }-        if (!url.startsWith("http://") && !url.startsWith("https://")) return null-        return withContext(Dispatchers.IO) {-            val resp = NetworkClient.execute(url)-            if (!resp.isSuccess) {-                throw java.io.IOException("HTTP ${resp.status} for $url")-            }-            FetchResult.Bytes(resp.bytes)-        }-    }-}
youpipe/src/test/java/com/vayunmathur/youpipe/data/ModelsPass3Test.kt
diff --git a/youpipe/src/test/java/com/vayunmathur/youpipe/data/ModelsPass3Test.kt b/youpipe/src/test/java/com/vayunmathur/youpipe/data/ModelsPass3Test.ktindex a69b55a9d1..3c2cfbe74a 100644--- a/youpipe/src/test/java/com/vayunmathur/youpipe/data/ModelsPass3Test.kt+++ b/youpipe/src/test/java/com/vayunmathur/youpipe/data/ModelsPass3Test.kt@@ -1,6 +1,8 @@ package com.vayunmathur.youpipe.data  import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.library.image.fetchers.HttpImageFetcher+import com.vayunmathur.library.network.NetworkClient import androidx.test.ext.junit.runners.AndroidJUnit4 import com.vayunmathur.youpipe.Route import com.vayunmathur.youpipe.platform.defaultBackStack@@ -171,15 +173,15 @@ class ModelsPass3Test {     @Test     fun remoteImageFetchers_rejectNonHttpWithoutNetwork() = runTest {         // None of these may touch the network: non-HTTP inputs answer null.-        assertNull(RemoteImageFetchers.network("ftp://example.com/x.jpg", context))-        assertNull(RemoteImageFetchers.network("relative/path.jpg", context))-        assertNull(RemoteImageFetchers.network(12345, context))-        assertNull(RemoteImageFetchers.network(null, context))+        assertNull(HttpImageFetcher.fetch("ftp://example.com/x.jpg", NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch("relative/path.jpg", NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(12345, NetworkClient::getBytes))+        assertNull(HttpImageFetcher.fetch(null, NetworkClient::getBytes))         assertNull(-            RemoteImageFetchers.network(android.net.Uri.parse("file:///sdcard/x.jpg"), context),+            HttpImageFetcher.fetch(android.net.Uri.parse("file:///sdcard/x.jpg"), NetworkClient::getBytes),         )         assertNull(-            RemoteImageFetchers.network(android.net.Uri.parse("content://media/1"), context),+            HttpImageFetcher.fetch(android.net.Uri.parse("content://media/1"), NetworkClient::getBytes),         )     } }