mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-28 13:58:23 +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) {
|
@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) {
|
@objc func getLocalLibraryItem(_ call: CAPPluginCall) {
|
||||||
call.resolve()
|
call.resolve()
|
||||||
|
|
|
@ -9,7 +9,7 @@ import Foundation
|
||||||
import RealmSwift
|
import RealmSwift
|
||||||
|
|
||||||
|
|
||||||
class LocalLibraryItem: Object {
|
class LocalLibraryItem: Object, Encodable {
|
||||||
@Persisted(primaryKey: true) var id: String
|
@Persisted(primaryKey: true) var id: String
|
||||||
@Persisted var basePath: String = ""
|
@Persisted var basePath: String = ""
|
||||||
@Persisted var absolutePath: String = ""
|
@Persisted var absolutePath: String = ""
|
||||||
|
@ -44,6 +44,15 @@ class LocalLibraryItem: Object {
|
||||||
self.serverAddress = server.address
|
self.serverAddress = server.address
|
||||||
self.serverUserId = server.userId
|
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 {
|
class LocalMediaType: Object {
|
||||||
|
@ -146,7 +155,7 @@ class LocalPodcastEpisode: Object {
|
||||||
// @Persisted var serverEpisodeId: String?
|
// @Persisted var serverEpisodeId: String?
|
||||||
}
|
}
|
||||||
|
|
||||||
class LocalAudioFile: Object, Codable {
|
class LocalAudioFile: Object {
|
||||||
@Persisted var index: Int
|
@Persisted var index: Int
|
||||||
@Persisted var ino: String
|
@Persisted var ino: String
|
||||||
@Persisted var metadata: LocalFileMetadata?
|
@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 id: String
|
||||||
@Persisted var name: String
|
@Persisted var name: String
|
||||||
@Persisted var coverPath: String? = ""
|
@Persisted var coverPath: String? = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
class LocalChapter: Object, Codable {
|
class LocalChapter: Object {
|
||||||
@Persisted var id: Int
|
@Persisted var id: Int
|
||||||
@Persisted var start: Double
|
@Persisted var start: Double
|
||||||
@Persisted var end: 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 filename: String
|
||||||
@Persisted var ext: String
|
@Persisted var ext: String
|
||||||
@Persisted var path: 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 id: String
|
||||||
@Persisted var localLibraryItemId: String
|
@Persisted var localLibraryItemId: String
|
||||||
@Persisted var localEpisodeId: String? = ""
|
@Persisted var localEpisodeId: String? = ""
|
||||||
|
|
|
@ -6,18 +6,31 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
import RealmSwift
|
||||||
|
|
||||||
extension String: Error {}
|
extension String: Error {}
|
||||||
|
|
||||||
|
typealias Dictionaryable = Encodable
|
||||||
|
|
||||||
extension Encodable {
|
extension Encodable {
|
||||||
func asDictionary() throws -> [String: Any] {
|
func asDictionary() throws -> [String: Any] {
|
||||||
let data = try JSONEncoder().encode(self)
|
let data = try JSONEncoder().encode(self)
|
||||||
guard let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] else {
|
guard let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] else {
|
||||||
throw NSError()
|
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 {
|
extension DispatchQueue {
|
||||||
static func runOnMainQueue(callback: @escaping (() -> Void)) {
|
static func runOnMainQueue(callback: @escaping (() -> Void)) {
|
||||||
if Thread.isMainThread {
|
if Thread.isMainThread {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue