diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..089cf0c --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/libs/DgLab-common-4.2.11.18.jar b/libs/DgLab-common-4.3.13.18.jar similarity index 62% rename from libs/DgLab-common-4.2.11.18.jar rename to libs/DgLab-common-4.3.13.18.jar index 548593c..bf86aa7 100644 Binary files a/libs/DgLab-common-4.2.11.18.jar and b/libs/DgLab-common-4.3.13.18.jar differ diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/CheveretoClient.kt b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/CheveretoClient.kt new file mode 100644 index 0000000..c9bdd54 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/CheveretoClient.kt @@ -0,0 +1,107 @@ +package top.r3944realms.ltdmanager.chevereto + +import io.ktor.client.* +import io.ktor.client.call.* +import io.ktor.client.engine.cio.* +import io.ktor.client.plugins.contentnegotiation.* +import io.ktor.client.request.* +import io.ktor.client.request.forms.* +import io.ktor.http.* +import io.ktor.serialization.kotlinx.json.* +import kotlinx.coroutines.* +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.Semaphore +import kotlinx.coroutines.sync.withLock +import kotlinx.coroutines.sync.withPermit +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json +import java.io.ByteArrayInputStream +import java.io.Closeable +import java.io.File +import java.util.* + + +object CheveretoUploader { + + private val client = HttpClient(CIO) { + install(ContentNegotiation) { + json(Json { + ignoreUnknownKeys = true + }) + } + } + + /** + * 上传本地文件 + */ + suspend fun uploadFile( + apiUrl: String, + apiKey: String, + file: File, + title: String? = null, + description: String? = null + ): CheveretoResponse { + return client.submitFormWithBinaryData( + url = apiUrl, + formData = formData { + append("source", file.readBytes(), Headers.build { + append(HttpHeaders.ContentDisposition, "form-data; name=\"source\"; filename=\"${file.name}\"") + }) + append("format", "json") + title?.let { append("title", it) } + description?.let { append("description", it) } + } + ) { + headers { + append("X-API-Key", apiKey) + } + }.body() + } + + /** + * 上传网络图片 URL + */ + suspend fun uploadFromUrl( + apiUrl: String, + apiKey: String, + imageUrl: String + ): CheveretoResponse { + return client.submitForm( + url = apiUrl, + formParameters = Parameters.build { + append("source", imageUrl) + append("format", "json") + } + ) { + headers { + append("X-API-Key", apiKey) + } + }.body() + } + /** + * 上传 ByteArrayInputStream + */ + suspend fun uploadFromStream( + apiUrl: String, + apiKey: String, + inputStream: ByteArrayInputStream, + fileName: String, + title: String? = null, + description: String? = null + ): CheveretoResponse { + val bytes = inputStream.readBytes() + return client.submitFormWithBinaryData( + url = apiUrl, + formData = formData { + append("source", bytes, Headers.build { + append(HttpHeaders.ContentDisposition, "form-data; name=\"source\"; filename=\"$fileName\"") + }) + append("format", "json") + title?.let { append("title", it) } + description?.let { append("description", it) } + } + ) { + headers { append("X-API-Key", apiKey) } + }.body() + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/CheveretoQueueItem.kt b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/CheveretoQueueItem.kt new file mode 100644 index 0000000..f3c2109 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/CheveretoQueueItem.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.chevereto + +class CheveretoQueueItem { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/CheveretoImage.kt b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/CheveretoImage.kt new file mode 100644 index 0000000..a3b536e --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/CheveretoImage.kt @@ -0,0 +1,14 @@ +package top.r3944realms.ltdmanager.chevereto + +import kotlinx.serialization.Serializable + +@Serializable +data class CheveretoImage( + val name: String, + val extension: String, + val size: Long, + val width: Int, + val height: Int, + val date: String, + val url: String +) \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/CheveretoResponse.kt b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/CheveretoResponse.kt new file mode 100644 index 0000000..83395b0 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/CheveretoResponse.kt @@ -0,0 +1,12 @@ +package top.r3944realms.ltdmanager.chevereto + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class CheveretoResponse( + @SerialName("status_code") + val statusCode: Int, + val success: Map? = null, + val image: CheveretoImage? = null +) \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/File.kt b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/File.kt new file mode 100644 index 0000000..04c9fb9 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/File.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.chevereto.data + +class File { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/ImageFile.kt b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/ImageFile.kt new file mode 100644 index 0000000..ea0a283 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/ImageFile.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.chevereto.data + +class ImageFile { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/ImageThumb.kt b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/ImageThumb.kt new file mode 100644 index 0000000..91a6949 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/ImageThumb.kt @@ -0,0 +1,3 @@ +package top.r3944realms.ltdmanager.chevereto.data + +data class ImageThumb() diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/Medium.kt b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/Medium.kt new file mode 100644 index 0000000..b0a10a4 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/Medium.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.chevereto.data + +class Medium { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/Success.kt b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/Success.kt new file mode 100644 index 0000000..56d1c7f --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/chevereto/data/Success.kt @@ -0,0 +1,3 @@ +package top.r3944realms.ltdmanager.chevereto.data + +data class Success() diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/core/config/ImgTuConfig.kt b/src/main/kotlin/top/r3944realms/ltdmanager/core/config/ImgTuConfig.kt new file mode 100644 index 0000000..5aa23cc --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/core/config/ImgTuConfig.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.core.config + +class ImgTuConfig { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/dglab/manager/DgLabManager.kt b/src/main/kotlin/top/r3944realms/ltdmanager/dglab/DgLab.kt similarity index 100% rename from src/main/kotlin/top/r3944realms/ltdmanager/dglab/manager/DgLabManager.kt rename to src/main/kotlin/top/r3944realms/ltdmanager/dglab/DgLab.kt diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/dglab/model/game/PlayerManager.kt b/src/main/kotlin/top/r3944realms/ltdmanager/dglab/model/game/PlayerManager.kt new file mode 100644 index 0000000..b98ac82 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/dglab/model/game/PlayerManager.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.dglab.model.game + +class PlayerManager { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/module/StateModule.kt b/src/main/kotlin/top/r3944realms/ltdmanager/module/StateModule.kt new file mode 100644 index 0000000..6c52f5f --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/module/StateModule.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.module + +class StateModule { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/module/common/AdvancedCommandParser.kt b/src/main/kotlin/top/r3944realms/ltdmanager/module/common/AdvancedCommandParser.kt new file mode 100644 index 0000000..4a0dea0 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/module/common/AdvancedCommandParser.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.module.common + +class AdvancedCommandParser { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/module/common/filter/type/AdvancedCommonFilter.kt b/src/main/kotlin/top/r3944realms/ltdmanager/module/common/filter/type/AdvancedCommonFilter.kt new file mode 100644 index 0000000..0763092 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/module/common/filter/type/AdvancedCommonFilter.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.module.common.filter.type + +class AdvancedCommonFilter { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/GroupMember.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/GroupMember.kt new file mode 100644 index 0000000..13b39f8 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/GroupMember.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.napcat.data + +class GroupMember { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/msghistory/MsgHistoryContent.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/msghistory/MsgHistoryContent.kt new file mode 100644 index 0000000..2cc76b5 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/msghistory/MsgHistoryContent.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.napcat.data.msghistory + +class MsgHistoryContent { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/msghistory/MsgHistoryMessage.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/msghistory/MsgHistoryMessage.kt new file mode 100644 index 0000000..4ee9600 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/msghistory/MsgHistoryMessage.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.napcat.data.msghistory + +class MsgHistoryMessage { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/msghistory/MsgHistoryMessageData.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/msghistory/MsgHistoryMessageData.kt new file mode 100644 index 0000000..2ba6566 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/msghistory/MsgHistoryMessageData.kt @@ -0,0 +1,21 @@ +package top.r3944realms.ltdmanager.napcat.data.msghistory + +import kotlinx.serialization.Serializable +import top.r3944realms.ltdmanager.napcat.data.ID + +@Serializable +data class MsgHistoryMessageData ( + val text: String? = null, + val name: String? = null, + val qq: ID? = null, + val id: ID? = null, + val file: String? = null, + + /** + * 外显 + */ + val summary: String? = null, + + val data: String? = null, + val content: MsgHistoryContent? = null +) \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/msghistory/MsgHistorySpecificMsg.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/msghistory/MsgHistorySpecificMsg.kt new file mode 100644 index 0000000..b915db2 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/data/msghistory/MsgHistorySpecificMsg.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.napcat.data.msghistory + +class MsgHistorySpecificMsg { +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/serializer/MsgHistoryContentSerializer.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/serializer/MsgHistoryContentSerializer.kt new file mode 100644 index 0000000..4e2fba1 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/serializer/MsgHistoryContentSerializer.kt @@ -0,0 +1,4 @@ +package top.r3944realms.ltdmanager.napcat.serializer + +object MsgHistoryContentSerializer { +} \ No newline at end of file diff --git a/src/test/kotlin/top/r394realms/ltdmanagertest/command/Mojang.kt b/src/test/kotlin/top/r394realms/ltdmanagertest/command/Mojang.kt new file mode 100644 index 0000000..ffb70cf --- /dev/null +++ b/src/test/kotlin/top/r394realms/ltdmanagertest/command/Mojang.kt @@ -0,0 +1,2 @@ +package top.r394realms.ltdmanagertest.command + diff --git a/src/test/kotlin/top/r394realms/ltdmanagertest/command/ParameterExtractionDemo.kt b/src/test/kotlin/top/r394realms/ltdmanagertest/command/ParameterExtractionDemo.kt new file mode 100644 index 0000000..649aa0e --- /dev/null +++ b/src/test/kotlin/top/r394realms/ltdmanagertest/command/ParameterExtractionDemo.kt @@ -0,0 +1,4 @@ +package top.r394realms.ltdmanagertest.command + +class ParameterExtractionDemo { +} \ No newline at end of file diff --git a/src/test/kotlin/top/r394realms/ltdmanagertest/command/testACP.kt b/src/test/kotlin/top/r394realms/ltdmanagertest/command/testACP.kt new file mode 100644 index 0000000..567ca5f --- /dev/null +++ b/src/test/kotlin/top/r394realms/ltdmanagertest/command/testACP.kt @@ -0,0 +1,4 @@ +package top.r394realms.ltdmanagertest.command + +class testACP { +} \ No newline at end of file diff --git a/src/test/kotlin/top/r394realms/ltdmanagertest/command/testAdvancedCommandParser.kt b/src/test/kotlin/top/r394realms/ltdmanagertest/command/testAdvancedCommandParser.kt new file mode 100644 index 0000000..ffb70cf --- /dev/null +++ b/src/test/kotlin/top/r394realms/ltdmanagertest/command/testAdvancedCommandParser.kt @@ -0,0 +1,2 @@ +package top.r394realms.ltdmanagertest.command + diff --git a/src/test/kotlin/top/r394realms/ltdmanagertest/msg/sendMsgTest.kt b/src/test/kotlin/top/r394realms/ltdmanagertest/msg/sendMsgTest.kt new file mode 100644 index 0000000..ffdf2ef --- /dev/null +++ b/src/test/kotlin/top/r394realms/ltdmanagertest/msg/sendMsgTest.kt @@ -0,0 +1,4 @@ +package top.r394realms.ltdmanagertest.msg + +class sendMsgTest { +} \ No newline at end of file diff --git a/src/test/kotlin/top/r394realms/ltdmanagertest/testRandom.kt b/src/test/kotlin/top/r394realms/ltdmanagertest/testRandom.kt new file mode 100644 index 0000000..2caf5c4 --- /dev/null +++ b/src/test/kotlin/top/r394realms/ltdmanagertest/testRandom.kt @@ -0,0 +1,4 @@ +package top.r394realms.ltdmanagertest + +class testRandom { +} \ No newline at end of file diff --git a/src/test/kotlin/top/r394realms/ltdmanagertest/util/ImageUploader.kt b/src/test/kotlin/top/r394realms/ltdmanagertest/util/ImageUploader.kt new file mode 100644 index 0000000..8777ee2 --- /dev/null +++ b/src/test/kotlin/top/r394realms/ltdmanagertest/util/ImageUploader.kt @@ -0,0 +1,112 @@ +package top.r394realms.ltdmanagertest.util + + +import okhttp3.* +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.RequestBody.Companion.asRequestBody +import top.r3944realms.ltdmanager.GlobalManager +import top.r3944realms.ltdmanager.utils.LoggerUtil +import java.io.File +import java.io.IOException + +object ImageUploader { + + private val client = OkHttpClient().newBuilder() + .addInterceptor(HttpLoggingInterceptor().apply { + level = HttpLoggingInterceptor.Level.BODY // 查看完整的请求和响应 + }) + .build() + + fun uploadImage(filePath: String, apiKey: String): String { + val file = File(filePath) + + // 检查文件是否存在 + if (!file.exists()) { + throw IllegalArgumentException("文件不存在: $filePath") + } + + LoggerUtil.logger.info("开始上传文件: ${file.name}, 大小: ${file.length()} bytes") + + // 创建 multipart 请求体 + val requestBody = MultipartBody.Builder() + .setType(MultipartBody.FORM) + .addFormDataPart( + "source", + file.name, + file.asRequestBody("image/png".toMediaType()) + ) + .addFormDataPart("format", "json") + .build() + + // 创建请求 + val request = Request.Builder() + .url("https://pic.xiaobuawa.top/api/1/upload") + .header("X-API-Key", apiKey.trim()) // 重要:去除空格 + .post(requestBody) + .build() + + // 执行请求 + val response = client.newCall(request).execute() + try { + if (!response.isSuccessful) { + throw IOException("上传失败,状态码: ${response.code}, 响应: ${response.body?.string()}") + } + + val responseBody = response.body?.string() + LoggerUtil.logger.info("上传成功: $responseBody") + return responseBody ?: throw IOException("响应体为空") + } finally { + response.close() + } + } + + // 异步版本(推荐用于生产环境) + fun uploadImageAsync(filePath: String, apiKey: String, callback: (Result) -> Unit) { + val file = File(filePath) + + if (!file.exists()) { + callback(Result.failure(IllegalArgumentException("文件不存在: $filePath"))) + return + } + + val requestBody = MultipartBody.Builder() + .setType(MultipartBody.FORM) + .addFormDataPart( + "source", + file.name, + file.asRequestBody("image/png".toMediaType()) + ) + .addFormDataPart("format", "json") + .build() + + val request = Request.Builder() + .url("https://pic.xiaobuawa.top/api/1/upload") + .header("X-API-Key", apiKey.trim()) + .post(requestBody) + .build() + + client.newCall(request).enqueue(object : Callback { + override fun onFailure(call: Call, e: IOException) { + callback(Result.failure(e)) + } + + override fun onResponse(call: Call, response: Response) { + try { + if (!response.isSuccessful) { + callback(Result.failure(IOException("上传失败,状态码: ${response.code}"))) + return + } + + val responseBody = response.body?.string() + if (responseBody != null) { + callback(Result.success(responseBody)) + } else { + callback(Result.failure(IOException("响应体为空"))) + } + } catch (e: Exception) { + callback(Result.failure(e)) + } + } + }) + } +} \ No newline at end of file diff --git a/src/test/kotlin/top/r394realms/ltdmanagertest/util/img.kt b/src/test/kotlin/top/r394realms/ltdmanagertest/util/img.kt new file mode 100644 index 0000000..7f78883 --- /dev/null +++ b/src/test/kotlin/top/r394realms/ltdmanagertest/util/img.kt @@ -0,0 +1,4 @@ +package top.r394realms.ltdmanagertest.util + +class img { +} \ No newline at end of file diff --git a/src/test/kotlin/top/r394realms/ltdmanagertest/util/imgv2.kt b/src/test/kotlin/top/r394realms/ltdmanagertest/util/imgv2.kt new file mode 100644 index 0000000..a254a9b --- /dev/null +++ b/src/test/kotlin/top/r394realms/ltdmanagertest/util/imgv2.kt @@ -0,0 +1,2 @@ +package top.r394realms.ltdmanagertest.util + diff --git a/src/test/kotlin/top/r394realms/ltdmanagertest/util/imgv3.kt b/src/test/kotlin/top/r394realms/ltdmanagertest/util/imgv3.kt new file mode 100644 index 0000000..a254a9b --- /dev/null +++ b/src/test/kotlin/top/r394realms/ltdmanagertest/util/imgv3.kt @@ -0,0 +1,2 @@ +package top.r394realms.ltdmanagertest.util + diff --git a/src/test/kotlin/top/r394realms/ltdmanagertest/util/imgv4.kt b/src/test/kotlin/top/r394realms/ltdmanagertest/util/imgv4.kt new file mode 100644 index 0000000..bc291e7 --- /dev/null +++ b/src/test/kotlin/top/r394realms/ltdmanagertest/util/imgv4.kt @@ -0,0 +1,4 @@ +package top.r394realms.ltdmanagertest.util + +class imgv4 { +} \ No newline at end of file