[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)
|
||||
|
||||
@@ -292,7 +292,7 @@ fun ComicPageView(comicId: String, page: String, navController: NavHostControll
|
||||
showBookMarkPop = false
|
||||
comicPageViewModel.coroutineScope?.launch {
|
||||
MediaManager.postBookmark(comicId.hexToString(), BookMark(name = s, page = comicPageViewModel.pageList[pagerState.currentPage]))
|
||||
comicPageViewModel.comic.value = MediaManager.queryComicInfo(comicId.hexToString())
|
||||
comicPageViewModel.comic.value = MediaManager.queryComicInfoSingle(comicId.hexToString())
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -47,12 +47,12 @@ class ComicGridViewModel : ViewModel()
|
||||
{
|
||||
viewModelScope.launch {
|
||||
if(comic.value == null) {
|
||||
comic.value = MediaManager.queryComicInfo(id)
|
||||
comic.value = MediaManager.queryComicInfoSingle(id)
|
||||
val c = comic.value!!
|
||||
for (i in c.comic.bookmarks) {
|
||||
chapterList.add(i)
|
||||
}
|
||||
}else comic.value = MediaManager.queryComicInfo(id)
|
||||
}else comic.value = MediaManager.queryComicInfoSingle(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class ComicPageViewModel : ViewModel()
|
||||
if(comic.value != null) return
|
||||
LaunchedEffect(id, page) {
|
||||
coroutineScope?.launch {
|
||||
comic.value = MediaManager.queryComicInfo(id)
|
||||
comic.value = MediaManager.queryComicInfoSingle(id)
|
||||
comic.value?.let {
|
||||
pageList.addAll(it.comic.list)
|
||||
title.value = it.comic.comic_name
|
||||
|
||||
@@ -57,14 +57,14 @@ class ComicScreenViewModel : ViewModel() {
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
val l = MediaManager.listComics()
|
||||
for(i in l)
|
||||
{
|
||||
val m = MediaManager.queryComicInfo(i)
|
||||
val m = MediaManager.queryComicInfoBulk(l)
|
||||
if(m != null) {
|
||||
comics.add(m)
|
||||
for(i in m.comic.tags)
|
||||
for(i in m)
|
||||
{
|
||||
insertItem(i)
|
||||
comics.add(i)
|
||||
for(j in i.comic.tags)
|
||||
{
|
||||
insertItem(j)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.acitelight.aether.helper.insertInNaturalOrder
|
||||
import com.acitelight.aether.model.Video
|
||||
import com.acitelight.aether.service.ApiClient.createOkHttp
|
||||
import com.acitelight.aether.service.MediaManager
|
||||
import com.acitelight.aether.service.MediaManager.queryVideoKlasses
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
@@ -56,8 +57,14 @@ class VideoScreenViewModel(application: Application) : AndroidViewModel(applicat
|
||||
classesMap[it] = mutableStateListOf<Video>()
|
||||
}
|
||||
updatingMap[0] = true
|
||||
MediaManager.listVideos(classes[0], listOf()){
|
||||
v -> classesMap[classes[0]]?.insertInNaturalOrder(v)
|
||||
val vl = MediaManager.queryVideoBulk(classes[0],
|
||||
queryVideoKlasses(classes[0])
|
||||
)
|
||||
|
||||
if(vl != null)
|
||||
for(it in vl)
|
||||
{
|
||||
classesMap[classes[0]]?.insertInNaturalOrder(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,11 +76,15 @@ class VideoScreenViewModel(application: Application) : AndroidViewModel(applicat
|
||||
if(updatingMap[index] == true) return@launch
|
||||
|
||||
updatingMap[index] = true
|
||||
MediaManager.listVideos(classes[index], (classesMap[classes[index]]?:listOf()).map{ it.id })
|
||||
|
||||
val vl = MediaManager.queryVideoBulk(classes[index],
|
||||
queryVideoKlasses(classes[index])
|
||||
)
|
||||
|
||||
if(vl != null)
|
||||
for(it in vl)
|
||||
{
|
||||
v ->
|
||||
if(classesMap[classes[index]]?.contains(v) == false)
|
||||
classesMap[classes[index]]?.insertInNaturalOrder(v)
|
||||
classesMap[classes[index]]?.insertInNaturalOrder(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user