mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-09-12 21:01:50 +02:00
Merge branch 'master' of https://github.com/advplyr/audiobookshelf-app
This commit is contained in:
@@ -740,7 +740,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = Icons;
|
ASSETCATALOG_COMPILER_APPICON_NAME = Icons;
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 46;
|
CURRENT_PROJECT_VERSION = 47;
|
||||||
DEVELOPMENT_TEAM = 7UFJ7D8V6A;
|
DEVELOPMENT_TEAM = 7UFJ7D8V6A;
|
||||||
INFOPLIST_FILE = App/Info.plist;
|
INFOPLIST_FILE = App/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||||
@@ -764,7 +764,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = Icons;
|
ASSETCATALOG_COMPILER_APPICON_NAME = Icons;
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 46;
|
CURRENT_PROJECT_VERSION = 47;
|
||||||
DEVELOPMENT_TEAM = 7UFJ7D8V6A;
|
DEVELOPMENT_TEAM = 7UFJ7D8V6A;
|
||||||
INFOPLIST_FILE = App/Info.plist;
|
INFOPLIST_FILE = App/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ class Database {
|
|||||||
debugPrint(error)
|
debugPrint(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setServerConnectionConfig(config: ServerConnectionConfig) {
|
public func setServerConnectionConfig(config: ServerConnectionConfig) {
|
||||||
let config = config
|
let config = config
|
||||||
let realm = try! Realm()
|
let realm = try! Realm()
|
||||||
let existing: ServerConnectionConfig? = realm.object(ofType: ServerConnectionConfig.self, forPrimaryKey: config.id)
|
let existing: ServerConnectionConfig? = realm.object(ofType: ServerConnectionConfig.self, forPrimaryKey: config.id)
|
||||||
|
|
||||||
if let existing = existing {
|
if let existing = existing {
|
||||||
do {
|
do {
|
||||||
try existing.update {
|
try existing.update {
|
||||||
@@ -40,19 +40,19 @@ class Database {
|
|||||||
AbsLogger.error("setServerConn", message: "failed to update server config")
|
AbsLogger.error("setServerConn", message: "failed to update server config")
|
||||||
debugPrint(error)
|
debugPrint(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
setLastActiveConfigIndex(index: existing.index)
|
setLastActiveConfigIndex(index: existing.index)
|
||||||
} else {
|
} else {
|
||||||
if config.index == 0 {
|
if config.index == 0 {
|
||||||
let lastConfig: ServerConnectionConfig? = realm.objects(ServerConnectionConfig.self).last
|
let lastConfig: ServerConnectionConfig? = realm.objects(ServerConnectionConfig.self).last
|
||||||
|
|
||||||
if lastConfig != nil {
|
if lastConfig != nil {
|
||||||
config.index = lastConfig!.index + 1
|
config.index = lastConfig!.index + 1
|
||||||
} else {
|
} else {
|
||||||
config.index = 1
|
config.index = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try realm.write {
|
try realm.write {
|
||||||
realm.add(config)
|
realm.add(config)
|
||||||
@@ -61,7 +61,7 @@ class Database {
|
|||||||
AbsLogger.error(message: "failed to save server config")
|
AbsLogger.error(message: "failed to save server config")
|
||||||
debugPrint(exception)
|
debugPrint(exception)
|
||||||
}
|
}
|
||||||
|
|
||||||
setLastActiveConfigIndex(index: config.index)
|
setLastActiveConfigIndex(index: config.index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,11 +78,11 @@ class Database {
|
|||||||
debugPrint("Failed to update server connection config token: \(error)")
|
debugPrint("Failed to update server connection config token: \(error)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func deleteServerConnectionConfig(id: String) {
|
public func deleteServerConnectionConfig(id: String) {
|
||||||
let realm = try! Realm()
|
let realm = try! Realm()
|
||||||
let config = realm.object(ofType: ServerConnectionConfig.self, forPrimaryKey: id)
|
let config = realm.object(ofType: ServerConnectionConfig.self, forPrimaryKey: id)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try realm.write {
|
try realm.write {
|
||||||
if config != nil {
|
if config != nil {
|
||||||
@@ -94,27 +94,27 @@ class Database {
|
|||||||
debugPrint(exception)
|
debugPrint(exception)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getServerConnectionConfigs() -> [ServerConnectionConfig] {
|
public func getServerConnectionConfigs() -> [ServerConnectionConfig] {
|
||||||
let realm = try! Realm()
|
let realm = try! Realm()
|
||||||
return Array(realm.objects(ServerConnectionConfig.self))
|
return Array(realm.objects(ServerConnectionConfig.self))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setLastActiveConfigIndexToNil() {
|
public func setLastActiveConfigIndexToNil() {
|
||||||
setLastActiveConfigIndex(index: nil)
|
setLastActiveConfigIndex(index: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setLastActiveConfigIndex(index: Int?) {
|
private func setLastActiveConfigIndex(index: Int?) {
|
||||||
let realm = try! Realm()
|
let realm = try! Realm()
|
||||||
do {
|
do {
|
||||||
try realm.write {
|
try realm.write {
|
||||||
let existing = realm.objects(ServerConnectionConfigActiveIndex.self).last
|
let existing = realm.objects(ServerConnectionConfigActiveIndex.self).last
|
||||||
|
|
||||||
if ( existing?.index != index ) {
|
if ( existing?.index != index ) {
|
||||||
if let existing = existing {
|
if let existing = existing {
|
||||||
realm.delete(existing)
|
realm.delete(existing)
|
||||||
}
|
}
|
||||||
|
|
||||||
let activeConfig = ServerConnectionConfigActiveIndex()
|
let activeConfig = ServerConnectionConfigActiveIndex()
|
||||||
activeConfig.index = index
|
activeConfig.index = index
|
||||||
realm.add(activeConfig)
|
realm.add(activeConfig)
|
||||||
@@ -125,12 +125,12 @@ class Database {
|
|||||||
debugPrint(exception)
|
debugPrint(exception)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getLastActiveConfigIndex() -> Int? {
|
public func getLastActiveConfigIndex() -> Int? {
|
||||||
let realm = try! Realm()
|
let realm = try! Realm()
|
||||||
return realm.objects(ServerConnectionConfigActiveIndex.self).first?.index ?? nil
|
return realm.objects(ServerConnectionConfigActiveIndex.self).first?.index ?? nil
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setDeviceSettings(deviceSettings: DeviceSettings) {
|
public func setDeviceSettings(deviceSettings: DeviceSettings) {
|
||||||
let realm = try! Realm()
|
let realm = try! Realm()
|
||||||
let existing = realm.objects(DeviceSettings.self)
|
let existing = realm.objects(DeviceSettings.self)
|
||||||
@@ -144,7 +144,7 @@ class Database {
|
|||||||
AbsLogger.error(message: "failed to save device settings")
|
AbsLogger.error(message: "failed to save device settings")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getLocalLibraryItems(mediaType: MediaType? = nil) -> [LocalLibraryItem] {
|
public func getLocalLibraryItems(mediaType: MediaType? = nil) -> [LocalLibraryItem] {
|
||||||
do {
|
do {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
@@ -154,7 +154,7 @@ class Database {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getLocalLibraryItem(byServerLibraryItemId: String) -> LocalLibraryItem? {
|
public func getLocalLibraryItem(byServerLibraryItemId: String) -> LocalLibraryItem? {
|
||||||
do {
|
do {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
@@ -164,7 +164,7 @@ class Database {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getLocalLibraryItem(localLibraryItemId: String) -> LocalLibraryItem? {
|
public func getLocalLibraryItem(localLibraryItemId: String) -> LocalLibraryItem? {
|
||||||
do {
|
do {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
@@ -174,12 +174,12 @@ class Database {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func saveLocalLibraryItem(localLibraryItem: LocalLibraryItem) throws {
|
public func saveLocalLibraryItem(localLibraryItem: LocalLibraryItem) throws {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
try realm.write { realm.add(localLibraryItem, update: .modified) }
|
try realm.write { realm.add(localLibraryItem, update: .modified) }
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getLocalFile(localFileId: String) -> LocalFile? {
|
public func getLocalFile(localFileId: String) -> LocalFile? {
|
||||||
do {
|
do {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
@@ -189,7 +189,7 @@ class Database {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getDownloadItem(downloadItemId: String) -> DownloadItem? {
|
public func getDownloadItem(downloadItemId: String) -> DownloadItem? {
|
||||||
do {
|
do {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
@@ -199,7 +199,7 @@ class Database {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getDownloadItem(libraryItemId: String) -> DownloadItem? {
|
public func getDownloadItem(libraryItemId: String) -> DownloadItem? {
|
||||||
do {
|
do {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
@@ -209,7 +209,7 @@ class Database {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getDownloadItem(downloadItemPartId: String) -> DownloadItem? {
|
public func getDownloadItem(downloadItemPartId: String) -> DownloadItem? {
|
||||||
do {
|
do {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
@@ -219,17 +219,17 @@ class Database {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func saveDownloadItem(_ downloadItem: DownloadItem) throws {
|
public func saveDownloadItem(_ downloadItem: DownloadItem) throws {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
return try realm.write { realm.add(downloadItem, update: .modified) }
|
return try realm.write { realm.add(downloadItem, update: .modified) }
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getDeviceSettings() -> DeviceSettings {
|
public func getDeviceSettings() -> DeviceSettings {
|
||||||
let realm = try! Realm()
|
let realm = try! Realm()
|
||||||
return realm.objects(DeviceSettings.self).first ?? getDefaultDeviceSettings()
|
return realm.objects(DeviceSettings.self).first ?? getDefaultDeviceSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getAllLocalMediaProgress() -> [LocalMediaProgress] {
|
public func getAllLocalMediaProgress() -> [LocalMediaProgress] {
|
||||||
do {
|
do {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
@@ -239,7 +239,7 @@ class Database {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For books this will just be the localLibraryItemId for podcast episodes this will be "{localLibraryItemId}-{episodeId}"
|
// For books this will just be the localLibraryItemId for podcast episodes this will be "{localLibraryItemId}-{episodeId}"
|
||||||
public func getLocalMediaProgress(localMediaProgressId: String) -> LocalMediaProgress? {
|
public func getLocalMediaProgress(localMediaProgressId: String) -> LocalMediaProgress? {
|
||||||
do {
|
do {
|
||||||
@@ -250,7 +250,7 @@ class Database {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func removeLocalMediaProgress(localMediaProgressId: String) throws {
|
public func removeLocalMediaProgress(localMediaProgressId: String) throws {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
try realm.write {
|
try realm.write {
|
||||||
@@ -258,7 +258,7 @@ class Database {
|
|||||||
realm.delete(progress!)
|
realm.delete(progress!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getAllPlaybackSessions() -> [PlaybackSession] {
|
public func getAllPlaybackSessions() -> [PlaybackSession] {
|
||||||
do {
|
do {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
@@ -268,7 +268,7 @@ class Database {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getPlaybackSession(id: String) -> PlaybackSession? {
|
public func getPlaybackSession(id: String) -> PlaybackSession? {
|
||||||
do {
|
do {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
@@ -279,12 +279,12 @@ class Database {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func saveLog(_ log: LogEntry) throws {
|
public func saveLog(_ log: LogEntry) throws {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
return try realm.write { realm.add(log) }
|
return try realm.write { realm.add(log) }
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getAllLogs() -> [LogEntry] {
|
public func getAllLogs() -> [LogEntry] {
|
||||||
do {
|
do {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
@@ -294,7 +294,7 @@ class Database {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func clearLogs() throws {
|
public func clearLogs() throws {
|
||||||
do {
|
do {
|
||||||
let realm = try! Realm()
|
let realm = try! Realm()
|
||||||
@@ -308,25 +308,13 @@ class Database {
|
|||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func cleanExpiredLogs() throws {
|
private func cleanExpiredLogs() throws {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
let numberOfHoursToKeep = 48
|
let numberOfHoursToKeep = 48
|
||||||
let keepLogCutoffMs = Int(Date().addingTimeInterval(TimeInterval(-1 * numberOfHoursToKeep * 3600)).timeIntervalSince1970 * 1000)
|
let keepLogCutoffMs = Int(Date().addingTimeInterval(TimeInterval(-1 * numberOfHoursToKeep * 3600)).timeIntervalSince1970 * 1000)
|
||||||
|
try realm.write {
|
||||||
let allLogs = getAllLogs()
|
realm.delete(realm.objects(LogEntry.self).filter("timestamp < %@", keepLogCutoffMs))
|
||||||
var logsRemoved = 0
|
|
||||||
try? realm.write {
|
|
||||||
allLogs.forEach { log in
|
|
||||||
if log.timestamp < keepLogCutoffMs {
|
|
||||||
realm.delete(log)
|
|
||||||
logsRemoved += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if logsRemoved > 0 {
|
|
||||||
AbsLogger.info(message: "cleanLogs: Removed \(logsRemoved) logs older than \(numberOfHoursToKeep) hours")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user