status-lib/status/updates.nim

35 lines
1.0 KiB
Nim
Raw Permalink Normal View History

2021-09-08 18:05:39 +00:00
import stew/byteutils
from stew/base32 import nil
from stew/base58 import nil
2021-12-22 13:41:13 +00:00
import ./statusgo_backend_new/ens as status_ens
2021-09-08 18:05:39 +00:00
import chronicles, httpclient, net
import strutils
2021-12-22 13:41:13 +00:00
import json
2021-09-08 18:05:39 +00:00
import semver
import constants
type
VersionInfo* = object
version*: string
url*: string
proc getLatestVersion*(): VersionInfo =
2021-12-22 13:41:13 +00:00
let response = status_ens.resourceUrl(chainId=1, username=APP_UPDATES_ENS)
let host = response.result{"Host"}.getStr
if host == "":
raise newException(ValueError, "ENS does not have a content hash")
2021-09-08 18:05:39 +00:00
2021-12-22 13:41:13 +00:00
let url = "https://" & host & response.result{"Path"}.getStr
2021-09-08 18:05:39 +00:00
# Read version from folder
let secureSSLContext = newContext()
let client = newHttpClient(sslContext = secureSSLContext, timeout = CHECK_VERSION_TIMEOUT_MS)
result.version = client.getContent(url & "/VERSION").strip()
result.url = url
2021-09-08 18:05:39 +00:00
proc isNewer*(currentVersion, versionToCheck: string): bool =
let lastVersion = parseVersion(versionToCheck)
let currVersion = parseVersion(currentVersion)
result = lastVersion > currVersion