mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 22:13:07 +00:00
* properly pass userMessageLimit to OnchainGroupManager * waku.nimble 2.2.4 Nim compiler * rm stew/shims/net import * change ValidIpAddress.init with parseIpAddress * fix serialize for zerokit * group_manager: separate if statements * protocol_types: add encode UInt32 with zeros up to 32 bytes * windows build: skip libunwind build and rm libunwind.a inlcusion step * bump nph to overcome the compilation issues with 2.2.x * bump nim-libp2p to v1.10.1
54 lines
1.4 KiB
Nim
54 lines
1.4 KiB
Nim
{.push raises: [].}
|
|
|
|
import
|
|
std/json,
|
|
results,
|
|
chronicles,
|
|
chronicles/topics_registry,
|
|
chronos,
|
|
presto/[client, common]
|
|
|
|
type NodeLocation* = object
|
|
country*: string
|
|
city*: string
|
|
lat*: string
|
|
long*: string
|
|
isp*: string
|
|
|
|
proc flatten*[T](a: seq[seq[T]]): seq[T] =
|
|
var aFlat = newSeq[T](0)
|
|
for subseq in a:
|
|
aFlat &= subseq
|
|
return aFlat
|
|
|
|
proc decodeBytes*(
|
|
t: typedesc[NodeLocation], value: openArray[byte], contentType: Opt[ContentTypeData]
|
|
): RestResult[NodeLocation] =
|
|
var res: string
|
|
if len(value) > 0:
|
|
res = newString(len(value))
|
|
copyMem(addr res[0], unsafeAddr value[0], len(value))
|
|
try:
|
|
let jsonContent = parseJson(res)
|
|
if $jsonContent["status"].getStr() != "success":
|
|
error "query failed", result = jsonContent
|
|
return err("query failed")
|
|
return ok(
|
|
NodeLocation(
|
|
country: jsonContent["country"].getStr(),
|
|
city: jsonContent["city"].getStr(),
|
|
lat: $jsonContent["lat"].getFloat(),
|
|
long: $jsonContent["lon"].getFloat(),
|
|
isp: jsonContent["isp"].getStr(),
|
|
)
|
|
)
|
|
except Exception:
|
|
return err("failed to get the location: " & getCurrentExceptionMsg())
|
|
|
|
proc encodeString*(value: string): RestResult[string] =
|
|
ok(value)
|
|
|
|
proc ipToLocation*(
|
|
ip: string
|
|
): RestResponse[NodeLocation] {.rest, endpoint: "json/{ip}", meth: MethodGet.}
|