1- # # Provides functions for connecting to the unofficial curseforge api .
1+ # # Provides functions for connecting to the CF proxy [https://github.com/bmpm-mc/cfproxy] .
22# #
3- # # The unofficial API has capabilities like:
3+ # # The proxy connects to the official API internally, and has capabilities like:
44# # - Searching for a addon.
55# # - Retrieving an addon by their project id.
66# # - Retrieving the files of an given addon.
77# #
8- # # Some docs for the unofficial API are available at https://gaz492.github.io/.
8+ # # Docs for the official API are available at https://docs.curseforge.com.
9+ # # Requests to the proxy stay the same, except the base URL is switched out.
910
1011import asyncdispatch, json, options, strutils
1112import uri except Url
1213import cfcore, http
1314
1415const
15- # # base url of the forgesvc endpoint
16- addonsBaseUrl = " https://addons-ecs.forgesvc.net/api/v2 "
16+ # # base url of the cfproxy endpoint
17+ addonsBaseUrl = " https://cfproxy.fly.dev "
1718 # # base url of the curse metadata api endpoint
1819 # # used for retrieving mods by their slug, which isn't possible with the curse api
1920 addonsSlugBaseUrl = " https://curse.nikky.moe/graphql"
2021
21- proc fetchAddonsByQuery * (query: string , category = CfAddonGameCategory . Mod ): Future [seq [CfAddon ]] {.async .} =
22+ proc fetchAddonsByQuery * (query: string , category: Option [ CfAddonGameCategory ] ): Future [seq [CfAddon ]] {.async .} =
2223 # # retrieves all addons that match the given `query` search and `category`.
2324 let encodedQuery = encodeUrl (query, usePlus = false )
24- let url = addonsBaseUrl & " /addon/search?gameId=432§ionId=" & $ category & " &pageSize=50&searchFilter=" & encodedQuery
25+ var url = addonsBaseUrl & " /v1/mods/search?gameId=432&pageSize=50&sortField=6&sortOrder=desc&searchFilter=" & encodedQuery
26+ if category.isSome:
27+ url = url & " &classId=" & $ ord (category.get ())
2528 try :
26- return get (url.Url ).await.parseJson.addonsFromForgeSvc
29+ return get (url.Url ).await.parseJson[ " data " ] .addonsFromForgeSvc
2730 except HttpRequestError :
2831 return @ []
2932
33+ proc fetchAddonsByQuery * (query: string ): Future [seq [CfAddon ]] {.async .} =
34+ return await fetchAddonsByQuery (query, category = none [CfAddonGameCategory ]())
35+
3036proc fetchAddon * (projectId: int ): Future [Option [CfAddon ]] {.async .} =
3137 # # get the addon with the given `projectId`.
32- let url = addonsBaseUrl & " /addon /" & $ projectId
38+ let url = addonsBaseUrl & " /v1/mods /" & $ projectId
3339 try :
34- return get (url.Url ).await.parseJson.addonFromForgeSvc.some
40+ return get (url.Url ).await.parseJson[ " data " ] .addonFromForgeSvc.some
3541 except HttpRequestError :
3642 return none [CfAddon ]()
3743
@@ -53,16 +59,16 @@ proc fetchAddon*(slug: string): Future[Option[CfAddon]] {.async.} =
5359
5460proc fetchAddonFiles * (projectId: int ): Future [seq [CfAddonFile ]] {.async .} =
5561 # # get all addon files associated with the given `projectId`.
56- let url = addonsBaseUrl & " /addon/ " & $ projectId & " /files"
62+ let url = addonsBaseUrl & " /v1/mods/ " & $ projectId & " /files?pageSize=10000 "
5763 try :
58- return get (url.Url ).await.parseJson.addonFilesFromForgeSvc
64+ return get (url.Url ).await.parseJson[ " data " ] .addonFilesFromForgeSvc
5965 except HttpRequestError :
6066 return @ []
6167
6268proc fetchAddonFile * (projectId: int , fileId: int ): Future [Option [CfAddonFile ]] {.async .} =
6369 # # get the addon file with the given `fileId` & `projectId`.
64- let url = addonsBaseUrl & " /addon/ " & $ projectId & " /file /" & $ fileId
70+ let url = addonsBaseUrl & " /v1/mods/ " & $ projectId & " /files /" & $ fileId
6571 try :
66- return get (url.Url ).await.parseJson.addonFileFromForgeSvc.some
72+ return get (url.Url ).await.parseJson[ " data " ] .addonFileFromForgeSvc.some
6773 except HttpRequestError :
6874 return none [CfAddonFile ]()
0 commit comments