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] .
2
2
# #
3
- # # The unofficial API has capabilities like:
3
+ # # The proxy connects to the official API internally, and has capabilities like:
4
4
# # - Searching for a addon.
5
5
# # - Retrieving an addon by their project id.
6
6
# # - Retrieving the files of an given addon.
7
7
# #
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.
9
10
10
11
import asyncdispatch, json, options, strutils
11
12
import uri except Url
12
13
import cfcore, http
13
14
14
15
const
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 "
17
18
# # base url of the curse metadata api endpoint
18
19
# # used for retrieving mods by their slug, which isn't possible with the curse api
19
20
addonsSlugBaseUrl = " https://curse.nikky.moe/graphql"
20
21
21
- proc fetchAddonsByQuery* (query: string , category = CfAddonGameCategory.Mod ): Future[seq [CfAddon]] {.async.} =
22
+ proc fetchAddonsByQuery* (query: string , category: Option[ CfAddonGameCategory] ) : Future[seq [CfAddon]] {.async.} =
22
23
# # retrieves all addons that match the given `query` search and `category`.
23
24
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())
25
28
try :
26
- return get(url.Url).await.parseJson.addonsFromForgeSvc
29
+ return get(url.Url).await.parseJson[ " data " ] .addonsFromForgeSvc
27
30
except HttpRequestError:
28
31
return @ []
29
32
33
+ proc fetchAddonsByQuery* (query: string ): Future[seq [CfAddon]] {.async.} =
34
+ return await fetchAddonsByQuery(query, category = none[CfAddonGameCategory]())
35
+
30
36
proc fetchAddon*(projectId: int ): Future[Option[CfAddon]] {.async.} =
31
37
## get the addon with the given `projectId`.
32
- let url = addonsBaseUrl & " /addon /" & $ projectId
38
+ let url = addonsBaseUrl & "/v1/mods /" & $projectId
33
39
try:
34
- return get(url.Url).await.parseJson.addonFromForgeSvc.some
40
+ return get(url.Url).await.parseJson["data " ] .addonFromForgeSvc.some
35
41
except HttpRequestError:
36
42
return none[CfAddon]()
37
43
@@ -53,16 +59,16 @@ proc fetchAddon*(slug: string): Future[Option[CfAddon]] {.async.} =
53
59
54
60
proc fetchAddonFiles*(projectId: int ): Future[seq [CfAddonFile]] {.async.} =
55
61
## 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 "
57
63
try:
58
- return get(url.Url).await.parseJson.addonFilesFromForgeSvc
64
+ return get(url.Url).await.parseJson["data " ] .addonFilesFromForgeSvc
59
65
except HttpRequestError:
60
66
return @ []
61
67
62
68
proc fetchAddonFile* (projectId: int , fileId: int ): Future[Option[CfAddonFile]] {.async.} =
63
69
# # 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
65
71
try :
66
- return get(url.Url).await.parseJson.addonFileFromForgeSvc.some
72
+ return get(url.Url).await.parseJson[ " data " ] .addonFileFromForgeSvc.some
67
73
except HttpRequestError:
68
74
return none[CfAddonFile]()
0 commit comments