2022-04-11 16:29:19 +02:00
|
|
|
//
|
|
|
|
// AbsDatabase.swift
|
|
|
|
// App
|
|
|
|
//
|
|
|
|
// Created by Rasmus Krämer on 11.04.22.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Capacitor
|
|
|
|
import RealmSwift
|
|
|
|
|
|
|
|
extension String {
|
|
|
|
|
|
|
|
func fromBase64() -> String? {
|
|
|
|
guard let data = Data(base64Encoded: self) else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return String(data: data, encoding: .utf8)
|
|
|
|
}
|
|
|
|
|
|
|
|
func toBase64() -> String {
|
|
|
|
return Data(self.utf8).base64EncodedString()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(AbsDatabase)
|
|
|
|
public class AbsDatabase: CAPPlugin {
|
|
|
|
@objc func setCurrentServerConnectionConfig(_ call: CAPPluginCall) {
|
|
|
|
Database.realmQueue.sync {
|
|
|
|
var id = call.getString("id")
|
|
|
|
let address = call.getString("address", "")
|
|
|
|
let userId = call.getString("userId", "")
|
|
|
|
let username = call.getString("username", "")
|
|
|
|
let token = call.getString("token", "")
|
|
|
|
|
|
|
|
let name = "\(address) (\(username))"
|
|
|
|
let config = ServerConnectionConfig()
|
|
|
|
|
|
|
|
if id == nil {
|
|
|
|
id = "\(address)@\(username)".toBase64()
|
|
|
|
}
|
|
|
|
|
|
|
|
config.id = id!
|
|
|
|
config.name = name
|
|
|
|
config.address = address
|
|
|
|
config.userId = userId
|
|
|
|
config.username = username
|
|
|
|
config.token = token
|
|
|
|
|
|
|
|
Store.serverConfig = config
|
2022-04-11 18:31:14 +02:00
|
|
|
call.resolve(convertServerConnectionConfigToJSON(config: config))
|
2022-04-11 16:29:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
@objc func getDeviceData(_ call: CAPPluginCall) {
|
|
|
|
Database.realmQueue.sync {
|
2022-04-11 18:31:14 +02:00
|
|
|
let configs = Database.getServerConnectionConfigs()
|
|
|
|
let index = Database.getActiveServerConfigIndex()
|
|
|
|
|
|
|
|
call.resolve([
|
|
|
|
"serverConnectionConfigs": configs.map { config in
|
|
|
|
return convertServerConnectionConfigToJSON(config: config)
|
|
|
|
},
|
2022-04-12 14:28:47 +02:00
|
|
|
"lastServerConnectionConfigId": index < 0 ? -1 : configs.first(where: {
|
|
|
|
(config: ServerConnectionConfig) -> Bool in
|
|
|
|
return config.index == index
|
|
|
|
})!.id,
|
2022-04-11 18:31:14 +02:00
|
|
|
"currentLocalPlaybackSession": nil, // Luckily this isn't implemented yet
|
|
|
|
])
|
2022-04-11 16:29:19 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-11 18:31:14 +02:00
|
|
|
|
2022-04-11 18:50:25 +02:00
|
|
|
// We have to send a empty array or the client will break
|
|
|
|
@objc func getLocalLibraryItems(_ call: CAPPluginCall) {
|
|
|
|
call.resolve([ "value": [] ])
|
|
|
|
}
|
|
|
|
@objc func getLocalLibraryItem(_ call: CAPPluginCall) {
|
|
|
|
call.resolve([ "value": [] ])
|
|
|
|
}
|
|
|
|
@objc func getLocalLibraryItemByLLId(_ call: CAPPluginCall) {
|
|
|
|
call.resolve([ "value": [] ])
|
|
|
|
}
|
|
|
|
@objc func getLocalLibraryItemsInFolder(_ call: CAPPluginCall) {
|
|
|
|
call.resolve([ "value": [] ])
|
|
|
|
}
|
2022-04-11 16:29:19 +02:00
|
|
|
}
|