mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 10:04:39 +02:00
Fix:iOS downloading not saving progress for local copy #825
This commit is contained in:
parent
a88e404ccf
commit
81b11bac93
3 changed files with 11 additions and 5 deletions
|
@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
// Override point for customization after application launch.
|
||||
|
||||
let configuration = Realm.Configuration(
|
||||
schemaVersion: 13,
|
||||
schemaVersion: 14,
|
||||
migrationBlock: { [weak self] migration, oldSchemaVersion in
|
||||
if (oldSchemaVersion < 1) {
|
||||
self?.logger.log("Realm schema version was \(oldSchemaVersion)")
|
||||
|
|
|
@ -10,6 +10,7 @@ import RealmSwift
|
|||
|
||||
class MediaProgress: EmbeddedObject, Codable {
|
||||
@Persisted var id: String = ""
|
||||
@Persisted var userId: String = ""
|
||||
@Persisted var libraryItemId: String = ""
|
||||
@Persisted var episodeId: String?
|
||||
@Persisted var duration: Double = 0
|
||||
|
@ -23,7 +24,7 @@ class MediaProgress: EmbeddedObject, Codable {
|
|||
@Persisted var finishedAt: Double?
|
||||
|
||||
private enum CodingKeys : String, CodingKey {
|
||||
case id, libraryItemId, episodeId, duration, progress, currentTime, isFinished, ebookLocation, ebookProgress, lastUpdate, startedAt, finishedAt
|
||||
case id, userId, libraryItemId, episodeId, duration, progress, currentTime, isFinished, ebookLocation, ebookProgress, lastUpdate, startedAt, finishedAt
|
||||
}
|
||||
|
||||
override init() {
|
||||
|
@ -33,6 +34,7 @@ class MediaProgress: EmbeddedObject, Codable {
|
|||
required init(from decoder: Decoder) throws {
|
||||
let values = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = try values.decode(String.self, forKey: .id)
|
||||
userId = try values.decode(String.self, forKey: .userId)
|
||||
libraryItemId = try values.decode(String.self, forKey: .libraryItemId)
|
||||
episodeId = try? values.decode(String.self, forKey: .episodeId)
|
||||
duration = try values.doubleOrStringDecoder(key: .duration)
|
||||
|
@ -40,7 +42,7 @@ class MediaProgress: EmbeddedObject, Codable {
|
|||
currentTime = try values.doubleOrStringDecoder(key: .currentTime)
|
||||
isFinished = try values.decode(Bool.self, forKey: .isFinished)
|
||||
ebookLocation = try values.decodeIfPresent(String.self, forKey: .ebookLocation)
|
||||
ebookProgress = try values.doubleOrStringDecoder(key: .ebookProgress)
|
||||
ebookProgress = try? values.doubleOrStringDecoder(key: .ebookProgress)
|
||||
lastUpdate = try values.doubleOrStringDecoder(key: .lastUpdate)
|
||||
startedAt = try values.doubleOrStringDecoder(key: .startedAt)
|
||||
finishedAt = try? values.doubleOrStringDecoder(key: .finishedAt)
|
||||
|
@ -49,6 +51,7 @@ class MediaProgress: EmbeddedObject, Codable {
|
|||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(id, forKey: .id)
|
||||
try container.encode(userId, forKey: .userId)
|
||||
try container.encode(libraryItemId, forKey: .libraryItemId)
|
||||
try container.encode(episodeId, forKey: .episodeId)
|
||||
try container.encode(duration, forKey: .duration)
|
||||
|
|
|
@ -219,7 +219,9 @@ class ApiClient {
|
|||
}
|
||||
if (localMediaProgress != nil && mediaProgress.lastUpdate > localMediaProgress!.lastUpdate) {
|
||||
logger.log("syncLocalSessionsWithServer: Updating local media progress \(localMediaProgress!.id) with server media progress")
|
||||
try localMediaProgress?.updateFromServerMediaProgress(mediaProgress)
|
||||
if let localMediaProgress = localMediaProgress?.thaw() {
|
||||
try localMediaProgress.updateFromServerMediaProgress(mediaProgress)
|
||||
}
|
||||
} else if (localMediaProgress != nil) {
|
||||
logger.log("syncLocalSessionsWithServer: Local progress for \(localMediaProgress!.id) is more recent then server progress")
|
||||
}
|
||||
|
@ -276,9 +278,10 @@ class ApiClient {
|
|||
}
|
||||
|
||||
ApiClient.getResource(endpoint: endpoint, decodable: LibraryItem.self) { obj in
|
||||
callback(obj)
|
||||
callback(obj)
|
||||
}
|
||||
}
|
||||
|
||||
public static func pingServer() async -> Bool {
|
||||
var status = true
|
||||
AF.request("\(Store.serverConfig!.address)/ping", method: .get).responseDecodable(of: PingResponsePayload.self) { response in
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue