mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-31 23:20:35 +02:00
Handle deleting library items
This commit is contained in:
parent
8edeefc1cd
commit
60cb5f398c
7 changed files with 40 additions and 22 deletions
|
@ -44,7 +44,7 @@ public class AbsAudioPlayer: CAPPlugin {
|
||||||
|
|
||||||
let isLocalItem = libraryItemId?.starts(with: "local_") ?? false
|
let isLocalItem = libraryItemId?.starts(with: "local_") ?? false
|
||||||
if (isLocalItem) {
|
if (isLocalItem) {
|
||||||
let item = Database.shared.getLocalLibraryItem(localLibraryItem: libraryItemId!)
|
let item = Database.shared.getLocalLibraryItem(localLibraryItemId: libraryItemId!)
|
||||||
// TODO: Logic required for podcasts here
|
// TODO: Logic required for podcasts here
|
||||||
let playbackSession = item?.getPlaybackSession(episode: nil)
|
let playbackSession = item?.getPlaybackSession(episode: nil)
|
||||||
PlayerHandler.startPlayback(session: playbackSession!, playWhenReady: playWhenReady, playbackRate: playbackRate)
|
PlayerHandler.startPlayback(session: playbackSession!, playWhenReady: playWhenReady, playbackRate: playbackRate)
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class AbsDatabase: CAPPlugin {
|
||||||
|
|
||||||
@objc func getLocalLibraryItem(_ call: CAPPluginCall) {
|
@objc func getLocalLibraryItem(_ call: CAPPluginCall) {
|
||||||
do {
|
do {
|
||||||
let item = Database.shared.getLocalLibraryItem(localLibraryItem: call.getString("id") ?? "")
|
let item = Database.shared.getLocalLibraryItem(localLibraryItemId: call.getString("id") ?? "")
|
||||||
switch item {
|
switch item {
|
||||||
case .some(let foundItem):
|
case .some(let foundItem):
|
||||||
call.resolve(try foundItem.asDictionary())
|
call.resolve(try foundItem.asDictionary())
|
||||||
|
@ -97,7 +97,7 @@ public class AbsDatabase: CAPPlugin {
|
||||||
|
|
||||||
@objc func getLocalLibraryItemByLId(_ call: CAPPluginCall) {
|
@objc func getLocalLibraryItemByLId(_ call: CAPPluginCall) {
|
||||||
do {
|
do {
|
||||||
let item = Database.shared.getLocalLibraryItemByLLId(libraryItem: call.getString("libraryItemId") ?? "")
|
let item = Database.shared.getLocalLibraryItem(byServerLibraryItemId: call.getString("libraryItemId") ?? "")
|
||||||
switch item {
|
switch item {
|
||||||
case .some(let foundItem):
|
case .some(let foundItem):
|
||||||
call.resolve(try foundItem.asDictionary())
|
call.resolve(try foundItem.asDictionary())
|
||||||
|
|
|
@ -157,7 +157,7 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
|
||||||
}
|
}
|
||||||
return LocalFile(libraryItem.id, part.filename!, part.mimeType()!, part.destinationUri!, fileSize: Int(part.destinationURL!.fileSize))
|
return LocalFile(libraryItem.id, part.filename!, part.mimeType()!, part.destinationUri!, fileSize: Int(part.destinationURL!.fileSize))
|
||||||
}
|
}
|
||||||
var localLibraryItem = Database.shared.getLocalLibraryItemByLLId(libraryItem: libraryItem.id)
|
var localLibraryItem = Database.shared.getLocalLibraryItem(byServerLibraryItemId: libraryItem.id)
|
||||||
if (localLibraryItem != nil && localLibraryItem!.isPodcast) {
|
if (localLibraryItem != nil && localLibraryItem!.isPodcast) {
|
||||||
try! localLibraryItem?.addFiles(files, item: libraryItem)
|
try! localLibraryItem?.addFiles(files, item: libraryItem)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -67,13 +67,23 @@ public class AbsFileSystem: CAPPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func deleteItem(_ call: CAPPluginCall) {
|
@objc func deleteItem(_ call: CAPPluginCall) {
|
||||||
let localLibraryItemId = call.getString("localLibraryItemId")
|
let localLibraryItemId = call.getString("id")
|
||||||
let contentUrl = call.getString("contentUrl")
|
let contentUrl = call.getString("contentUrl")
|
||||||
|
|
||||||
// TODO: Implement
|
|
||||||
NSLog("deleteItem \(localLibraryItemId ?? "UNSET") url \(contentUrl ?? "UNSET")")
|
NSLog("deleteItem \(localLibraryItemId ?? "UNSET") url \(contentUrl ?? "UNSET")")
|
||||||
|
|
||||||
call.resolve()
|
var success = false
|
||||||
|
do {
|
||||||
|
if let localLibraryItemId = localLibraryItemId, let item = Database.shared.getLocalLibraryItem(localLibraryItemId: localLibraryItemId) {
|
||||||
|
try FileManager.default.removeItem(at: item.contentDirectory!)
|
||||||
|
Database.shared.removeLocalLibraryItem(localLibraryItemId: localLibraryItemId)
|
||||||
|
success = true
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
NSLog("Failed to delete \(error)")
|
||||||
|
}
|
||||||
|
|
||||||
|
call.resolve(["success": success])
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func deleteTrackFromItem(_ call: CAPPluginCall) {
|
@objc func deleteTrackFromItem(_ call: CAPPluginCall) {
|
||||||
|
|
|
@ -31,6 +31,14 @@ struct LocalLibraryItem: Realmable, Codable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var contentDirectory: URL? {
|
||||||
|
if let path = _contentUrl {
|
||||||
|
return AbsDownloader.itemDownloadFolder(path: path)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var coverContentUrl: String? {
|
var coverContentUrl: String? {
|
||||||
if let path = self._coverContentUrl {
|
if let path = self._coverContentUrl {
|
||||||
return AbsDownloader.itemDownloadFolder(path: path)!.absoluteString
|
return AbsDownloader.itemDownloadFolder(path: path)!.absoluteString
|
||||||
|
|
|
@ -108,14 +108,14 @@ class Database {
|
||||||
return Array(realm.objects(LocalLibraryItem.self))
|
return Array(realm.objects(LocalLibraryItem.self))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getLocalLibraryItemByLLId(libraryItem: String) -> LocalLibraryItem? {
|
public func getLocalLibraryItem(byServerLibraryItemId: String) -> LocalLibraryItem? {
|
||||||
let realm = try! Realm()
|
let realm = try! Realm()
|
||||||
return realm.objects(LocalLibraryItem.self).first(where: { $0.libraryItemId == libraryItem })
|
return realm.objects(LocalLibraryItem.self).first(where: { $0.libraryItemId == byServerLibraryItemId })
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getLocalLibraryItem(localLibraryItem: String) -> LocalLibraryItem? {
|
public func getLocalLibraryItem(localLibraryItemId: String) -> LocalLibraryItem? {
|
||||||
let realm = try! Realm()
|
let realm = try! Realm()
|
||||||
return realm.object(ofType: LocalLibraryItem.self, forPrimaryKey: localLibraryItem)
|
return realm.object(ofType: LocalLibraryItem.self, forPrimaryKey: localLibraryItemId)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func saveLocalLibraryItem(localLibraryItem: LocalLibraryItem) {
|
public func saveLocalLibraryItem(localLibraryItem: LocalLibraryItem) {
|
||||||
|
@ -123,6 +123,14 @@ class Database {
|
||||||
try! realm.write { realm.add(localLibraryItem, update: .modified) }
|
try! realm.write { realm.add(localLibraryItem, update: .modified) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func removeLocalLibraryItem(localLibraryItemId: String) {
|
||||||
|
let realm = try! Realm()
|
||||||
|
try! realm.write {
|
||||||
|
let item = getLocalLibraryItem(localLibraryItemId: localLibraryItemId)
|
||||||
|
realm.delete(item!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func getDownloadItem(downloadItemId: String) -> DownloadItem? {
|
public func getDownloadItem(downloadItemId: String) -> DownloadItem? {
|
||||||
let realm = try! Realm()
|
let realm = try! Realm()
|
||||||
return realm.object(ofType: DownloadItem.self, forPrimaryKey: downloadItemId)
|
return realm.object(ofType: DownloadItem.self, forPrimaryKey: downloadItemId)
|
||||||
|
@ -158,14 +166,6 @@ class Database {
|
||||||
return realm.objects(DeviceSettings.self).first ?? getDefaultDeviceSettings()
|
return realm.objects(DeviceSettings.self).first ?? getDefaultDeviceSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func removeLocalLibraryItem(localLibraryItemId: String) {
|
|
||||||
let realm = try! Realm()
|
|
||||||
try! realm.write {
|
|
||||||
let item = getLocalLibraryItemByLLId(libraryItem: localLibraryItemId)
|
|
||||||
realm.delete(item!)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public func saveLocalMediaProgress(_ mediaProgress: LocalMediaProgress) {
|
public func saveLocalMediaProgress(_ mediaProgress: LocalMediaProgress) {
|
||||||
let realm = try! Realm()
|
let realm = try! Realm()
|
||||||
try! realm.write { realm.add(mediaProgress, update: .modified) }
|
try! realm.write { realm.add(mediaProgress, update: .modified) }
|
||||||
|
|
|
@ -322,13 +322,13 @@ export default {
|
||||||
async deleteItem() {
|
async deleteItem() {
|
||||||
const { value } = await Dialog.confirm({
|
const { value } = await Dialog.confirm({
|
||||||
title: 'Confirm',
|
title: 'Confirm',
|
||||||
message: `Warning! This will delete the folder "${this.basePath}" and all contents. Are you sure?`
|
message: `Warning! This will delete "${this.media.metadata.title}" and all associated local files. Are you sure?`
|
||||||
})
|
})
|
||||||
if (value) {
|
if (value) {
|
||||||
var res = await AbsFileSystem.deleteItem(this.localLibraryItem)
|
var res = await AbsFileSystem.deleteItem(this.localLibraryItem)
|
||||||
if (res && res.success) {
|
if (res && res.success) {
|
||||||
this.$toast.success('Deleted Successfully')
|
this.$toast.success('Deleted Successfully')
|
||||||
this.$router.replace(`/localMedia/folders/${this.folderId}`)
|
this.$router.replace(this.isIos ? '/bookshelf' : `/localMedia/folders/${this.folderId}`)
|
||||||
} else this.$toast.error('Failed to delete')
|
} else this.$toast.error('Failed to delete')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue