mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-28 14:17:19 +02:00
Improved error handling
This commit is contained in:
@@ -70,7 +70,7 @@ public class AbsFileSystem: CAPPlugin {
|
||||
do {
|
||||
if let localLibraryItemId = localLibraryItemId, let item = Database.shared.getLocalLibraryItem(localLibraryItemId: localLibraryItemId) {
|
||||
try FileManager.default.removeItem(at: item.contentDirectory!)
|
||||
item.delete()
|
||||
try item.delete()
|
||||
success = true
|
||||
}
|
||||
} catch {
|
||||
@@ -89,24 +89,29 @@ public class AbsFileSystem: CAPPlugin {
|
||||
|
||||
var success = false
|
||||
if let localLibraryItemId = localLibraryItemId, let trackLocalFileId = trackLocalFileId, let item = Database.shared.getLocalLibraryItem(localLibraryItemId: localLibraryItemId) {
|
||||
item.update {
|
||||
do {
|
||||
if let fileIndex = item.localFiles.firstIndex(where: { $0.id == trackLocalFileId }) {
|
||||
try FileManager.default.removeItem(at: item.localFiles[fileIndex].contentPath)
|
||||
item.realm?.delete(item.localFiles[fileIndex])
|
||||
if item.isPodcast, let media = item.media {
|
||||
if let episodeIndex = media.episodes.firstIndex(where: { $0.audioTrack?.localFileId == trackLocalFileId }) {
|
||||
media.episodes.remove(at: episodeIndex)
|
||||
do {
|
||||
try item.update {
|
||||
do {
|
||||
if let fileIndex = item.localFiles.firstIndex(where: { $0.id == trackLocalFileId }) {
|
||||
try FileManager.default.removeItem(at: item.localFiles[fileIndex].contentPath)
|
||||
item.realm?.delete(item.localFiles[fileIndex])
|
||||
if item.isPodcast, let media = item.media {
|
||||
if let episodeIndex = media.episodes.firstIndex(where: { $0.audioTrack?.localFileId == trackLocalFileId }) {
|
||||
media.episodes.remove(at: episodeIndex)
|
||||
}
|
||||
item.media = media
|
||||
}
|
||||
item.media = media
|
||||
call.resolve(try item.asDictionary())
|
||||
success = true
|
||||
}
|
||||
call.resolve(try item.asDictionary())
|
||||
success = true
|
||||
} catch {
|
||||
NSLog("Failed to delete \(error)")
|
||||
success = false
|
||||
}
|
||||
} catch {
|
||||
NSLog("Failed to delete \(error)")
|
||||
success = false
|
||||
}
|
||||
} catch {
|
||||
NSLog("Failed to delete \(error)")
|
||||
success = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user