mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 18:15:01 +02:00
Prototype response to app
This commit is contained in:
parent
175e642081
commit
b7725c455b
3 changed files with 41 additions and 13 deletions
|
@ -75,7 +75,13 @@ public class AbsDatabase: CAPPlugin {
|
|||
}
|
||||
|
||||
@objc func getLocalLibraryItems(_ call: CAPPluginCall) {
|
||||
call.resolve([ "value": [] ])
|
||||
do {
|
||||
let items = Database.shared.getLocalLibraryItems()
|
||||
call.resolve([ "value": try items.asDictionaryArray() ])
|
||||
} catch(let exception) {
|
||||
NSLog("error while readling local library items")
|
||||
debugPrint(exception)
|
||||
}
|
||||
}
|
||||
@objc func getLocalLibraryItem(_ call: CAPPluginCall) {
|
||||
call.resolve()
|
||||
|
|
|
@ -9,7 +9,7 @@ import Foundation
|
|||
import RealmSwift
|
||||
|
||||
|
||||
class LocalLibraryItem: Object {
|
||||
class LocalLibraryItem: Object, Encodable {
|
||||
@Persisted(primaryKey: true) var id: String
|
||||
@Persisted var basePath: String = ""
|
||||
@Persisted var absolutePath: String = ""
|
||||
|
@ -44,6 +44,15 @@ class LocalLibraryItem: Object {
|
|||
self.serverAddress = server.address
|
||||
self.serverUserId = server.userId
|
||||
}
|
||||
|
||||
enum CodingKeys: CodingKey {
|
||||
case id
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(id, forKey: .id)
|
||||
}
|
||||
}
|
||||
|
||||
class LocalMediaType: Object {
|
||||
|
@ -146,7 +155,7 @@ class LocalPodcastEpisode: Object {
|
|||
// @Persisted var serverEpisodeId: String?
|
||||
}
|
||||
|
||||
class LocalAudioFile: Object, Codable {
|
||||
class LocalAudioFile: Object {
|
||||
@Persisted var index: Int
|
||||
@Persisted var ino: String
|
||||
@Persisted var metadata: LocalFileMetadata?
|
||||
|
@ -162,13 +171,13 @@ class LocalAudioFile: Object, Codable {
|
|||
}
|
||||
}
|
||||
|
||||
class LocalAuthor: Object, Codable {
|
||||
class LocalAuthor: Object {
|
||||
@Persisted var id: String
|
||||
@Persisted var name: String
|
||||
@Persisted var coverPath: String? = ""
|
||||
}
|
||||
|
||||
class LocalChapter: Object, Codable {
|
||||
class LocalChapter: Object {
|
||||
@Persisted var id: Int
|
||||
@Persisted var start: Double
|
||||
@Persisted var end: Double
|
||||
|
@ -216,7 +225,7 @@ class LocalAudioTrack: Object {
|
|||
}
|
||||
}
|
||||
|
||||
class LocalFileMetadata: Object, Codable {
|
||||
class LocalFileMetadata: Object {
|
||||
@Persisted var filename: String
|
||||
@Persisted var ext: String
|
||||
@Persisted var path: String
|
||||
|
@ -248,7 +257,7 @@ class LocalFile: Object {
|
|||
}
|
||||
}
|
||||
|
||||
class LocalMediaProgress: Object, Codable {
|
||||
class LocalMediaProgress: Object {
|
||||
@Persisted var id: String
|
||||
@Persisted var localLibraryItemId: String
|
||||
@Persisted var localEpisodeId: String? = ""
|
||||
|
|
|
@ -6,18 +6,31 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import RealmSwift
|
||||
|
||||
extension String: Error {}
|
||||
|
||||
typealias Dictionaryable = Encodable
|
||||
|
||||
extension Encodable {
|
||||
func asDictionary() throws -> [String: Any] {
|
||||
let data = try JSONEncoder().encode(self)
|
||||
guard let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] else {
|
||||
throw NSError()
|
||||
func asDictionary() throws -> [String: Any] {
|
||||
let data = try JSONEncoder().encode(self)
|
||||
guard let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] else {
|
||||
throw NSError()
|
||||
}
|
||||
return dictionary
|
||||
}
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
||||
extension Collection where Iterator.Element: Encodable {
|
||||
func asDictionaryArray() throws -> [[String: Any]] {
|
||||
return try self.enumerated().map() {
|
||||
i, element -> [String: Any] in try element.asDictionary()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension DispatchQueue {
|
||||
static func runOnMainQueue(callback: @escaping (() -> Void)) {
|
||||
if Thread.isMainThread {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue