fix compiler-warnings
This commit is contained in:
parent
cb2fcc16dd
commit
a03e08b99b
|
@ -5,12 +5,12 @@ randomize()
|
||||||
|
|
||||||
|
|
||||||
proc cacheExists* (id: string ): bool =
|
proc cacheExists* (id: string ): bool =
|
||||||
return existsFile(getEnv("CACHE_PATH") & "/" & $id & ".json")
|
return fileExists(getEnv("CACHE_PATH") & "/" & $id & ".json")
|
||||||
|
|
||||||
proc getFreeId (): string =
|
proc getFreeId (): string =
|
||||||
result = toAlphaId(int32(rand(high(int32))))
|
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))))
|
result = toAlphaId(int32(rand(high(int32))))
|
||||||
|
|
||||||
proc getCacheObject* (reqId: string): CacheObject =
|
proc getCacheObject* (reqId: string): CacheObject =
|
||||||
|
@ -25,7 +25,7 @@ proc saveJourneys* (params: JourneysParams, journeysResponse: JourneysResponse):
|
||||||
|
|
||||||
for journey in journeysResponse.journeys:
|
for journey in journeysResponse.journeys:
|
||||||
inc(maxId)
|
inc(maxId)
|
||||||
journeys.add($maxId, journey)
|
journeys[$maxId] = journey
|
||||||
|
|
||||||
var cacheObj = CacheObject(
|
var cacheObj = CacheObject(
|
||||||
version: 1,
|
version: 1,
|
||||||
|
@ -51,13 +51,13 @@ proc updateJourneys* (reqId: string, mode: moreJourneysMode, journeysResponse: J
|
||||||
cacheObj.minId -= journeysResponse.journeys.len
|
cacheObj.minId -= journeysResponse.journeys.len
|
||||||
var cnt = cacheObj.minId
|
var cnt = cacheObj.minId
|
||||||
for journey in journeysResponse.journeys:
|
for journey in journeysResponse.journeys:
|
||||||
cacheObj.journeys.add($cnt, journey)
|
cacheObj.journeys[$cnt] = journey
|
||||||
inc(cnt)
|
inc(cnt)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for journey in journeysResponse.journeys:
|
for journey in journeysResponse.journeys:
|
||||||
inc(cacheObj.maxId)
|
inc(cacheObj.maxId)
|
||||||
cacheObj.journeys.add($cacheObj.maxId, journey)
|
cacheObj.journeys[$cacheObj.maxId] = journey
|
||||||
|
|
||||||
cacheObj.lastUpdated = getTime().toUnix()
|
cacheObj.lastUpdated = getTime().toUnix()
|
||||||
if mode != later:
|
if mode != later:
|
||||||
|
@ -74,7 +74,7 @@ proc updateJourney* (reqId: string, journeyId: string, journey: Journey): Future
|
||||||
var cacheObj = getCacheObject(reqId)
|
var cacheObj = getCacheObject(reqId)
|
||||||
|
|
||||||
cacheObj.lastUpdated = getTime().toUnix()
|
cacheObj.lastUpdated = getTime().toUnix()
|
||||||
cacheObj.journeys.add(journeyId, journey)
|
cacheObj.journeys[journeyId] = journey
|
||||||
|
|
||||||
var file = openAsync(getEnv("CACHE_PATH") & "/" & $reqId & ".json", fmReadWrite)
|
var file = openAsync(getEnv("CACHE_PATH") & "/" & $reqId & ".json", fmReadWrite)
|
||||||
await file.write($(%* cacheObj))
|
await file.write($(%* cacheObj))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import json, tables, options, asyncdispatch, sequtils
|
import json, tables, options, asyncdispatch
|
||||||
import ../types, ../backend/hafas, ../cache
|
import ../types, ../backend/hafas, ../cache
|
||||||
|
|
||||||
when not defined(release):
|
when not defined(release):
|
||||||
|
|
|
@ -29,9 +29,9 @@ proc servePath*(req: Request): NimHttpResponse =
|
||||||
let path = "client" & req.url.path.decodeUrl()
|
let path = "client" & req.url.path.decodeUrl()
|
||||||
#if path.existsDir:
|
#if path.existsDir:
|
||||||
# return sendDirContents(path)
|
# return sendDirContents(path)
|
||||||
if path.existsFile:
|
if path.fileExists:
|
||||||
return sendStaticFile(path)
|
return sendStaticFile(path)
|
||||||
if existsFile(path & "index.html"):
|
if fileExists(path & "index.html"):
|
||||||
return sendStaticFile(path & "index.html")
|
return sendStaticFile(path & "index.html")
|
||||||
else:
|
else:
|
||||||
raise newException(notFoundException, "NOT_FOUND")
|
raise newException(notFoundException, "NOT_FOUND")
|
||||||
|
|
|
@ -41,10 +41,10 @@ proc handleRequest(req: Request) {.async,gcsafe.} =
|
||||||
proc main() =
|
proc main() =
|
||||||
endpoints = initTable[string, proc(data: JsonNode): Future[JsonNode] {.gcsafe.}]()
|
endpoints = initTable[string, proc(data: JsonNode): Future[JsonNode] {.gcsafe.}]()
|
||||||
|
|
||||||
endpoints.add($HttpGet & "/suggestions", suggestionsEndpoint)
|
endpoints[$HttpGet & "/suggestions"] = suggestionsEndpoint
|
||||||
endpoints.add($HttpGet & "/journeys", journeysEndpoint)
|
endpoints[$HttpGet & "/journeys"] = journeysEndpoint
|
||||||
endpoints.add($HttpGet & "/moreJourneys", moreJourneysEndpoint)
|
endpoints[$HttpGet & "/moreJourneys"] = moreJourneysEndpoint
|
||||||
endpoints.add($HttpGet & "/refreshJourney", refreshJourneyEndpoint)
|
endpoints[$HttpGet & "/refreshJourney"] = refreshJourneyEndpoint
|
||||||
|
|
||||||
if getEnv("CACHE_PATH") == "":
|
if getEnv("CACHE_PATH") == "":
|
||||||
echo "CACHE_PATH not set! Bye...."
|
echo "CACHE_PATH not set! Bye...."
|
||||||
|
|
Loading…
Reference in a new issue