Skip to content

Commit

Permalink
Fix:Include device info with sync local-all request
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Feb 4, 2024
1 parent fcd6270 commit e3f82bb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ class MediaProgressSyncer(val playerNotificationService: PlayerNotificationServi
saveLocalProgress(it)
lastSyncTime = System.currentTimeMillis()

Log.d(tag, "Sync local device current serverConnectionConfigId=${DeviceManager.serverConnectionConfig?.id}")

// Local library item is linked to a server library item
// Send sync to server also if connected to this server and local item belongs to this server
if (hasNetworkConnection && shouldSyncServer && !it.libraryItemId.isNullOrEmpty() && it.serverConnectionConfigId != null && DeviceManager.serverConnectionConfig?.id == it.serverConnectionConfigId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.audiobookshelf.app.server

import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.provider.Settings
import android.util.Log
import com.audiobookshelf.app.data.*
import com.audiobookshelf.app.device.DeviceManager
Expand Down Expand Up @@ -31,7 +34,7 @@ class ApiHandler(var ctx:Context) {
private var pingClient = OkHttpClient.Builder().callTimeout(3, TimeUnit.SECONDS).build()
private var jacksonMapper = jacksonObjectMapper().enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature())

data class LocalSessionsSyncRequestPayload(val sessions:List<PlaybackSession>)
data class LocalSessionsSyncRequestPayload(val sessions:List<PlaybackSession>, val deviceInfo:DeviceInfo)
@JsonIgnoreProperties(ignoreUnknown = true)
data class LocalSessionSyncResult(val id:String, val success:Boolean, val progressSynced:Boolean?, val error:String?)
data class LocalSessionsSyncResponsePayload(val results:List<LocalSessionSyncResult>)
Expand Down Expand Up @@ -322,7 +325,11 @@ class ApiHandler(var ctx:Context) {
}

fun sendSyncLocalSessions(playbackSessions:List<PlaybackSession>, cb: (Boolean, String?) -> Unit) {
val payload = JSObject(jacksonMapper.writeValueAsString(LocalSessionsSyncRequestPayload(playbackSessions)))
@SuppressLint("HardwareIds")
val deviceId = Settings.Secure.getString(ctx.contentResolver, Settings.Secure.ANDROID_ID)
val deviceInfo = DeviceInfo(deviceId, Build.MANUFACTURER, Build.MODEL, Build.VERSION.SDK_INT, Build.VERSION.RELEASE)

val payload = JSObject(jacksonMapper.writeValueAsString(LocalSessionsSyncRequestPayload(playbackSessions, deviceInfo)))
Log.d(tag, "Sending ${playbackSessions.size} saved local playback sessions to server")
postRequest("/api/session/local-all", payload, null) {
if (!it.getString("error").isNullOrEmpty()) {
Expand Down
1 change: 0 additions & 1 deletion pages/item/_id/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export default {
// Filter by downloaded when redirecting from the local copy
queryParams.set('episodefilter', 'downloaded')
}
console.log('Redirecting to server library item page with queryparams', queryParams.toString())
return redirect(`/item/${libraryItem.libraryItemId}?${queryParams.toString()}`)
}
} else if (!store.state.user.serverConnectionConfig) {
Expand Down

0 comments on commit e3f82bb

Please sign in to comment.