Skip to content

Commit

Permalink
Merge branch 'bugfix/47-fix-index-out-of-bounds-error' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
maradotwebp committed Jul 19, 2021
2 parents 0992f2a + 1a70fb3 commit 7fcb96d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/pr.yml → .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: pr
name: check

on: pull_request
on: [push, pull_request]

env:
APP_NAME: 'pax'
NIM_VERSION: 'stable'

jobs:
Expand Down
9 changes: 7 additions & 2 deletions src/api/cf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ proc fetchMod*(projectId: int): Future[CfMod] {.async.} =

proc fetchMod*(slug: string): Future[CfMod] {.async.} =
## get the mod matching the `slug`
let cfMods = await fetchModsByQuery(slug)
return cfMods.filter((x) => x.websiteUrl.endsWith(slug))[0]
let query = "{ addons(slug: \"" & slug & "\") { id }}"
let reqBody = %* {
"query": query
}
let curseProxyInfo = await post("https://curse.nikky.moe/graphql", body = $reqBody)
let projectId = curseProxyInfo.parseJson["data"]["addons"][0]["id"].getInt()
return await fetchMod(projectId)

proc fetchModFiles*(projectId: int): Future[seq[CfModFile]] {.async.} =
## get all mod files associated with the given `projectId`
Expand Down
8 changes: 7 additions & 1 deletion src/api/http.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ import asyncdispatch, httpclient
proc fetch*(url: string): Future[string] {.async.} =
## fetch the content of a given `url` asynchronously
let http = newAsyncHttpClient()
result = await http.getContent(url)
result = await http.getContent(url)

proc post*(url: string, body: string): Future[string] {.async.} =
## fetch the content of a given `url` with a POST request (asynchronously)
let http = newAsyncHttpClient()
http.headers = newHttpHeaders({ "Content-Type": "application/json" })
result = await http.postContent(url, body)
6 changes: 5 additions & 1 deletion tests/api/tcf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ block: # fetch mod by id
doAssert cfMod.name == "Biomes O' Plenty"

block: # fetch mod by slug
let cfMod = waitFor(fetchMod("appleskin"))
var cfMod = waitFor(fetchMod("appleskin"))
doAssert cfMod.projectId == 248787
cfMod = waitFor(fetchMod("dtbop"))
doAssert cfMod.projectId == 289529
cfMod = waitFor(fetchMod("dtphc"))
doAssert cfMod.projectId == 307560

block: # fetch mod files
let modFiles = waitFor(fetchModFiles(248787))
Expand Down
8 changes: 5 additions & 3 deletions tests/api/thttp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ discard """
import asyncdispatch, api/http

block: # fetch
let googleHttpsReq = fetch("https://www.google.com")
let googleHttpReq = fetch("http://www.google.com")
let exampleReq = fetch("https://example.com")
waitFor(googleHttpsReq and googleHttpReq and exampleReq)
discard waitFor(exampleReq)

block: # post
let apiTestReq = post("https://httpbin.org/post", "{}")
discard waitFor(apiTestReq)

0 comments on commit 7fcb96d

Please sign in to comment.