[feat] Bulk Requests
This commit is contained in:
@@ -93,7 +93,7 @@ class AbyssTunnelProxy(
|
|||||||
|
|
||||||
// Copy from local InputStream into AbyssStream.write in frames.
|
// Copy from local InputStream into AbyssStream.write in frames.
|
||||||
private suspend fun copyExactSuspend(localIn: InputStream, abyss: AbyssStream) = withContext(coroutineContext) {
|
private suspend fun copyExactSuspend(localIn: InputStream, abyss: AbyssStream) = withContext(coroutineContext) {
|
||||||
val buffer = ByteArray(16 * 1024)
|
val buffer = ByteArray(64 * 1024)
|
||||||
while (true) {
|
while (true) {
|
||||||
val read = localIn.read(buffer)
|
val read = localIn.read(buffer)
|
||||||
if (read <= 0)
|
if (read <= 0)
|
||||||
@@ -104,13 +104,12 @@ class AbyssTunnelProxy(
|
|||||||
|
|
||||||
// Copy from AbyssStream (read frames/decrypt) to local OutputStream
|
// Copy from AbyssStream (read frames/decrypt) to local OutputStream
|
||||||
private suspend fun copyFromAbyssToLocal(abyss: AbyssStream, localOut: OutputStream) = withContext(coroutineContext) {
|
private suspend fun copyFromAbyssToLocal(abyss: AbyssStream, localOut: OutputStream) = withContext(coroutineContext) {
|
||||||
val buffer = ByteArray(16 * 1024)
|
val buffer = ByteArray(64 * 1024)
|
||||||
while (true) {
|
while (true) {
|
||||||
val n = abyss.read(buffer, 0, buffer.size)
|
val n = abyss.read(buffer, 0, buffer.size)
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
break
|
break
|
||||||
localOut.write(buffer, 0, n)
|
localOut.write(buffer, 0, n)
|
||||||
localOut.flush()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,11 +28,21 @@ interface ApiInterface {
|
|||||||
@Query("token") token: String
|
@Query("token") token: String
|
||||||
): VideoResponse
|
): 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")
|
@GET("api/image")
|
||||||
suspend fun getComics(@Query("token") token: String): List<String>
|
suspend fun getComics(@Query("token") token: String): List<String>
|
||||||
@GET("api/image/{id}")
|
@GET("api/image/{id}")
|
||||||
suspend fun queryComicInfo(@Path("id") id: String, @Query("token") token: String): ComicResponse
|
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")
|
@POST("api/image/{id}/bookmark")
|
||||||
suspend fun postBookmark(@Path("id") id: String, @Query("token") token: String, @Body bookmark: 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)
|
val j = ApiClient.api!!.queryVideoClasses(klass, token)
|
||||||
for(it in j)
|
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>
|
suspend fun listComics() : List<String>
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
@@ -60,7 +83,7 @@ object MediaManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun queryComicInfo(id: String) : Comic?
|
suspend fun queryComicInfoSingle(id: String) : Comic?
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
val j = ApiClient.api!!.queryComicInfo(id, token)
|
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
|
suspend fun postBookmark(id: String, bookMark: BookMark): Boolean
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
|
|||||||
@@ -52,12 +52,16 @@ object RecentManager
|
|||||||
val r = Json.decodeFromString<List<VideoQueryIndex>>(content)
|
val r = Json.decodeFromString<List<VideoQueryIndex>>(content)
|
||||||
|
|
||||||
recent.clear()
|
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)
|
if(v != null)
|
||||||
recent.add(recent.size, v)
|
for(j in v)
|
||||||
|
{
|
||||||
|
recent.add(recent.size, j)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
@@ -82,7 +86,7 @@ object RecentManager
|
|||||||
|
|
||||||
recent.removeAt(index)
|
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)
|
if(recent.size >= 21)
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ fun ComicPageView(comicId: String, page: String, navController: NavHostControll
|
|||||||
showBookMarkPop = false
|
showBookMarkPop = false
|
||||||
comicPageViewModel.coroutineScope?.launch {
|
comicPageViewModel.coroutineScope?.launch {
|
||||||
MediaManager.postBookmark(comicId.hexToString(), BookMark(name = s, page = comicPageViewModel.pageList[pagerState.currentPage]))
|
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 {
|
viewModelScope.launch {
|
||||||
if(comic.value == null) {
|
if(comic.value == null) {
|
||||||
comic.value = MediaManager.queryComicInfo(id)
|
comic.value = MediaManager.queryComicInfoSingle(id)
|
||||||
val c = comic.value!!
|
val c = comic.value!!
|
||||||
for (i in c.comic.bookmarks) {
|
for (i in c.comic.bookmarks) {
|
||||||
chapterList.add(i)
|
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
|
if(comic.value != null) return
|
||||||
LaunchedEffect(id, page) {
|
LaunchedEffect(id, page) {
|
||||||
coroutineScope?.launch {
|
coroutineScope?.launch {
|
||||||
comic.value = MediaManager.queryComicInfo(id)
|
comic.value = MediaManager.queryComicInfoSingle(id)
|
||||||
comic.value?.let {
|
comic.value?.let {
|
||||||
pageList.addAll(it.comic.list)
|
pageList.addAll(it.comic.list)
|
||||||
title.value = it.comic.comic_name
|
title.value = it.comic.comic_name
|
||||||
|
|||||||
@@ -57,14 +57,14 @@ class ComicScreenViewModel : ViewModel() {
|
|||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val l = MediaManager.listComics()
|
val l = MediaManager.listComics()
|
||||||
for(i in l)
|
val m = MediaManager.queryComicInfoBulk(l)
|
||||||
{
|
if(m != null) {
|
||||||
val m = MediaManager.queryComicInfo(i)
|
for(i in m)
|
||||||
if(m != null) {
|
{
|
||||||
comics.add(m)
|
comics.add(i)
|
||||||
for(i in m.comic.tags)
|
for(j in i.comic.tags)
|
||||||
{
|
{
|
||||||
insertItem(i)
|
insertItem(j)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.acitelight.aether.helper.insertInNaturalOrder
|
|||||||
import com.acitelight.aether.model.Video
|
import com.acitelight.aether.model.Video
|
||||||
import com.acitelight.aether.service.ApiClient.createOkHttp
|
import com.acitelight.aether.service.ApiClient.createOkHttp
|
||||||
import com.acitelight.aether.service.MediaManager
|
import com.acitelight.aether.service.MediaManager
|
||||||
|
import com.acitelight.aether.service.MediaManager.queryVideoKlasses
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
@@ -56,9 +57,15 @@ class VideoScreenViewModel(application: Application) : AndroidViewModel(applicat
|
|||||||
classesMap[it] = mutableStateListOf<Video>()
|
classesMap[it] = mutableStateListOf<Video>()
|
||||||
}
|
}
|
||||||
updatingMap[0] = true
|
updatingMap[0] = true
|
||||||
MediaManager.listVideos(classes[0], listOf()){
|
val vl = MediaManager.queryVideoBulk(classes[0],
|
||||||
v -> classesMap[classes[0]]?.insertInNaturalOrder(v)
|
queryVideoKlasses(classes[0])
|
||||||
}
|
)
|
||||||
|
|
||||||
|
if(vl != null)
|
||||||
|
for(it in vl)
|
||||||
|
{
|
||||||
|
classesMap[classes[0]]?.insertInNaturalOrder(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setTabIndex(index: Int)
|
fun setTabIndex(index: Int)
|
||||||
@@ -69,12 +76,16 @@ class VideoScreenViewModel(application: Application) : AndroidViewModel(applicat
|
|||||||
if(updatingMap[index] == true) return@launch
|
if(updatingMap[index] == true) return@launch
|
||||||
|
|
||||||
updatingMap[index] = true
|
updatingMap[index] = true
|
||||||
MediaManager.listVideos(classes[index], (classesMap[classes[index]]?:listOf()).map{ it.id })
|
|
||||||
{
|
val vl = MediaManager.queryVideoBulk(classes[index],
|
||||||
v ->
|
queryVideoKlasses(classes[index])
|
||||||
if(classesMap[classes[index]]?.contains(v) == false)
|
)
|
||||||
classesMap[classes[index]]?.insertInNaturalOrder(v)
|
|
||||||
}
|
if(vl != null)
|
||||||
|
for(it in vl)
|
||||||
|
{
|
||||||
|
classesMap[classes[index]]?.insertInNaturalOrder(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user