mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-29 06:37:16 +02:00
Handle deleting podcast episodes
This commit is contained in:
@@ -81,19 +81,40 @@ public class AbsFileSystem: CAPPlugin {
|
|||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
NSLog("Failed to delete \(error)")
|
NSLog("Failed to delete \(error)")
|
||||||
|
success = false
|
||||||
}
|
}
|
||||||
|
|
||||||
call.resolve(["success": success])
|
call.resolve(["success": success])
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func deleteTrackFromItem(_ call: CAPPluginCall) {
|
@objc func deleteTrackFromItem(_ call: CAPPluginCall) {
|
||||||
let localLibraryItemId = call.getString("localLibraryItemId")
|
let localLibraryItemId = call.getString("id")
|
||||||
let trackLocalFileId = call.getString("trackLocalFileId")
|
let trackLocalFileId = call.getString("trackLocalFileId")
|
||||||
let contentUrl = call.getString("contentUrl")
|
|
||||||
|
|
||||||
// TODO: Implement
|
NSLog("deleteTrackFromItem \(localLibraryItemId ?? "UNSET") track file \(trackLocalFileId ?? "UNSET")")
|
||||||
NSLog("deleteTrackFromItem \(localLibraryItemId ?? "UNSET") track file \(trackLocalFileId ?? "UNSET") url \(contentUrl ?? "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 mimeType: String?
|
||||||
var size: Int = 0
|
var size: Int = 0
|
||||||
|
|
||||||
var contentUrl: String {
|
var contentUrl: String { AbsDownloader.itemDownloadFolder(path: _contentUrl)!.absoluteString }
|
||||||
return AbsDownloader.itemDownloadFolder(path: _contentUrl)!.absoluteString
|
var contentPath: URL { AbsDownloader.itemDownloadFolder(path: _contentUrl)! }
|
||||||
}
|
var basePath: String? { self.filename }
|
||||||
|
|
||||||
static func primaryKey() -> String? {
|
static func primaryKey() -> String? {
|
||||||
return "id"
|
return "id"
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum CodingKeys : String, CodingKey {
|
private enum CodingKeys : String, CodingKey {
|
||||||
case id, filename, contentUrl, mimeType, size
|
case id, filename, contentUrl, mimeType, size, basePath
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {}
|
init() {}
|
||||||
@@ -129,6 +129,7 @@ struct LocalFile: Realmable, Codable {
|
|||||||
try container.encode(contentUrl, forKey: .contentUrl)
|
try container.encode(contentUrl, forKey: .contentUrl)
|
||||||
try container.encode(mimeType, forKey: .mimeType)
|
try container.encode(mimeType, forKey: .mimeType)
|
||||||
try container.encode(size, forKey: .size)
|
try container.encode(size, forKey: .size)
|
||||||
|
try container.encode(basePath, forKey: .basePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user