This commit is contained in:
2022-06-14 21:14:20 +08:00
parent 917d5f2a68
commit be20a22fe9
6 changed files with 107 additions and 20 deletions

View File

@ -16,6 +16,7 @@ import top.jie65535.jcf.model.response.*
/** /**
* [Api docs](https://docs.curseforge.com/) * [Api docs](https://docs.curseforge.com/)
* @author jie65535
*/ */
@OptIn(ExperimentalSerializationApi::class) @OptIn(ExperimentalSerializationApi::class)
class CurseforgeApi(apiKey: String) { class CurseforgeApi(apiKey: String) {
@ -57,7 +58,7 @@ class CurseforgeApi(apiKey: String) {
* Specify a game id for a list of all game categories, * Specify a game id for a list of all game categories,
* or a class id for a list of categories under that class. * or a class id for a list of categories under that class.
*/ */
suspend fun getCategories(gameId: Int, classId: Int?): Array<Category> { suspend fun getCategories(gameId: Int, classId: Int? = null): Array<Category> {
return json.decodeFromString<GetCategoriesResponse>( return json.decodeFromString<GetCategoriesResponse>(
http.get("/v1/categories") { http.get("/v1/categories") {
parameter("gameId", gameId) parameter("gameId", gameId)
@ -87,17 +88,17 @@ class CurseforgeApi(apiKey: String) {
*/ */
suspend fun searchMods( suspend fun searchMods(
gameId: Int, gameId: Int,
classId: Int?, classId: Int? = null,
categoryId: Int?, categoryId: Int? = null,
gameVersion: String?, gameVersion: String? = null,
searchFilter: String?, searchFilter: String? = null,
sortField: ModsSearchSortField?, sortField: ModsSearchSortField? = null,
sortOrder: SortOrder?, sortOrder: SortOrder? = null,
modLoaderType: ModLoaderType?, modLoaderType: ModLoaderType? = null,
gameVersionTypeId: Int?, gameVersionTypeId: Int? = null,
slug: String?, slug: String? = null,
index: Int?, index: Int? = null,
pageSize: Int? pageSize: Int? = null
): SearchModsResponse { ): SearchModsResponse {
return json.decodeFromString( return json.decodeFromString(
http.get("/v1/mods/search") { http.get("/v1/mods/search") {
@ -147,7 +148,7 @@ class CurseforgeApi(apiKey: String) {
suspend fun getFeaturedMods( suspend fun getFeaturedMods(
gameId: Int, gameId: Int,
excludedModIds: IntArray, excludedModIds: IntArray,
gameVersionTypeId: Int? gameVersionTypeId: Int? = null
): FeaturedModsResponse { ): FeaturedModsResponse {
return json.decodeFromString<GetFeaturedModsResponse>( return json.decodeFromString<GetFeaturedModsResponse>(
http.get("/v1/mods/featured") { http.get("/v1/mods/featured") {
@ -183,11 +184,11 @@ class CurseforgeApi(apiKey: String) {
*/ */
suspend fun getModFiles( suspend fun getModFiles(
modId: Int, modId: Int,
gameVersion: String?, gameVersion: String? = null,
modLoaderType: ModLoaderType?, modLoaderType: ModLoaderType? = null,
gameVersionTypeId: Int?, gameVersionTypeId: Int? = null,
index: Int?, index: Int? = null,
pageSize: Int? pageSize: Int? = null
): GetModFilesResponse { ): GetModFilesResponse {
return json.decodeFromString( return json.decodeFromString(
http.get("/v1/mods/$modId/files") { http.get("/v1/mods/$modId/files") {

View File

@ -6,16 +6,59 @@ import java.time.OffsetDateTime
@Serializable @Serializable
class Category( class Category(
/**
* The category id
*/
val id: Int, val id: Int,
/**
* The game id related to the category
*/
val gameId: Int, val gameId: Int,
/**
* Category name
*/
val name: String, val name: String,
/**
* The category slug as it appear in the URL
*/
val slug: String, val slug: String,
/**
* The category URL
*/
val url: String, val url: String,
/**
* URL for the category icon
*/
val iconUrl: String, val iconUrl: String,
/**
* Last modified date of the category
*/
@Serializable(OffsetDateTimeSerializer::class) @Serializable(OffsetDateTimeSerializer::class)
val dateModified: OffsetDateTime, val dateModified: OffsetDateTime,
/**
* A top level category for other categories
*/
val isClass: Boolean?, val isClass: Boolean?,
/**
* The class id of the category, meaning - the class of which this category is under
*/
val classId: Int?, val classId: Int?,
/**
* The parent category for this category
*/
val parentCategoryId: Int?, val parentCategoryId: Int?,
/**
* The display index for this category
*/
val displayIndex: Int? val displayIndex: Int?
) )

View File

@ -2,8 +2,23 @@ package top.jie65535.jcf.model
@kotlinx.serialization.Serializable @kotlinx.serialization.Serializable
class Pagination( class Pagination(
/**
* A zero based index of the first item that is included in the response
*/
val index: Int, val index: Int,
/**
* The requested number of items to be included in the response
*/
val pageSize: Int, val pageSize: Int,
/**
* The actual number of items that were included in the response
*/
val resultCount: Int, val resultCount: Int,
/**
* The total number of items available by the request
*/
val totalCount: Long, val totalCount: Long,
) )

View File

@ -10,19 +10,23 @@ class SortableGameVersion(
* Original version name (e.g. 1.5b) * Original version name (e.g. 1.5b)
*/ */
val gameVersionName: String, val gameVersionName: String,
/** /**
* Used for sorting (e.g. 0000000001.0000000005) * Used for sorting (e.g. 0000000001.0000000005)
*/ */
val gameVersionPadded: String, val gameVersionPadded: String,
/** /**
* game version clean name (e.g. 1.5) * game version clean name (e.g. 1.5)
*/ */
val gameVersion: String, val gameVersion: String,
/** /**
* Game version release date * Game version release date
*/ */
@Serializable(OffsetDateTimeSerializer::class) @Serializable(OffsetDateTimeSerializer::class)
val gameVersionReleaseDate: OffsetDateTime, val gameVersionReleaseDate: OffsetDateTime,
/** /**
* Game version type id * Game version type id
*/ */

View File

@ -7,108 +7,132 @@ import top.jie65535.jcf.model.file.FileIndex
import top.jie65535.jcf.util.OffsetDateTimeSerializer import top.jie65535.jcf.util.OffsetDateTimeSerializer
import java.time.OffsetDateTime import java.time.OffsetDateTime
@kotlinx.serialization.Serializable @Serializable
class Mod( class Mod(
/** /**
* The mod id * The mod id
*/ */
val id: Int, val id: Int,
/** /**
* The game id this mod is for * The game id this mod is for
*/ */
val gameId: Int, val gameId: Int,
/** /**
* The name of the mod * The name of the mod
*/ */
val name: String, val name: String,
/** /**
* The mod slug that would appear in the URL * The mod slug that would appear in the URL
*/ */
val slug: String, val slug: String,
/** /**
* Relevant links for the mod such as Issue tracker and Wiki * Relevant links for the mod such as Issue tracker and Wiki
*/ */
val links: ModLinks, val links: ModLinks,
/** /**
* Mod summary * Mod summary
*/ */
val summary: String, val summary: String,
/** /**
* Current mod status * Current mod status
*/ */
val status: ModStatus, val status: ModStatus,
/** /**
* Number of downloads for the mod * Number of downloads for the mod
*/ */
val downloadCount: Long, val downloadCount: Long,
/** /**
* Whether the mod is included in the featured mods list * Whether the mod is included in the featured mods list
*/ */
val isFeatured: Boolean, val isFeatured: Boolean,
/** /**
* The main category of the mod as it was chosen by the mod author * The main category of the mod as it was chosen by the mod author
*/ */
val primaryCategoryId: Int, val primaryCategoryId: Int,
/** /**
* List of categories that this mod is related to * List of categories that this mod is related to
*/ */
val categories: Array<Category>, val categories: Array<Category>,
/** /**
* The class id this mod belongs to * The class id this mod belongs to
*/ */
val classId: Int?, val classId: Int?,
/** /**
* List of the mod's authors * List of the mod's authors
*/ */
val authors: Array<ModAuthor>, val authors: Array<ModAuthor>,
/** /**
* The mod's logo asset * The mod's logo asset
*/ */
val logo: ModAsset, val logo: ModAsset,
/** /**
* List of screenshots assets * List of screenshots assets
*/ */
val screenshots: Array<ModAsset>, val screenshots: Array<ModAsset>,
/** /**
* The id of the main file of the mod * The id of the main file of the mod
*/ */
val mainFileId: Int, val mainFileId: Int,
/** /**
* List of latest files of the mod * List of latest files of the mod
*/ */
val latestFiles: Array<File>, val latestFiles: Array<File>,
/** /**
* List of file related details for the latest files of the mod * List of file related details for the latest files of the mod
*/ */
val latestFilesIndexes: Array<FileIndex>, val latestFilesIndexes: Array<FileIndex>,
/** /**
* The creation date of the mod * The creation date of the mod
*/ */
@Serializable(OffsetDateTimeSerializer::class) @Serializable(OffsetDateTimeSerializer::class)
val dateCreated: OffsetDateTime, val dateCreated: OffsetDateTime,
/** /**
* The last time the mod was modified * The last time the mod was modified
*/ */
@Serializable(OffsetDateTimeSerializer::class) @Serializable(OffsetDateTimeSerializer::class)
val dateModified: OffsetDateTime, val dateModified: OffsetDateTime,
/** /**
* The release date of the mod * The release date of the mod
*/ */
@Serializable(OffsetDateTimeSerializer::class) @Serializable(OffsetDateTimeSerializer::class)
val dateReleased: OffsetDateTime, val dateReleased: OffsetDateTime,
/** /**
* Is mod allowed to be distributed * Is mod allowed to be distributed
*/ */
val allowModDistribution: Boolean?, val allowModDistribution: Boolean?,
/** /**
* The mod popularity rank for the game * The mod popularity rank for the game
*/ */
val gamePopularityRank: Int, val gamePopularityRank: Int,
/** /**
* Is the mod available for search. This can be false when a mod is experimental, * Is the mod available for search. This can be false when a mod is experimental,
* in a deleted state or has only alpha files * in a deleted state or has only alpha files
*/ */
val isAvailable: Boolean, val isAvailable: Boolean,
/** /**
* The mod's thumbs up count * The mod's thumbs up count
*/ */

View File

@ -5,6 +5,6 @@ import top.jie65535.jcf.model.mod.Mod
@kotlinx.serialization.Serializable @kotlinx.serialization.Serializable
class SearchModsResponse( class SearchModsResponse(
val data: Mod, val data: Array<Mod>,
val pagination: Pagination, val pagination: Pagination,
) )