package eu.friedcutlet.yokan.database import kotlinx.serialization.Serializable @Serializable enum class PreferredDownloader { BuiltIn, Aria2 } @Serializable enum class RemoteDownloadState { Pending, Submitting, Active, Waiting, Paused, Error, Complete, Removed, Attention } @Serializable enum class RemoteDownloadIntent { Run, Pause, Cancel } @Serializable enum class RemoteDownloadProblem { None, Connection, MissingOrRejected, ServerChanged, InvalidSource } @Serializable data class DbExternalDownloads( val preferred: PreferredDownloader = PreferredDownloader.BuiltIn, val endpoint: String = "", val secret: String = "", val directory: String = "", val jobs: List = emptyList(), ) @Serializable data class DbRemoteDownloadJob( val id: String, val chapterId: Long, val itemType: DbItemType, val mangaName: String, val chapterName: String, val endpoint: String, /** SHA-256 binding; old controls cannot target a newly configured account. */ val accountBinding: String, val directory: String, val files: List, val intent: RemoteDownloadIntent = RemoteDownloadIntent.Run, val problem: RemoteDownloadProblem = RemoteDownloadProblem.None, val createdAt: Long = 0, val mangaId: Long? = null, val sourceId: Long? = null, val mangaLink: String? = null, val chapterUrl: String = "", val sourceTitleName: String = "", val sourceChapterName: String = "", ) { val complete: Boolean get() = files.isNotEmpty() && files.all { it.state == RemoteDownloadState.Complete } val terminal: Boolean get() = files.isNotEmpty() && files.all { it.state in setOf(RemoteDownloadState.Complete, RemoteDownloadState.Removed) } } @Serializable data class DbRemoteDownloadFile( val gid: String, val name: String, /** Cleared once the server has accepted the task; never exported or synced. */ val url: String = "", val headers: Map = emptyMap(), val state: RemoteDownloadState = RemoteDownloadState.Pending, val totalBytes: Long = 0, val completedBytes: Long = 0, val errorCode: Int? = null, /** Allows identical-representation retries to resume; changed resources get a fresh output file. */ val resourceBinding: String = "", )