mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-26 21:34:05 +02:00
Return local items on DB lookup
This commit is contained in:
@@ -81,14 +81,42 @@ public class AbsDatabase: CAPPlugin {
|
|||||||
} catch(let exception) {
|
} catch(let exception) {
|
||||||
NSLog("error while readling local library items")
|
NSLog("error while readling local library items")
|
||||||
debugPrint(exception)
|
debugPrint(exception)
|
||||||
|
call.resolve()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func getLocalLibraryItem(_ call: CAPPluginCall) {
|
@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) {
|
@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) {
|
@objc func getLocalLibraryItemsInFolder(_ call: CAPPluginCall) {
|
||||||
call.resolve([ "value": [] ])
|
call.resolve([ "value": [] ])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -373,11 +373,11 @@ extension LocalFile {
|
|||||||
|
|
||||||
func isAudioFile() -> Bool {
|
func isAudioFile() -> Bool {
|
||||||
switch self.mimeType {
|
switch self.mimeType {
|
||||||
case "application/octet-stream",
|
case "application/octet-stream",
|
||||||
"video/mp4":
|
"video/mp4":
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return self.mimeType?.starts(with: "audio") ?? false
|
return self.mimeType?.starts(with: "audio") ?? false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ class Database {
|
|||||||
public func getLocalLibraryItemByLLId(libraryItem: String) -> LocalLibraryItem? {
|
public func getLocalLibraryItemByLLId(libraryItem: String) -> LocalLibraryItem? {
|
||||||
let items = getLocalLibraryItems()
|
let items = getLocalLibraryItems()
|
||||||
for item in items {
|
for item in items {
|
||||||
if (item.id == libraryItem) {
|
if (item.libraryItemId == libraryItem) {
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,6 +182,17 @@ class Database {
|
|||||||
return nil
|
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) {
|
public func saveLocalLibraryItem(localLibraryItem: LocalLibraryItem) {
|
||||||
Database.realmQueue.sync {
|
Database.realmQueue.sync {
|
||||||
do {
|
do {
|
||||||
|
|||||||
Reference in New Issue
Block a user