Skip to content

Commit

Permalink
Merge branch 'development' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
froehlichA committed May 2, 2022
2 parents a7eb44b + eec6259 commit 987c88e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 41 deletions.
19 changes: 7 additions & 12 deletions src/api/cfapi.nim
Expand Up @@ -15,9 +15,6 @@ import cfcore, http
const
## base url of the cfproxy endpoint
addonsBaseUrl = "https://cfproxy.bmpm.workers.dev"
## base url of the curse metadata api endpoint
## used for retrieving mods by their slug, which isn't possible with the curse api
addonsSlugBaseUrl = "https://curse.nikky.moe/graphql"

type
CfApiError* = object of HttpRequestError
Expand Down Expand Up @@ -52,15 +49,13 @@ proc fetchAddons*(projectIds: seq[int]): Future[seq[CfAddon]] {.async.} =

proc fetchAddon*(slug: string): Future[CfAddon] {.async.} =
## get the addon matching the `slug`.
let reqBody = %* {
"query": "{ addons(slug: \"" & slug & "\") { id }}"
}
let curseProxyInfo = await post(addonsSlugBaseUrl.Url, body = $reqBody)
let addons = curseProxyInfo.parseJson["data"]["addons"]
if addons.len == 0:
raise newException(CfApiError, "addon with slug '" & slug & "' not found")
let projectId = addons[0]["id"].getInt()
return await fetchAddon(projectId)
let url = addonsBaseUrl & "/v1/mods/search?gameId=432&pageSize=50&sortField=6&sortOrder=desc&slug=" & slug
try:
return get(url.Url).await.parseJson["data"][0].addonFromForgeSvc
except HttpRequestError:
raise newException(CfApiError, "addon with slug '" & $slug & "' not found.")
except IndexDefect:
raise newException(CfApiError, "addon with slug '" & $slug & "' not found. Please add the addon using the project id instead.")

proc fetchAddonFiles*(projectId: int): Future[seq[CfAddonFile]] {.async.} =
## get all addon files associated with the given `projectId`.
Expand Down
34 changes: 5 additions & 29 deletions tests/cmd/tremove/tremove_without_dependencies.nim
@@ -1,5 +1,5 @@
discard """
joinable: false
joinable: false
batchable: false
input: '''
y
Expand All @@ -26,16 +26,6 @@ let manifestJson = %* {
"author": "testauthor",
"name": "testmodpack123",
"files": [
{
"projectID": 60089,
"fileID": 3202662,
"required": true,
"__meta": {
"name": "Mouse Tweaks",
"explicit": true,
"dependencies": []
}
},
{
"projectID": 238222,
"fileID": 3383205,
Expand All @@ -46,18 +36,6 @@ let manifestJson = %* {
"dependencies": []
}
},
{
"projectID": 240630,
"fileID": 3336760,
"required": true,
"__meta": {
"name": "Just Enough Resources (JER)",
"explicit": true,
"dependencies": [
238222
]
}
},
{
"projectID": 243121,
"fileID": 3366626,
Expand Down Expand Up @@ -88,11 +66,9 @@ block:

createDir("./modpack")
writeFile("./modpack/manifest.json", manifestJson.pretty)
paxRemove("mouse", strategy = "recommended")
paxRemove("jei", strategy = "recommended")

let manifest = readFile("./modpack/manifest.json").parseJson
doAssert manifest["files"].getElems().len == 4
doAssert manifest["files"][0]["__meta"]["name"].getStr() == "Just Enough Items (JEI)"
doAssert manifest["files"][1]["__meta"]["name"].getStr() == "Just Enough Resources (JER)"
doAssert manifest["files"][2]["__meta"]["name"].getStr() == "Quark"
doAssert manifest["files"][3]["__meta"]["name"].getStr() == "AutoRegLib"
doAssert manifest["files"].getElems().len == 2
doAssert manifest["files"][0]["__meta"]["name"].getStr() == "Quark"
doAssert manifest["files"][1]["__meta"]["name"].getStr() == "AutoRegLib"

0 comments on commit 987c88e

Please sign in to comment.