[feat] Bulk Requests
This commit is contained in:
@@ -93,7 +93,7 @@ class AbyssTunnelProxy(
|
||||
|
||||
// Copy from local InputStream into AbyssStream.write in frames.
|
||||
private suspend fun copyExactSuspend(localIn: InputStream, abyss: AbyssStream) = withContext(coroutineContext) {
|
||||
val buffer = ByteArray(16 * 1024)
|
||||
val buffer = ByteArray(64 * 1024)
|
||||
while (true) {
|
||||
val read = localIn.read(buffer)
|
||||
if (read <= 0)
|
||||
@@ -104,13 +104,12 @@ class AbyssTunnelProxy(
|
||||
|
||||
// Copy from AbyssStream (read frames/decrypt) to local OutputStream
|
||||
private suspend fun copyFromAbyssToLocal(abyss: AbyssStream, localOut: OutputStream) = withContext(coroutineContext) {
|
||||
val buffer = ByteArray(16 * 1024)
|
||||
val buffer = ByteArray(64 * 1024)
|
||||
while (true) {
|
||||
val n = abyss.read(buffer, 0, buffer.size)
|
||||
if (n <= 0)
|
||||
break
|
||||
localOut.write(buffer, 0, n)
|
||||
localOut.flush()
|
||||
}
|
||||
}
|
||||
}
|
@@ -28,11 +28,21 @@ interface ApiInterface {
|
||||
@Query("token") token: String
|
||||
): VideoResponse
|
||||
|
||||
@POST("api/video/{klass}/bulkquery")
|
||||
suspend fun queryVideoBulk(
|
||||
@Path("klass") klass: String,
|
||||
@Body() id: List<String>,
|
||||
@Query("token") token: String
|
||||
): List<VideoResponse>
|
||||
|
||||
@GET("api/image")
|
||||
suspend fun getComics(@Query("token") token: String): List<String>
|
||||
@GET("api/image/{id}")
|
||||
suspend fun queryComicInfo(@Path("id") id: String, @Query("token") token: String): ComicResponse
|
||||
|
||||
@POST("api/image/bulkquery")
|
||||
suspend fun queryComicInfoBulk(@Body() id: List<String>, @Query("token") token: String): List<ComicResponse>
|
||||
|
||||
@POST("api/image/{id}/bookmark")
|
||||
suspend fun postBookmark(@Path("id") id: String, @Query("token") token: String, @Body bookmark: BookMark)
|
||||
|
||||
|
@@ -22,7 +22,19 @@ object MediaManager
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun listVideos(klass: String, filter: List<String>, callback: (Video) -> Unit)
|
||||
suspend fun queryVideoKlasses(klass: String): List<String>
|
||||
{
|
||||
try
|
||||
{
|
||||
val j = ApiClient.api!!.queryVideoClasses(klass, token)
|
||||
return j.toList()
|
||||
}catch(e: Exception)
|
||||
{
|
||||
return listOf()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun listVideos(klass: String, filter: List<String>, callback: (Video) -> Unit)
|
||||
{
|
||||
val j = ApiClient.api!!.queryVideoClasses(klass, token)
|
||||
for(it in j)
|
||||
@@ -49,6 +61,17 @@ object MediaManager
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun queryVideoBulk(klass: String, id: List<String>): List<Video>?
|
||||
{
|
||||
try {
|
||||
val j = ApiClient.api!!.queryVideoBulk(klass, id, token)
|
||||
return j.zip(id).map {Video(klass = klass, id = it.second, token=token, it.first)}
|
||||
}catch (e: Exception)
|
||||
{
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun listComics() : List<String>
|
||||
{
|
||||
try{
|
||||
@@ -60,7 +83,7 @@ object MediaManager
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun queryComicInfo(id: String) : Comic?
|
||||
suspend fun queryComicInfoSingle(id: String) : Comic?
|
||||
{
|
||||
try{
|
||||
val j = ApiClient.api!!.queryComicInfo(id, token)
|
||||
@@ -71,6 +94,17 @@ object MediaManager
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun queryComicInfoBulk(id: List<String>) : List<Comic>?
|
||||
{
|
||||
try{
|
||||
val j = ApiClient.api!!.queryComicInfoBulk(id, token)
|
||||
return j.zip(id).map { Comic(id = it.second, comic = it.first, token = token) }
|
||||
}catch (e: Exception)
|
||||
{
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun postBookmark(id: String, bookMark: BookMark): Boolean
|
||||
{
|
||||
try{
|
||||
|
@@ -52,12 +52,16 @@ object RecentManager
|
||||
val r = Json.decodeFromString<List<VideoQueryIndex>>(content)
|
||||
|
||||
recent.clear()
|
||||
val gr = r.groupBy { it.klass }
|
||||
|
||||
for(it in r)
|
||||
for(it in gr)
|
||||
{
|
||||
val v = MediaManager.queryVideo(it.klass, it.id)
|
||||
val v = MediaManager.queryVideoBulk(it.key, it.value.map { it.id })
|
||||
if(v != null)
|
||||
recent.add(recent.size, v)
|
||||
for(j in v)
|
||||
{
|
||||
recent.add(recent.size, j)
|
||||
}
|
||||
}
|
||||
|
||||
return r
|
||||
@@ -82,7 +86,7 @@ object RecentManager
|
||||
|
||||
recent.removeAt(index)
|
||||
}
|
||||
recent.add(0, MediaManager.queryVideo(video.klass, video.id)!!)
|
||||
recent.add(0, MediaManager.queryVideoBulk(video.klass, listOf(video.id))!![0])
|
||||
|
||||
|
||||
if(recent.size >= 21)
|
||||
|
Reference in New Issue
Block a user