mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 18:15:01 +02:00
Handle deleting podcast episodes
This commit is contained in:
parent
4e63d43679
commit
0a989e7811
2 changed files with 31 additions and 9 deletions
|
@ -81,19 +81,40 @@ public class AbsFileSystem: CAPPlugin {
|
|||
}
|
||||
} catch {
|
||||
NSLog("Failed to delete \(error)")
|
||||
success = false
|
||||
}
|
||||
|
||||
call.resolve(["success": success])
|
||||
}
|
||||
|
||||
@objc func deleteTrackFromItem(_ call: CAPPluginCall) {
|
||||
let localLibraryItemId = call.getString("localLibraryItemId")
|
||||
let localLibraryItemId = call.getString("id")
|
||||
let trackLocalFileId = call.getString("trackLocalFileId")
|
||||
let contentUrl = call.getString("contentUrl")
|
||||
|
||||
// TODO: Implement
|
||||
NSLog("deleteTrackFromItem \(localLibraryItemId ?? "UNSET") track file \(trackLocalFileId ?? "UNSET") url \(contentUrl ?? "UNSET")")
|
||||
NSLog("deleteTrackFromItem \(localLibraryItemId ?? "UNSET") track file \(trackLocalFileId ?? "UNSET")")
|
||||
|
||||
call.resolve()
|
||||
var success = false
|
||||
do {
|
||||
if let localLibraryItemId = localLibraryItemId, let trackLocalFileId = trackLocalFileId, var item = Database.shared.getLocalLibraryItem(localLibraryItemId: localLibraryItemId) {
|
||||
if let fileIndex = item.localFiles.firstIndex(where: { $0.id == trackLocalFileId }) {
|
||||
try FileManager.default.removeItem(at: item.localFiles[fileIndex].contentPath)
|
||||
item.localFiles.remove(at: fileIndex)
|
||||
if item.isPodcast, var media = item.media {
|
||||
media.episodes = media.episodes?.filter { $0.audioTrack?.localFileId != trackLocalFileId }
|
||||
item.media = media
|
||||
}
|
||||
Database.shared.saveLocalLibraryItem(localLibraryItem: item)
|
||||
call.resolve(try item.asDictionary())
|
||||
success = true
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
NSLog("Failed to delete \(error)")
|
||||
success = false
|
||||
}
|
||||
|
||||
if !success {
|
||||
call.resolve(["success": success])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,16 +100,16 @@ struct LocalFile: Realmable, Codable {
|
|||
var mimeType: String?
|
||||
var size: Int = 0
|
||||
|
||||
var contentUrl: String {
|
||||
return AbsDownloader.itemDownloadFolder(path: _contentUrl)!.absoluteString
|
||||
}
|
||||
var contentUrl: String { AbsDownloader.itemDownloadFolder(path: _contentUrl)!.absoluteString }
|
||||
var contentPath: URL { AbsDownloader.itemDownloadFolder(path: _contentUrl)! }
|
||||
var basePath: String? { self.filename }
|
||||
|
||||
static func primaryKey() -> String? {
|
||||
return "id"
|
||||
}
|
||||
|
||||
private enum CodingKeys : String, CodingKey {
|
||||
case id, filename, contentUrl, mimeType, size
|
||||
case id, filename, contentUrl, mimeType, size, basePath
|
||||
}
|
||||
|
||||
init() {}
|
||||
|
@ -129,6 +129,7 @@ struct LocalFile: Realmable, Codable {
|
|||
try container.encode(contentUrl, forKey: .contentUrl)
|
||||
try container.encode(mimeType, forKey: .mimeType)
|
||||
try container.encode(size, forKey: .size)
|
||||
try container.encode(basePath, forKey: .basePath)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue