mirror of
https://github.com/fromchat-messenger/app.git
synced 2026-09-22 19:15:05 +03:00
Stop using /api prefix on API
Signed-off-by: denis0001-dev <denis0001.dev@ya.ru>
This commit is contained in:
@@ -854,16 +854,19 @@ object ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch encrypted file bytes. Path is e.g. "/uploads/files/encrypted/xxx.jpg" or "/api/uploads/files/encrypted/xxx.jpg".
|
* Fetch encrypted file bytes. Path examples:
|
||||||
* Backend may return path with /api prefix; apiBaseUrl already includes /api, so we avoid double /api.
|
* - absolute URL like "http://..." -> returned as-is
|
||||||
|
* - "/uploads/files/encrypted/xxx.jpg" -> returned as <apiBaseUrl>/uploads/...
|
||||||
|
* - "/api/uploads/..." -> strip legacy `/api` prefix, then combine with apiBaseUrl
|
||||||
*/
|
*/
|
||||||
fun encryptedFileUrl(path: String): String = when {
|
fun encryptedFileUrl(path: String): String {
|
||||||
path.startsWith("http") -> path
|
if (path.startsWith("http")) return path
|
||||||
path.startsWith("/api") -> {
|
val base = ServerConfig.apiBaseUrl.trimEnd('/')
|
||||||
val serverBase = ServerConfig.apiBaseUrl.removeSuffix("/api")
|
var p = if (path.startsWith("/")) path else "/$path"
|
||||||
"$serverBase$path"
|
if (p.startsWith("/api/") || p == "/api") {
|
||||||
|
p = p.removePrefix("/api").ifEmpty { "/" }
|
||||||
}
|
}
|
||||||
else -> "${ServerConfig.apiBaseUrl}$path"
|
return base + p
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Plain public-chat attachment URL (same path resolution as [encryptedFileUrl]). */
|
/** Plain public-chat attachment URL (same path resolution as [encryptedFileUrl]). */
|
||||||
@@ -1357,7 +1360,7 @@ object ApiClient {
|
|||||||
suspend fun validateToken(): Boolean {
|
suspend fun validateToken(): Boolean {
|
||||||
try {
|
try {
|
||||||
http
|
http
|
||||||
.get("${ServerConfig.apiBaseUrl}/api/user/profile")
|
.get("${ServerConfig.apiBaseUrl}/user/profile")
|
||||||
return true // Token is valid if no exception thrown
|
return true // Token is valid if no exception thrown
|
||||||
} catch (e: ClientRequestException) {
|
} catch (e: ClientRequestException) {
|
||||||
if (e.response.status.value == 401 || e.response.status.value == 403) {
|
if (e.response.status.value == 401 || e.response.status.value == 403) {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ suspend fun resolveInstanceId(
|
|||||||
|
|
||||||
fun apiBaseUrlFor(config: ServerConfigData): String {
|
fun apiBaseUrlFor(config: ServerConfigData): String {
|
||||||
val scheme = if (config.httpsEnabled) "https" else "http"
|
val scheme = if (config.httpsEnabled) "https" else "http"
|
||||||
return "$scheme://${config.serverIp}:${config.apiPort}/api"
|
return "$scheme://${config.serverIp}:${config.apiPort}"
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun networkFailureToResolveResult(
|
private fun networkFailureToResolveResult(
|
||||||
|
|||||||
@@ -50,12 +50,12 @@ object ServerConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LiveKit signaling WebSocket URL: same host and API port as HTTPS reverse proxy (`/api/livekit/rtc`).
|
* LiveKit signaling WebSocket URL: same host and API port as HTTPS reverse proxy (`/livekit/rtc`).
|
||||||
* WebRTC media uses the configured calls port on the server (e.g. HAProxy in front of LiveKit).
|
* WebRTC media uses the configured calls port on the server (e.g. HAProxy in front of LiveKit).
|
||||||
*/
|
*/
|
||||||
fun liveKitSignalingWsUrl(): String {
|
fun liveKitSignalingWsUrl(): String {
|
||||||
val scheme = if (config.httpsEnabled) "wss" else "ws"
|
val scheme = if (config.httpsEnabled) "wss" else "ws"
|
||||||
return "$scheme://${config.serverIp}:${config.apiPort}/api/livekit/rtc"
|
return "$scheme://${config.serverIp}:${config.apiPort}/livekit/rtc"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,7 +64,7 @@ object ServerConfig {
|
|||||||
val apiBaseUrl: String
|
val apiBaseUrl: String
|
||||||
get() {
|
get() {
|
||||||
val scheme = if (config.httpsEnabled) "https" else "http"
|
val scheme = if (config.httpsEnabled) "https" else "http"
|
||||||
return "$scheme://${config.serverIp}:${config.apiPort}/api"
|
return "$scheme://${config.serverIp}:${config.apiPort}"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,7 +73,7 @@ object ServerConfig {
|
|||||||
val webSocketUrl: String
|
val webSocketUrl: String
|
||||||
get() {
|
get() {
|
||||||
val scheme = if (config.httpsEnabled) "wss" else "ws"
|
val scheme = if (config.httpsEnabled) "wss" else "ws"
|
||||||
return "$scheme://${config.serverIp}:${config.apiPort}/api/chat/ws"
|
return "$scheme://${config.serverIp}:${config.apiPort}/chat/ws"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,10 @@ fun Avatar(
|
|||||||
val fullUrl = if (profilePictureUrl.startsWith("http")) {
|
val fullUrl = if (profilePictureUrl.startsWith("http")) {
|
||||||
profilePictureUrl
|
profilePictureUrl
|
||||||
} else {
|
} else {
|
||||||
"${ServerConfig.apiBaseUrl}$profilePictureUrl"
|
val path = profilePictureUrl
|
||||||
|
.removePrefix("/api")
|
||||||
|
.let { if (it.startsWith("/")) it else "/$it" }
|
||||||
|
"${ServerConfig.apiBaseUrl}$path"
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
|
|||||||
Reference in New Issue
Block a user