Cleanup EhEngine
This commit is contained in:
1 parent
2ce2f0ee9b
commit
cec0578b77
2 files changed
+15
-12
No files matched your search
@@ -215,21 +215,19 @@ object EhEngine {
|
||||
galleryInfoList: List<GalleryInfo>,
|
||||
referer: String,
|
||||
) {
|
||||
val ja = JSONArray()
|
||||
var i = 0
|
||||
val size = galleryInfoList.size
|
||||
while (i < size) {
|
||||
val gi = galleryInfoList[i]
|
||||
val g = JSONArray()
|
||||
g.put(gi.gid)
|
||||
g.put(gi.token)
|
||||
ja.put(g)
|
||||
i++
|
||||
}
|
||||
return ehRequest(EhUrl.apiUrl, referer, EhUrl.origin) {
|
||||
jsonBody {
|
||||
put("method", "gdata")
|
||||
put("gidlist", ja)
|
||||
array("gidlist") {
|
||||
galleryInfoList.forEach {
|
||||
put(
|
||||
array {
|
||||
put(it.gid)
|
||||
put(it.token)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
put("namespace", 1)
|
||||
}
|
||||
}.executeAndParsingWith { GalleryApiParser.parse(this, galleryInfoList) }
|
||||
|
||||
@@ -22,6 +22,7 @@ import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.Request
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
inline fun ehRequest(url: String, referer: String? = null, origin: String? = null, builder: Request.Builder.() -> Unit = {}) = Request.Builder().url(url).apply {
|
||||
@@ -38,6 +39,10 @@ inline fun Request.Builder.multipart(builder: MultipartBody.Builder.() -> Unit)
|
||||
|
||||
val MEDIA_TYPE_JSON: MediaType = "application/json; charset=utf-8".toMediaType()
|
||||
|
||||
inline fun JSONObject.array(name: String, builder: JSONArray.() -> Unit): JSONObject = put(name, JSONArray().apply(builder))
|
||||
|
||||
inline fun JSONArray.array(builder: JSONArray.() -> Unit): JSONArray = put(JSONArray().apply(builder))
|
||||
|
||||
inline fun Request.Builder.jsonBody(builder: JSONObject.() -> Unit) = post(JSONObject().apply(builder).toString().toRequestBody(MEDIA_TYPE_JSON))
|
||||
|
||||
fun HttpMessageBuilder.referer(value: String?): Unit = value?.let { headers.append("Referer", it) } ?: Unit
|
||||
|
||||
Reference in new issue
Block a user