CuiPluginCenter Complete

This commit is contained in:
jiahua.liu 2020-04-04 21:28:56 +08:00
parent 20c5b5334d
commit 5b93a48e39
2 changed files with 27 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import com.google.gson.JsonObject
import com.google.gson.JsonParser
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.jsoup.Connection
import org.jsoup.Jsoup
object CuiPluginCenter: PluginCenter{
@ -34,7 +35,7 @@ object CuiPluginCenter: PluginCenter{
this.get("core")?.asString ?: "",
this.get("console")?.asString ?: "",
this.get("author")?.asString ?: "",
this.get("contact")?.asString ?: "",
this.get("description")?.asString ?: "",
this.get("tags")?.asJsonArray?.map { it.asString } ?: arrayListOf(),
this.get("commands")?.asJsonArray?.map { it.asString } ?: arrayListOf()
)
@ -44,7 +45,28 @@ object CuiPluginCenter: PluginCenter{
}
override suspend fun findPlugin(name: String): PluginCenter.PluginInfo? {
TODO()
val result = withContext(Dispatchers.IO){
Jsoup.connect("https://miraiapi.jasonczc.cn/getPluginDetailedInfo?name=$name").method(Connection.Method.GET).ignoreContentType(true).execute()
}.body()
if(result == "err:not found"){
return null
}
return result.asJson().run{
PluginCenter.PluginInfo(
this.get("name")?.asString ?: "",
this.get("version")?.asString ?: "",
this.get("core")?.asString ?: "",
this.get("console")?.asString ?: "",
this.get("tags")?.asJsonArray?.map { it.asString } ?: arrayListOf(),
this.get("author")?.asString ?: "",
this.get("contact")?.asString ?: "",
this.get("description")?.asString ?: "",
this.get("usage")?.asString ?: "",
this.get("vsc")?.asString ?: "",
this.get("commands")?.asJsonArray?.map { it.asString } ?: arrayListOf(),
this.get("changeLog")?.asJsonArray?.map { it.asString } ?: arrayListOf()
)
}
}
override suspend fun refresh() {
@ -55,10 +77,11 @@ object CuiPluginCenter: PluginCenter{
.ignoreContentType(true)
.execute()
}.body().asJson()
if(!(results.has("success") && results["success"].asBoolean)){
error("Failed to fetch plugin list from Cui Cloud")
}
plugins = results.getAsJsonArray("result")//先不解析
plugins = results.get("result").asJsonArray//先不解析
}
override val name: String

View File

@ -28,7 +28,7 @@ interface PluginCenter {
val description: String,
val usage: String,
val vcs: String,
val commands: String,
val commands: List<String>,
val changeLog: List<String>
)