Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class KomfClientFactory private constructor(private val builder: Builder) {
private val ktor: HttpClient = (builder.ktor ?: HttpClient()).config {
expectSuccess = true
builder.cookieStorage?.let { install(HttpCookies) { storage = it } }
defaultRequest { url(baseUrl()) }
defaultRequest { url(baseUrl().trimEnd('/') + "/") }
install(ContentNegotiation) { json(json) }
install(SSE)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class KomfConfigClient(
) {

suspend fun getConfig(): KomfConfig {
return ktor.get("/api/config").body()
return ktor.get("api/config").body()
}

suspend fun updateConfig(request: KomfConfigUpdateRequest) {
ktor.patch("/api/config") {
ktor.patch("api/config") {
contentType(ContentType.Application.Json)
setBody(request)
}
Expand All @@ -40,7 +40,7 @@ class KomfConfigClient(
fun updateMangaBakaDb(): Flow<DownloadProgress> {
return flow {
runCatching {
ktor.preparePost("/api/update-manga-baka-db").execute { response ->
ktor.preparePost("api/update-manga-baka-db").execute { response ->
streamProgressEvents(response.bodyAsChannel())
}
}.onFailure {
Expand All @@ -52,7 +52,7 @@ class KomfConfigClient(
fun updateBookWalkerDb(): Flow<DownloadProgress> {
return flow {
runCatching {
ktor.preparePost("/api/update-book-walker-db").execute { response ->
ktor.preparePost("api/update-book-walker-db").execute { response ->
streamProgressEvents(response.bodyAsChannel())
}
}.onFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,28 @@ class KomfJobClient(
) {

suspend fun getJob(jobId: KomfMetadataJobId): KomfMetadataJob {
return ktor.get("/api/jobs/$jobId").body()
return ktor.get("api/jobs/$jobId").body()
}

suspend fun getJobs(
status: KomfMetadataJobStatus? = null,
page: Int? = null,
pageSize: Int? = null,
): KomfPage<List<KomfMetadataJob>> {
return ktor.get("/api/jobs") {
return ktor.get("api/jobs") {
status?.let { parameter("status", status.name) }
page?.let { parameter("page", page) }
pageSize?.let { parameter("pageSize", pageSize) }
}.body()
}

suspend fun getJobEvents(jobId: KomfMetadataJobId): Flow<KomfMetadataJobEvent> {
return ktor.sseSession("/api/jobs/${jobId.value}/events").incoming
return ktor.sseSession("api/jobs/${jobId.value}/events").incoming
.map { json.toKomfEvent(it.event, it.data) }
}

suspend fun deleteAll() {
ktor.delete("/api/jobs/all")
ktor.delete("api/jobs/all")
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class KomfMediaServerClient(
private val ktor: HttpClient,
mediaServer: MediaServer
) {
private val mediaServerApiPrefix = "/api/${mediaServer.name.lowercase()}/media-server"
private val mediaServerApiPrefix = "api/${mediaServer.name.lowercase()}/media-server"

suspend fun checkConnection(): KomfMediaServerConnectionResponse {
return ktor.get("$mediaServerApiPrefix/connected").body()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class KomfMetadataClient(
private val ktor: HttpClient,
mediaServer: MediaServer
) {
private val metadataApiPrefix = "/api/${mediaServer.name.lowercase()}/metadata"
private val metadataApiPrefix = "api/${mediaServer.name.lowercase()}/metadata"

suspend fun getProviders(): List<String> {
return ktor.get("/api/metadata/providers").body()
return ktor.get("api/metadata/providers").body()
}

suspend fun searchSeries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,51 @@ class KomfNotificationClient(
private val ktor: HttpClient,
) {
suspend fun getDiscordTemplates(): KomfDiscordTemplates {
return ktor.get("/api/notifications/discord/templates").body()
return ktor.get("api/notifications/discord/templates").body()
}

suspend fun updateDiscordTemplates(templates: KomfDiscordTemplates): KomfDiscordTemplates {
return ktor.post("/api/notifications/discord/templates") {
return ktor.post("api/notifications/discord/templates") {
contentType(ContentType.Application.Json)
setBody(templates)
}.body()
}

suspend fun renderDiscord(request: KomfDiscordRequest): KomfDiscordRenderResult {
return ktor.post("/api/notifications/discord/render") {
return ktor.post("api/notifications/discord/render") {
contentType(ContentType.Application.Json)
setBody(request)
}.body()
}

suspend fun sendDiscord(request: KomfDiscordRequest) {
ktor.post("/api/notifications/discord/send") {
ktor.post("api/notifications/discord/send") {
contentType(ContentType.Application.Json)
setBody(request)
}
}


suspend fun getAppriseTemplates(): KomfAppriseTemplates {
return ktor.get("/api/notifications/apprise/templates").body()
return ktor.get("api/notifications/apprise/templates").body()
}

suspend fun updateAppriseTemplates(templates: KomfAppriseTemplates): KomfAppriseTemplates {
return ktor.post("/api/notifications/apprise/templates") {
return ktor.post("api/notifications/apprise/templates") {
contentType(ContentType.Application.Json)
setBody(templates)
}.body()
}

suspend fun renderApprise(request: KomfAppriseRequest): KomfAppriseRenderResult {
return ktor.post("/api/notifications/apprise/render") {
return ktor.post("api/notifications/apprise/render") {
contentType(ContentType.Application.Json)
setBody(request)
}.body()
}

suspend fun sendApprise(request: KomfAppriseRequest) {
ktor.post("/api/notifications/apprise/send") {
ktor.post("api/notifications/apprise/send") {
contentType(ContentType.Application.Json)
setBody(request)
}
Expand Down