From 616ae0d3b372736777e5a954f0c9ffe7c27be486 Mon Sep 17 00:00:00 2001 From: Majjo <90888719+NoxRare@users.noreply.github.com> Date: Mon, 20 Apr 2026 00:38:02 +0200 Subject: [PATCH] feat: add Developer > Debug Stories config with ZIP dump --- .../download/DownloadProcessor.kt | 24 +++++++++++++++++++ .../common/config/impl/DeveloperConfig.kt | 13 ++++++++++ .../common/config/impl/RootConfig.kt | 1 + 3 files changed, 38 insertions(+) create mode 100644 common/src/main/kotlin/me/eternal/purrfectsnap/common/config/impl/DeveloperConfig.kt diff --git a/app/src/main/kotlin/me/eternal/purrfectsnap/download/DownloadProcessor.kt b/app/src/main/kotlin/me/eternal/purrfectsnap/download/DownloadProcessor.kt index a06c44c5..d3b94b15 100644 --- a/app/src/main/kotlin/me/eternal/purrfectsnap/download/DownloadProcessor.kt +++ b/app/src/main/kotlin/me/eternal/purrfectsnap/download/DownloadProcessor.kt @@ -620,6 +620,30 @@ class DownloadProcessor ( downloadedMedias.values.find { FileType.fromFile(it) == FileType.ZIP }?.let { zipFile -> val oldDownloadedMedias = downloadedMedias.toMap() + // Debug Stories: save raw ZIP to the configured debug folder + val debugConfig = remoteSideContext.config.root.developer.debugStories + if (debugConfig.enabled.get()) { + val debugFolder = debugConfig.saveFolder.get().orEmpty().trim() + if (debugFolder.isNotBlank()) { + runCatching { + val debugDir = android.net.Uri.parse(debugFolder).let { uri -> + androidx.documentfile.provider.DocumentFile.fromTreeUri(remoteSideContext.androidContext, uri) + } + val timestamp = System.currentTimeMillis() + val debugFile = debugDir?.createFile("application/zip", "story_debug_${timestamp}.zip") + debugFile?.uri?.let { fileUri -> + remoteSideContext.androidContext.contentResolver.openOutputStream(fileUri)?.use { out -> + zipFile.inputStream().use { it.copyTo(out) } + } + } + }.onFailure { + remoteSideContext.log.warn("Debug Stories: failed to save zip: ${it.message}", "DownloadProcessor") + } + } else { + remoteSideContext.log.warn("Debug Stories: enabled but no folder configured", "DownloadProcessor") + } + } + var baseMediaFile: File? = null zipFile.inputStream().use { zipFileInputStream -> MediaDownloaderHelper.getSplitElements(zipFileInputStream) { type, inputStream -> diff --git a/common/src/main/kotlin/me/eternal/purrfectsnap/common/config/impl/DeveloperConfig.kt b/common/src/main/kotlin/me/eternal/purrfectsnap/common/config/impl/DeveloperConfig.kt new file mode 100644 index 00000000..ce077bcb --- /dev/null +++ b/common/src/main/kotlin/me/eternal/purrfectsnap/common/config/impl/DeveloperConfig.kt @@ -0,0 +1,13 @@ +package me.eternal.purrfectsnap.common.config.impl + +import me.eternal.purrfectsnap.common.config.ConfigContainer +import me.eternal.purrfectsnap.common.config.ConfigFlag + +class DeveloperConfig : ConfigContainer() { + inner class DebugStoriesConfig : ConfigContainer(hasGlobalState = true) { + val enabled = boolean("enabled", false) + val saveFolder = string("save_folder") { addFlags(ConfigFlag.FOLDER, ConfigFlag.SENSITIVE) } + } + + val debugStories = container("debug_stories", DebugStoriesConfig()) +} diff --git a/common/src/main/kotlin/me/eternal/purrfectsnap/common/config/impl/RootConfig.kt b/common/src/main/kotlin/me/eternal/purrfectsnap/common/config/impl/RootConfig.kt index 3885f851..09200c10 100644 --- a/common/src/main/kotlin/me/eternal/purrfectsnap/common/config/impl/RootConfig.kt +++ b/common/src/main/kotlin/me/eternal/purrfectsnap/common/config/impl/RootConfig.kt @@ -20,4 +20,5 @@ class RootConfig : ConfigContainer() { val scripting = container("scripting", Scripting()) { icon = Icons.Default.DataObject } val friendTracker = container("friend_tracker", FriendTrackerConfig()) { icon = Icons.Default.PersonSearch } val companionServer = container("companion_server", CompanionServerConfig()) { icon = Icons.Default.Monitor } + val developer = container("developer", DeveloperConfig()) { icon = Icons.Default.Code } } \ No newline at end of file