From 49ccc1b28ac77d6b5f35f28bea4347eca2664f14 Mon Sep 17 00:00:00 2001 From: laoyuyu Date: Thu, 23 Feb 2023 19:45:21 +0800 Subject: [PATCH] uploader --- .../aria/http/upload/HttpUBlockInterceptor.kt | 31 ++++++++ .../arialyy/aria/http/upload/HttpUTaskUtil.kt | 77 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 Http/src/main/java/com/arialyy/aria/http/upload/HttpUBlockInterceptor.kt create mode 100644 Http/src/main/java/com/arialyy/aria/http/upload/HttpUTaskUtil.kt diff --git a/Http/src/main/java/com/arialyy/aria/http/upload/HttpUBlockInterceptor.kt b/Http/src/main/java/com/arialyy/aria/http/upload/HttpUBlockInterceptor.kt new file mode 100644 index 00000000..ad4228c1 --- /dev/null +++ b/Http/src/main/java/com/arialyy/aria/http/upload/HttpUBlockInterceptor.kt @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.http.upload + +import com.arialyy.aria.core.task.ITaskInterceptor +import com.arialyy.aria.core.task.TaskChain +import com.arialyy.aria.core.task.TaskResp + +/** + * @Author laoyuyu + * @Description + * @Date 9:47 PM 2023/2/21 + **/ +class HttpUBlockInterceptor: ITaskInterceptor { + override suspend fun interceptor(chain: TaskChain): TaskResp { + + } +} \ No newline at end of file diff --git a/Http/src/main/java/com/arialyy/aria/http/upload/HttpUTaskUtil.kt b/Http/src/main/java/com/arialyy/aria/http/upload/HttpUTaskUtil.kt new file mode 100644 index 00000000..858e0536 --- /dev/null +++ b/Http/src/main/java/com/arialyy/aria/http/upload/HttpUTaskUtil.kt @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.http.upload + +import android.os.Looper +import com.arialyy.aria.core.DuaContext +import com.arialyy.aria.core.inf.IBlockManager +import com.arialyy.aria.core.task.AbsTaskUtil +import com.arialyy.aria.core.task.TaskResp +import com.arialyy.aria.exception.AriaException +import com.arialyy.aria.http.HttpTaskOption +import com.arialyy.aria.http.download.HttpBlockThreadInterceptor +import com.arialyy.aria.http.download.HttpDBlockInterceptor +import com.arialyy.aria.http.download.HttpDHeaderInterceptor +import com.arialyy.aria.http.download.TimerInterceptor +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch + +/** + * @Author laoyuyu + * @Description + * @Date 9:21 PM 2023/2/21 + **/ +class HttpUTaskUtil : AbsTaskUtil() { + override fun getBlockManager(): IBlockManager { + TODO("Not yet implemented") + } + + override fun isRunning(): Boolean { + TODO("Not yet implemented") + } + + override fun cancel() { + TODO("Not yet implemented") + } + + override fun stop() { + TODO("Not yet implemented") + } + + override fun start() { + getTask().getTaskOption(HttpTaskOption::class.java).taskInterceptor.let { + if (it.isNotEmpty()) { + addInterceptors(it) + } + } + DuaContext.duaScope.launch(Dispatchers.IO) { + Looper.prepare() + addCoreInterceptor(TimerInterceptor()) + addCoreInterceptor(HttpUBlockInterceptor()) + addCoreInterceptor(HttpBlockThreadInterceptor()) + val resp = interceptor() + if (resp == null || resp.code != TaskResp.CODE_SUCCESS) { + getTask().getTaskOption(HttpTaskOption::class.java).eventListener.onFail( + false, + AriaException("start task fail, task interrupt, code: ${resp?.code ?: TaskResp.CODE_INTERRUPT}") + ) + blockManager?.stop() + return@launch + } + Looper.loop() + } + } +} \ No newline at end of file