Debug: add forced bad download queue entry

This commit is contained in:
Nicholas Wallace committed 2026-09-13 14:48:55 -07:00
1 parent da4745217c
commit 108f34bfb7
2 files changed
+107 -2

No files matched your search

@@ -1,5 +1,6 @@
package com.audiobookshelf.app.plugins
import android.net.Uri
import android.os.Environment
import com.audiobookshelf.app.MainActivity
import com.audiobookshelf.app.data.*
@@ -66,6 +67,88 @@ class AbsDownloader : Plugin() {
call.resolve()
}
/** Writes a malformed persisted queue entry for manually testing startup recovery. */
@PluginMethod
fun createInvalidDownloadQueueEntry(call: PluginCall) {
try {
val downloadItemId = "debug-invalid-download"
val filename = "debug-invalid-download.m4b"
val localFolder =
LocalFolder(
"internal-book",
"Internal App Storage",
"",
"",
mainActivity.filesDir.absolutePath,
"internal",
"book"
)
val itemFolder = File(mainActivity.filesDir, "downloads/$downloadItemId")
val stagingFile =
File(mainActivity.filesDir, "download-staging/$downloadItemId/$filename.part")
val finalFile = File(itemFolder, filename)
val part =
DownloadItemPart(
id = "$downloadItemId-part",
downloadItemId = downloadItemId,
filename = filename,
fileSize = 1L,
destinationPath = stagingFile.absolutePath,
finalDestinationPath = finalFile.absolutePath,
serverPath = "/debug/invalid-download",
localFolderName = localFolder.name,
localFolderUrl = localFolder.contentUrl,
localFolderId = localFolder.id,
ebookFile = null,
audioTrack = null,
episode = null,
completed = false,
moved = false,
isMoving = false,
failed = false,
uri = Uri.parse("https://invalid.local/debug/invalid-download"),
destinationUri = Uri.fromFile(stagingFile),
finalDestinationUri = Uri.fromFile(finalFile),
completedDestinationUri = null,
finalDestinationSubfolder = downloadItemId,
downloadId = null,
lastUpdateTime = null,
progress = 0L,
bytesDownloaded = 0L
)
DownloadItemPart::class.java.getDeclaredField("destinationPath").apply {
isAccessible = true
set(part, null)
}
val downloadItem =
DownloadItem(
id = downloadItemId,
libraryItemId = downloadItemId,
episodeId = null,
userMediaProgress = null,
serverConnectionConfigId = "debug",
serverAddress = "https://invalid.local",
serverUserId = "debug",
mediaType = "book",
itemFolderPath = itemFolder.absolutePath,
localFolder = localFolder,
itemTitle = "Invalid Download Queue Test",
itemSubfolder = downloadItemId,
media = MediaType(MediaTypeMetadata("Invalid Download Queue Test", false), null),
downloadItemParts = mutableListOf(part)
)
DeviceManager.dbManager.saveDownloadItem(downloadItem)
AbsLogger.info(tag, "Created malformed download queue entry $downloadItemId")
call.resolve()
} catch (e: Exception) {
AbsLogger.error(tag, "Could not create malformed download queue entry: ${e.message}")
call.reject("Could not create malformed download queue entry", e)
}
}
/** Replays restored queue items when the frontend subscribes to download events. */
@PluginMethod(returnType = PluginMethod.RETURN_NONE)
override fun addListener(call: PluginCall) {
+24 -2
View File
@@ -8,6 +8,10 @@
<ui-icon-btn outlined borderless icon="more_vert" @click="showDialog = true" />
</div>
<div v-if="$platform === 'android'" class="px-4 mb-2">
<ui-btn color="error" small @click="createInvalidDownloadQueueEntry">Create Invalid Download Queue</ui-btn>
</div>
<div class="w-full h-[calc(100%-40px)] overflow-y-auto relative" ref="logContainer">
<div v-if="!logs.length && !isLoading" class="flex items-center justify-center h-32 p-4">
<p class="text-gray-400">{{ $strings.MessageNoLogs }}</p>
@@ -29,7 +33,8 @@
</div>
</template>
<script>
import { AbsLogger } from '@/plugins/capacitor'
import { Dialog } from '@capacitor/dialog'
import { AbsDownloader, AbsLogger } from '@/plugins/capacitor'
import { FileSharer } from '@webnativellc/capacitor-filesharer'
export default {
@@ -60,6 +65,24 @@ export default {
}
},
methods: {
async createInvalidDownloadQueueEntry() {
await this.$hapticsImpact()
const { value } = await Dialog.confirm({
title: 'Create Invalid Download Queue',
message: 'This will add a malformed queue entry. Existing queued downloads will be cleared the next time the app starts.',
okButtonTitle: 'Create',
cancelButtonTitle: this.$strings.ButtonCancel
})
if (!value) return
try {
await AbsDownloader.createInvalidDownloadQueueEntry()
this.$toast.success('Invalid download queue saved. Force-stop and reopen the app.')
} catch (error) {
console.error('Failed to create invalid download queue', error)
this.$toast.error('Failed to create invalid download queue: ' + error.message)
}
},
async dialogAction(action) {
await this.$hapticsImpact()
@@ -172,4 +195,3 @@ export default {
}
}
</script>