DbExternalDownloads.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/database/DbExternalDownloads.kt
1package eu.friedcutlet.yokan.database23import kotlinx.serialization.Serializable45@Serializable enum class PreferredDownloader { BuiltIn, Aria2 }6@Serializable enum class RemoteDownloadState { Pending, Submitting, Active, Waiting, Paused, Error, Complete, Removed, Attention }7@Serializable enum class RemoteDownloadIntent { Run, Pause, Cancel }8@Serializable enum class RemoteDownloadProblem { None, Connection, MissingOrRejected, ServerChanged, InvalidSource }910@Serializable11data class DbExternalDownloads(12 val preferred: PreferredDownloader = PreferredDownloader.BuiltIn,13 val endpoint: String = "",14 val secret: String = "",15 val directory: String = "",16 val jobs: List<DbRemoteDownloadJob> = emptyList(),17)1819@Serializable20data class DbRemoteDownloadJob(21 val id: String,22 val chapterId: Long,23 val itemType: DbItemType,24 val mangaName: String,25 val chapterName: String,26 val endpoint: String,27 /** SHA-256 binding; old controls cannot target a newly configured account. */28 val accountBinding: String,29 val directory: String,30 val files: List<DbRemoteDownloadFile>,31 val intent: RemoteDownloadIntent = RemoteDownloadIntent.Run,32 val problem: RemoteDownloadProblem = RemoteDownloadProblem.None,33 val createdAt: Long = 0,34 val mangaId: Long? = null,35 val sourceId: Long? = null,36 val mangaLink: String? = null,37 val chapterUrl: String = "",38 val sourceTitleName: String = "",39 val sourceChapterName: String = "",40) {41 val complete: Boolean get() = files.isNotEmpty() && files.all { it.state == RemoteDownloadState.Complete }42 val terminal: Boolean get() = files.isNotEmpty() && files.all { it.state in setOf(RemoteDownloadState.Complete, RemoteDownloadState.Removed) }43}4445@Serializable46data class DbRemoteDownloadFile(47 val gid: String,48 val name: String,49 /** Cleared once the server has accepted the task; never exported or synced. */50 val url: String = "",51 val headers: Map<String, String> = emptyMap(),52 val state: RemoteDownloadState = RemoteDownloadState.Pending,53 val totalBytes: Long = 0,54 val completedBytes: Long = 0,55 val errorCode: Int? = null,56 /** Allows identical-representation retries to resume; changed resources get a fresh output file. */57 val resourceBinding: String = "",58)59