feat: Add fallback transport server and enhance file download handling with blurhash support

This commit is contained in:
k1ngsterr1
2026-01-24 16:04:23 +05:00
parent d5083e60a5
commit 8c87b12c5f
5 changed files with 593 additions and 314 deletions

View File

@@ -31,6 +31,9 @@ data class TransportState(
object TransportManager {
private const val TAG = "TransportManager"
// Fallback transport server (CDN)
private const val FALLBACK_TRANSPORT_SERVER = "https://cdn.rosetta-im.com"
private var transportServer: String? = null
private val _uploading = MutableStateFlow<List<TransportState>>(emptyList())
@@ -54,9 +57,18 @@ object TransportManager {
}
/**
* Получить адрес транспортного сервера
* Получить адрес транспортного сервера (с fallback)
*/
fun getTransportServer(): String? = transportServer
fun getTransportServer(): String = transportServer ?: FALLBACK_TRANSPORT_SERVER
/**
* Получить активный сервер для скачивания/загрузки
*/
private fun getActiveServer(): String {
val server = transportServer ?: FALLBACK_TRANSPORT_SERVER
Log.d(TAG, "📡 Using transport server: $server (configured: ${transportServer != null})")
return server
}
/**
* Запросить адрес транспортного сервера с сервера протокола
@@ -73,10 +85,9 @@ object TransportManager {
* @return Tag для скачивания файла
*/
suspend fun uploadFile(id: String, content: String): String = withContext(Dispatchers.IO) {
val server = transportServer
?: throw IllegalStateException("Transport server is not set")
val server = getActiveServer()
Log.d(TAG, "📤 Uploading file: $id")
Log.d(TAG, "📤 Uploading file: $id to $server")
// Добавляем в список загрузок
_uploading.value = _uploading.value + TransportState(id, 0)
@@ -139,10 +150,9 @@ object TransportManager {
* @return Содержимое файла
*/
suspend fun downloadFile(id: String, tag: String): String = withContext(Dispatchers.IO) {
val server = transportServer
?: throw IllegalStateException("Transport server is not set")
val server = getActiveServer()
Log.d(TAG, "📥 Downloading file: $id (tag: $tag)")
Log.d(TAG, "📥 Downloading file: $id (tag: $tag) from $server")
// Добавляем в список скачиваний
_downloading.value = _downloading.value + TransportState(id, 0)