Add a downloading interaction handler

This commit is contained in:
Syer10
2021-06-11 19:10:05 -04:00
parent 57dcb60d60
commit 28c8de99bc
2 changed files with 44 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package ca.gosyer.data.server.interactions
import ca.gosyer.data.server.Http
import ca.gosyer.data.server.ServerPreferences
import ca.gosyer.data.server.requests.downloadsClearRequest
import ca.gosyer.data.server.requests.downloadsStartRequest
import ca.gosyer.data.server.requests.downloadsStopRequest
import ca.gosyer.util.lang.withIOContext
import io.ktor.client.statement.HttpResponse
import javax.inject.Inject
class DownloadInteractionHandler @Inject constructor(
client: Http,
serverPreferences: ServerPreferences
) : BaseInteractionHandler(client, serverPreferences) {
suspend fun startDownloading() = withIOContext {
client.getRepeat<HttpResponse>(
serverUrl + downloadsStartRequest()
)
}
suspend fun stopDownloading() = withIOContext {
client.getRepeat<HttpResponse>(
serverUrl + downloadsStopRequest()
)
}
suspend fun clearDownloadQueue() = withIOContext {
client.getRepeat<HttpResponse>(
serverUrl + downloadsClearRequest()
)
}
}

View File

@@ -6,14 +6,18 @@
package ca.gosyer.data.server.requests
@Get
fun downloadsQuery() =
"/api/v1/downloads"
@Get
fun downloadsStartRequest() =
"/api/v1/downloads/start"
@Get
fun downloadsStopRequest() =
"/api/v1/downloads/stop"
@Get
fun downloadsClearRequest() =
"/api/v1/downloads/clear"