Use AuthShared in Api.kt for future compatibility with commonMain
This commit is contained in:
@@ -3,7 +3,7 @@ package app.klottr.net
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import app.klottr.BuildConfig
|
import app.klottr.BuildConfig
|
||||||
import app.klottr.util.Auth
|
import app.klottr.util.AuthShared
|
||||||
import app.klottr.util.KLog
|
import app.klottr.util.KLog
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -11,8 +11,8 @@ import java.io.File
|
|||||||
* Android-adapter över Klottrs server-API.
|
* Android-adapter över Klottrs server-API.
|
||||||
*
|
*
|
||||||
* Vad gör den?
|
* Vad gör den?
|
||||||
* - Läser runtime-konfiguration (baseUrl, apiKey) från BuildConfig
|
* - Läser runtime-konfiguration (baseUrl, apiKey) från BuildKonfig
|
||||||
* och injicerar även Google ID-token (Bearer) från Auth.
|
* och injicerar även Google ID-token (Bearer) från AuthShared.
|
||||||
* - Delegerar alla nätverksanrop till delad KMP-klient (Ktor) i :shared.
|
* - Delegerar alla nätverksanrop till delad KMP-klient (Ktor) i :shared.
|
||||||
*
|
*
|
||||||
* Varför så här?
|
* Varför så här?
|
||||||
@@ -56,7 +56,7 @@ suspend fun fetchNearby(
|
|||||||
return KlottrApiShared.nearby(
|
return KlottrApiShared.nearby(
|
||||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||||
apiKey = ApiConfig.SERVER_API_KEY,
|
apiKey = ApiConfig.SERVER_API_KEY,
|
||||||
bearerToken = app.klottr.util.Auth.idToken,
|
bearerToken = AuthShared.idToken,
|
||||||
lat = lat,
|
lat = lat,
|
||||||
lon = lon,
|
lon = lon,
|
||||||
radiusMeters = radiusMeters,
|
radiusMeters = radiusMeters,
|
||||||
@@ -100,7 +100,7 @@ suspend fun uploadImageFromUri(
|
|||||||
KlottrApiShared.uploadImage(
|
KlottrApiShared.uploadImage(
|
||||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||||
apiKey = ApiConfig.SERVER_API_KEY,
|
apiKey = ApiConfig.SERVER_API_KEY,
|
||||||
bearerToken = app.klottr.util.Auth.idToken,
|
bearerToken = AuthShared.idToken,
|
||||||
data = bytes,
|
data = bytes,
|
||||||
filename = filename,
|
filename = filename,
|
||||||
mime = mime,
|
mime = mime,
|
||||||
@@ -157,7 +157,7 @@ suspend fun uploadImageFromFile(
|
|||||||
KlottrApiShared.uploadImage(
|
KlottrApiShared.uploadImage(
|
||||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||||
apiKey = ApiConfig.SERVER_API_KEY,
|
apiKey = ApiConfig.SERVER_API_KEY,
|
||||||
bearerToken = app.klottr.util.Auth.idToken,
|
bearerToken = AuthShared.idToken,
|
||||||
data = bytes,
|
data = bytes,
|
||||||
filename = filename,
|
filename = filename,
|
||||||
mime = mime,
|
mime = mime,
|
||||||
@@ -189,18 +189,18 @@ suspend fun createNote(
|
|||||||
createdAt: Long,
|
createdAt: Long,
|
||||||
clientRequestId: String?
|
clientRequestId: String?
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (Auth.idToken == null || Auth.userId == null) {
|
if (AuthShared.idToken == null || AuthShared.userId == null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return KlottrApiShared.create(
|
return KlottrApiShared.create(
|
||||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||||
apiKey = ApiConfig.SERVER_API_KEY,
|
apiKey = ApiConfig.SERVER_API_KEY,
|
||||||
bearerToken = Auth.idToken,
|
bearerToken = AuthShared.idToken,
|
||||||
lat = lat,
|
lat = lat,
|
||||||
lon = lon,
|
lon = lon,
|
||||||
text = text,
|
text = text,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
userId = Auth.userId,
|
userId = AuthShared.userId,
|
||||||
clientRequestId = clientRequestId
|
clientRequestId = clientRequestId
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -216,13 +216,13 @@ suspend fun createNoteDoc(
|
|||||||
createdAt: Long,
|
createdAt: Long,
|
||||||
clientRequestId: String?
|
clientRequestId: String?
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (Auth.idToken == null || Auth.userId == null) {
|
if (AuthShared.idToken == null || AuthShared.userId == null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return KlottrApiShared.createDoc(
|
return KlottrApiShared.createDoc(
|
||||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||||
apiKey = ApiConfig.SERVER_API_KEY,
|
apiKey = ApiConfig.SERVER_API_KEY,
|
||||||
bearerToken = Auth.idToken,
|
bearerToken = AuthShared.idToken,
|
||||||
lat = lat,
|
lat = lat,
|
||||||
lon = lon,
|
lon = lon,
|
||||||
title = title,
|
title = title,
|
||||||
@@ -230,18 +230,18 @@ suspend fun createNoteDoc(
|
|||||||
imageId = imageId,
|
imageId = imageId,
|
||||||
radiusM = radiusM,
|
radiusM = radiusM,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
userId = Auth.userId,
|
userId = AuthShared.userId,
|
||||||
clientRequestId = clientRequestId
|
clientRequestId = clientRequestId
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** delete_note.php → shared. */
|
/** delete_note.php → shared. */
|
||||||
suspend fun deleteNote(id: Long): Boolean {
|
suspend fun deleteNote(id: Long): Boolean {
|
||||||
if (Auth.idToken == null) return false
|
if (AuthShared.idToken == null) return false
|
||||||
return KlottrApiShared.deleteNote(
|
return KlottrApiShared.deleteNote(
|
||||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||||
apiKey = ApiConfig.SERVER_API_KEY,
|
apiKey = ApiConfig.SERVER_API_KEY,
|
||||||
bearerToken = Auth.idToken,
|
bearerToken = AuthShared.idToken,
|
||||||
id = id
|
id = id
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -255,7 +255,7 @@ suspend fun fetchNoteDetail(id: Long, lat: Double, lon: Double): NoteDetailShare
|
|||||||
KlottrApiShared.getNote(
|
KlottrApiShared.getNote(
|
||||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||||
apiKey = ApiConfig.SERVER_API_KEY,
|
apiKey = ApiConfig.SERVER_API_KEY,
|
||||||
bearerToken = app.klottr.util.Auth.idToken,
|
bearerToken = AuthShared.idToken,
|
||||||
id = id,
|
id = id,
|
||||||
lat = lat,
|
lat = lat,
|
||||||
lon = lon
|
lon = lon
|
||||||
@@ -280,7 +280,7 @@ suspend fun fetchMe(): MeShared? {
|
|||||||
KlottrApiShared.me(
|
KlottrApiShared.me(
|
||||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||||
apiKey = ApiConfig.SERVER_API_KEY,
|
apiKey = ApiConfig.SERVER_API_KEY,
|
||||||
bearerToken = app.klottr.util.Auth.idToken
|
bearerToken = AuthShared.idToken
|
||||||
)
|
)
|
||||||
} catch (_: Throwable) {
|
} catch (_: Throwable) {
|
||||||
return null
|
return null
|
||||||
@@ -296,7 +296,7 @@ suspend fun checkUsernameRemote(input: String): UsernameCheckResp? {
|
|||||||
KlottrApiShared.usernameCheck(
|
KlottrApiShared.usernameCheck(
|
||||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||||
apiKey = ApiConfig.SERVER_API_KEY,
|
apiKey = ApiConfig.SERVER_API_KEY,
|
||||||
bearerToken = app.klottr.util.Auth.idToken,
|
bearerToken = AuthShared.idToken,
|
||||||
username = disp
|
username = disp
|
||||||
)
|
)
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
@@ -313,7 +313,7 @@ suspend fun setUsernameRemote(input: String): UsernameSetResp? {
|
|||||||
KlottrApiShared.usernameSet(
|
KlottrApiShared.usernameSet(
|
||||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||||
apiKey = ApiConfig.SERVER_API_KEY,
|
apiKey = ApiConfig.SERVER_API_KEY,
|
||||||
bearerToken = app.klottr.util.Auth.idToken,
|
bearerToken = AuthShared.idToken,
|
||||||
username = disp
|
username = disp
|
||||||
)
|
)
|
||||||
} catch (_: Throwable) {
|
} catch (_: Throwable) {
|
||||||
@@ -336,7 +336,7 @@ suspend fun fetchImageStreamPost(
|
|||||||
KlottrApiShared.getImageStreamPost(
|
KlottrApiShared.getImageStreamPost(
|
||||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||||
apiKey = ApiConfig.SERVER_API_KEY,
|
apiKey = ApiConfig.SERVER_API_KEY,
|
||||||
bearerToken = app.klottr.util.Auth.idToken,
|
bearerToken = AuthShared.idToken,
|
||||||
id = imageId,
|
id = imageId,
|
||||||
noteId = noteId,
|
noteId = noteId,
|
||||||
lat = lat,
|
lat = lat,
|
||||||
|
|||||||
Reference in New Issue
Block a user