mirror of
https://github.com/sudoxnym/audiobookshelf-atv.git
synced 2026-04-14 19:46:30 +00:00
Return local items on DB lookup
This commit is contained in:
parent
9eca03cfd7
commit
32550a75ec
3 changed files with 47 additions and 8 deletions
|
|
@ -81,14 +81,42 @@ public class AbsDatabase: CAPPlugin {
|
|||
} catch(let exception) {
|
||||
NSLog("error while readling local library items")
|
||||
debugPrint(exception)
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func getLocalLibraryItem(_ call: CAPPluginCall) {
|
||||
call.resolve()
|
||||
do {
|
||||
let item = Database.shared.getLocalLibraryItemByLLId(libraryItem: call.getString("id") ?? "")
|
||||
switch item {
|
||||
case .some(let foundItem):
|
||||
call.resolve(try foundItem.asDictionary())
|
||||
default:
|
||||
call.resolve()
|
||||
}
|
||||
} catch(let exception) {
|
||||
NSLog("error while readling local library items")
|
||||
debugPrint(exception)
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func getLocalLibraryItemByLId(_ call: CAPPluginCall) {
|
||||
call.resolve()
|
||||
do {
|
||||
let item = Database.shared.getLocalLibraryItemByLLId(libraryItem: call.getString("libraryItemId") ?? "")
|
||||
switch item {
|
||||
case .some(let foundItem):
|
||||
call.resolve(try foundItem.asDictionary())
|
||||
default:
|
||||
call.resolve()
|
||||
}
|
||||
} catch(let exception) {
|
||||
NSLog("error while readling local library items")
|
||||
debugPrint(exception)
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func getLocalLibraryItemsInFolder(_ call: CAPPluginCall) {
|
||||
call.resolve([ "value": [] ])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -373,11 +373,11 @@ extension LocalFile {
|
|||
|
||||
func isAudioFile() -> Bool {
|
||||
switch self.mimeType {
|
||||
case "application/octet-stream",
|
||||
"video/mp4":
|
||||
return true
|
||||
default:
|
||||
return self.mimeType?.starts(with: "audio") ?? false
|
||||
case "application/octet-stream",
|
||||
"video/mp4":
|
||||
return true
|
||||
default:
|
||||
return self.mimeType?.starts(with: "audio") ?? false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ class Database {
|
|||
public func getLocalLibraryItemByLLId(libraryItem: String) -> LocalLibraryItem? {
|
||||
let items = getLocalLibraryItems()
|
||||
for item in items {
|
||||
if (item.id == libraryItem) {
|
||||
if (item.libraryItemId == libraryItem) {
|
||||
return item
|
||||
}
|
||||
}
|
||||
|
|
@ -182,6 +182,17 @@ class Database {
|
|||
return nil
|
||||
}
|
||||
|
||||
public func getLocalLibraryItem(localLibraryItem: String) -> LocalLibraryItem? {
|
||||
let items = getLocalLibraryItems()
|
||||
for item in items {
|
||||
if (item.id == localLibraryItem) {
|
||||
return item
|
||||
}
|
||||
}
|
||||
NSLog("Local library item with id \(localLibraryItem) not found")
|
||||
return nil
|
||||
}
|
||||
|
||||
public func saveLocalLibraryItem(localLibraryItem: LocalLibraryItem) {
|
||||
Database.realmQueue.sync {
|
||||
do {
|
||||
|
|
|
|||
Loading…
Reference in a new issue