fix compiler-warnings

This commit is contained in:
Leah Thein 2020-12-04 22:08:31 +01:00
parent cb2fcc16dd
commit a03e08b99b
4 changed files with 13 additions and 13 deletions

View file

@ -5,12 +5,12 @@ randomize()
proc cacheExists* (id: string ): bool =
return existsFile(getEnv("CACHE_PATH") & "/" & $id & ".json")
return fileExists(getEnv("CACHE_PATH") & "/" & $id & ".json")
proc getFreeId (): string =
result = toAlphaId(int32(rand(high(int32))))
while existsFile(getEnv("CACHE_PATH") & "/" & $result & ".json"):
while fileExists(getEnv("CACHE_PATH") & "/" & $result & ".json"):
result = toAlphaId(int32(rand(high(int32))))
proc getCacheObject* (reqId: string): CacheObject =
@ -25,7 +25,7 @@ proc saveJourneys* (params: JourneysParams, journeysResponse: JourneysResponse):
for journey in journeysResponse.journeys:
inc(maxId)
journeys.add($maxId, journey)
journeys[$maxId] = journey
var cacheObj = CacheObject(
version: 1,
@ -51,13 +51,13 @@ proc updateJourneys* (reqId: string, mode: moreJourneysMode, journeysResponse: J
cacheObj.minId -= journeysResponse.journeys.len
var cnt = cacheObj.minId
for journey in journeysResponse.journeys:
cacheObj.journeys.add($cnt, journey)
cacheObj.journeys[$cnt] = journey
inc(cnt)
else:
for journey in journeysResponse.journeys:
inc(cacheObj.maxId)
cacheObj.journeys.add($cacheObj.maxId, journey)
cacheObj.journeys[$cacheObj.maxId] = journey
cacheObj.lastUpdated = getTime().toUnix()
if mode != later:
@ -74,7 +74,7 @@ proc updateJourney* (reqId: string, journeyId: string, journey: Journey): Future
var cacheObj = getCacheObject(reqId)
cacheObj.lastUpdated = getTime().toUnix()
cacheObj.journeys.add(journeyId, journey)
cacheObj.journeys[journeyId] = journey
var file = openAsync(getEnv("CACHE_PATH") & "/" & $reqId & ".json", fmReadWrite)
await file.write($(%* cacheObj))

View file

@ -1,4 +1,4 @@
import json, tables, options, asyncdispatch, sequtils
import json, tables, options, asyncdispatch
import ../types, ../backend/hafas, ../cache
when not defined(release):

View file

@ -29,9 +29,9 @@ proc servePath*(req: Request): NimHttpResponse =
let path = "client" & req.url.path.decodeUrl()
#if path.existsDir:
# return sendDirContents(path)
if path.existsFile:
if path.fileExists:
return sendStaticFile(path)
if existsFile(path & "index.html"):
if fileExists(path & "index.html"):
return sendStaticFile(path & "index.html")
else:
raise newException(notFoundException, "NOT_FOUND")

View file

@ -41,10 +41,10 @@ proc handleRequest(req: Request) {.async,gcsafe.} =
proc main() =
endpoints = initTable[string, proc(data: JsonNode): Future[JsonNode] {.gcsafe.}]()
endpoints.add($HttpGet & "/suggestions", suggestionsEndpoint)
endpoints.add($HttpGet & "/journeys", journeysEndpoint)
endpoints.add($HttpGet & "/moreJourneys", moreJourneysEndpoint)
endpoints.add($HttpGet & "/refreshJourney", refreshJourneyEndpoint)
endpoints[$HttpGet & "/suggestions"] = suggestionsEndpoint
endpoints[$HttpGet & "/journeys"] = journeysEndpoint
endpoints[$HttpGet & "/moreJourneys"] = moreJourneysEndpoint
endpoints[$HttpGet & "/refreshJourney"] = refreshJourneyEndpoint
if getEnv("CACHE_PATH") == "":
echo "CACHE_PATH not set! Bye...."