mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-30 15:17:14 +02:00
Added realm
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// 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
|
||||
call.resolve(serverConnectionConfigToJSON(config: config))
|
||||
}
|
||||
}
|
||||
@objc func getDeviceData(_ call: CAPPluginCall) {
|
||||
Database.realmQueue.sync {
|
||||
call.resolve(serverConnectionConfigToJSON(config: Store.serverConfig))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user