|
@@ -21,6 +21,9 @@ import org.gradle.api.Project
|
|
|
import org.gradle.kotlin.dsl.provideDelegate
|
|
import org.gradle.kotlin.dsl.provideDelegate
|
|
|
import java.io.File
|
|
import java.io.File
|
|
|
import java.util.*
|
|
import java.util.*
|
|
|
|
|
+import kotlin.contracts.ExperimentalContracts
|
|
|
|
|
+import kotlin.contracts.InvocationKind
|
|
|
|
|
+import kotlin.contracts.contract
|
|
|
|
|
|
|
|
@Suppress("DEPRECATION")
|
|
@Suppress("DEPRECATION")
|
|
|
object CuiCloud {
|
|
object CuiCloud {
|
|
@@ -77,13 +80,18 @@ object CuiCloud {
|
|
|
val cuiCloudUrl = getUrl(project)
|
|
val cuiCloudUrl = getUrl(project)
|
|
|
val key = getKey(project)
|
|
val key = getKey(project)
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ val bytes = file.readBytes()
|
|
|
|
|
+
|
|
|
runBlocking {
|
|
runBlocking {
|
|
|
- uploadToCuiCloud(
|
|
|
|
|
- cuiCloudUrl,
|
|
|
|
|
- key,
|
|
|
|
|
- "/mirai/${project.name}/${file.nameWithoutExtension}.mp4",
|
|
|
|
|
- file.readBytes()
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ retryCatching(5) {
|
|
|
|
|
+ uploadToCuiCloud(
|
|
|
|
|
+ cuiCloudUrl,
|
|
|
|
|
+ key,
|
|
|
|
|
+ "/mirai/${project.name}/${file.nameWithoutExtension}.mp4",
|
|
|
|
|
+ bytes
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -129,6 +137,30 @@ object CuiCloud {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+@OptIn(ExperimentalContracts::class)
|
|
|
|
|
+@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "RESULT_CLASS_IN_RETURN_TYPE")
|
|
|
|
|
[email protected]
|
|
|
|
|
+internal inline fun <R> retryCatching(n: Int, block: () -> R): Result<R> {
|
|
|
|
|
+ contract {
|
|
|
|
|
+ callsInPlace(block, InvocationKind.AT_LEAST_ONCE)
|
|
|
|
|
+ }
|
|
|
|
|
+ require(n >= 0) { "param n for retryCatching must not be negative" }
|
|
|
|
|
+ var exception: Throwable? = null
|
|
|
|
|
+ repeat(n) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Result.success(block())
|
|
|
|
|
+ } catch (e: Throwable) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ exception?.addSuppressed(e)
|
|
|
|
|
+ } catch (e: Throwable) {
|
|
|
|
|
+ }
|
|
|
|
|
+ exception = e
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.failure(exception!!)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
inline fun <E> buildList(builderAction: MutableList<E>.() -> Unit): List<E> {
|
|
inline fun <E> buildList(builderAction: MutableList<E>.() -> Unit): List<E> {
|
|
|
return ArrayList<E>().apply(builderAction)
|
|
return ArrayList<E>().apply(builderAction)
|
|
|
}
|
|
}
|