illust-data: タグ付けリクエストができるように
This commit is contained in:
parent
68f07b0d16
commit
80c4b46336
|
@ -0,0 +1,31 @@
|
|||
package dev.usbharu.unos.illust.crud
|
||||
|
||||
import illust.tag.IllustTaggingServiceGrpcKt
|
||||
import illust.tag.taggingRequest
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.*
|
||||
|
||||
interface RequestTaggingService {
|
||||
suspend fun requestTagging(illustId: UUID): List<String>
|
||||
}
|
||||
|
||||
class RequestTaggingServiceImpl(private val clients: List<IllustTaggingServiceGrpcKt.IllustTaggingServiceCoroutineStub>) :
|
||||
RequestTaggingService {
|
||||
override suspend fun requestTagging(illustId: UUID): List<String> {
|
||||
val taggingResults = withContext(Dispatchers.IO) {
|
||||
clients.map {
|
||||
async {
|
||||
it.requestTagging(taggingRequest {
|
||||
this.illustId = illustId.toString()
|
||||
})
|
||||
}
|
||||
}.awaitAll()
|
||||
}
|
||||
|
||||
return taggingResults.flatMap { it.tagsList }
|
||||
}
|
||||
|
||||
}
|
|
@ -9,5 +9,9 @@ message TaggingRequest{
|
|||
|
||||
message TaggingResult{
|
||||
string illust_id = 1;
|
||||
|
||||
repeated string tags = 2;
|
||||
}
|
||||
|
||||
service IllustTaggingService {
|
||||
rpc requestTagging(TaggingRequest) returns (TaggingResult);
|
||||
}
|
Loading…
Reference in New Issue