Update for Nim 1.0.6
This commit is contained in:
parent
35baa815fd
commit
f93bd87316
12 changed files with 33 additions and 42 deletions
|
|
@ -12,16 +12,16 @@ skipExt = @["nim"]
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
requires "nim >= 0.18.1"
|
requires "nim >= 1.0.6"
|
||||||
requires "jester 0.4.0"
|
requires "jester#d8a03aa"
|
||||||
requires "bcrypt#head"
|
requires "bcrypt#head"
|
||||||
requires "hmac#9c61ebe2fd134cf97"
|
requires "hmac#9c61ebe2fd134cf97"
|
||||||
requires "recaptcha 1.0.2"
|
requires "recaptcha#d06488e"
|
||||||
requires "sass#649e0701fa5c"
|
requires "sass#649e0701fa5c"
|
||||||
|
|
||||||
requires "karax#d8df257dd"
|
requires "karax#f6bda9a"
|
||||||
|
|
||||||
requires "webdriver#20f3c1b"
|
requires "webdriver#c2fee57"
|
||||||
|
|
||||||
# Tasks
|
# Tasks
|
||||||
|
|
||||||
|
|
@ -36,7 +36,7 @@ task frontend, "Builds the necessary JS frontend (with CSS)":
|
||||||
exec "nimble c -r src/buildcss"
|
exec "nimble c -r src/buildcss"
|
||||||
exec "nimble js -d:release src/frontend/forum.nim"
|
exec "nimble js -d:release src/frontend/forum.nim"
|
||||||
mkDir "public/js"
|
mkDir "public/js"
|
||||||
cpFile "src/frontend/nimcache/forum.js", "public/js/forum.js"
|
cpFile "src/frontend/forum.js", "public/js/forum.js"
|
||||||
|
|
||||||
task minify, "Minifies the JS using Google's closure compiler":
|
task minify, "Minifies the JS using Google's closure compiler":
|
||||||
exec "closure-compiler public/js/forum.js --js_output_file public/js/forum.js.opt"
|
exec "closure-compiler public/js/forum.js --js_output_file public/js/forum.js.opt"
|
||||||
|
|
|
||||||
|
|
@ -71,13 +71,13 @@ when isMainModule:
|
||||||
"test",
|
"test",
|
||||||
"$2a$08$bY85AhoD1e9u0IsD9sM7Ee6kFSLeXRLxJ6rMgfb1wDnU9liaymoTG",
|
"$2a$08$bY85AhoD1e9u0IsD9sM7Ee6kFSLeXRLxJ6rMgfb1wDnU9liaymoTG",
|
||||||
1526908753,
|
1526908753,
|
||||||
"*B2a] IL\"~sh)q-GBd/i$^>.TL]PR~>1IX>Fp-:M3pCm^cFD\um"
|
"*B2a] IL\"~sh)q-GBd/i$^>.TL]PR~>1IX>Fp-:M3pCm^cFD\\um"
|
||||||
)
|
)
|
||||||
let ident2 = makeIdentHash(
|
let ident2 = makeIdentHash(
|
||||||
"test",
|
"test",
|
||||||
"$2a$08$bY85AhoD1e9u0IsD9sM7Ee6kFSLeXRLxJ6rMgfb1wDnU9liaymoTG",
|
"$2a$08$bY85AhoD1e9u0IsD9sM7Ee6kFSLeXRLxJ6rMgfb1wDnU9liaymoTG",
|
||||||
1526908753,
|
1526908753,
|
||||||
"*B2a] IL\"~sh)q-GBd/i$^>.TL]PR~>1IX>Fp-:M3pCm^cFD\um"
|
"*B2a] IL\"~sh)q-GBd/i$^>.TL]PR~>1IX>Fp-:M3pCm^cFD\\um"
|
||||||
)
|
)
|
||||||
doAssert ident == ident2
|
doAssert ident == ident2
|
||||||
|
|
||||||
|
|
@ -85,6 +85,6 @@ when isMainModule:
|
||||||
"test",
|
"test",
|
||||||
"$2a$08$bY85AhoD1e9u0IsD9sM7Ee6kFSLeXRLxJ6rMgfb1wDnU9liaymoTG",
|
"$2a$08$bY85AhoD1e9u0IsD9sM7Ee6kFSLeXRLxJ6rMgfb1wDnU9liaymoTG",
|
||||||
1526908754,
|
1526908754,
|
||||||
"*B2a] IL\"~sh)q-GBd/i$^>.TL]PR~>1IX>Fp-:M3pCm^cFD\um"
|
"*B2a] IL\"~sh)q-GBd/i$^>.TL]PR~>1IX>Fp-:M3pCm^cFD\\um"
|
||||||
)
|
)
|
||||||
doAssert ident != invalid
|
doAssert ident != invalid
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
import system except Thread
|
import system except Thread
|
||||||
import
|
import
|
||||||
os, strutils, times, md5, strtabs, math, db_sqlite,
|
os, strutils, times, md5, strtabs, math, db_sqlite,
|
||||||
scgi, jester, asyncdispatch, asyncnet, sequtils,
|
jester, asyncdispatch, asyncnet, sequtils,
|
||||||
parseutils, random, rst, recaptcha, json, re, sugar,
|
parseutils, random, rst, recaptcha, json, re, sugar,
|
||||||
strformat, logging
|
strformat, logging
|
||||||
import cgi except setCookie
|
import cgi except setCookie
|
||||||
|
|
@ -76,7 +76,6 @@ proc getGravatarUrl(email: string, size = 80): string =
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
template `||`(x: untyped): untyped = (if not isNil(x): x else: "")
|
|
||||||
|
|
||||||
proc validateCaptcha(recaptchaResp, ip: string) {.async.} =
|
proc validateCaptcha(recaptchaResp, ip: string) {.async.} =
|
||||||
# captcha validation:
|
# captcha validation:
|
||||||
|
|
@ -133,9 +132,9 @@ proc checkLoggedIn(c: TForumData) =
|
||||||
|
|
||||||
let row = getRow(db,
|
let row = getRow(db,
|
||||||
sql"select name, email, status from person where id = ?", c.userid)
|
sql"select name, email, status from person where id = ?", c.userid)
|
||||||
c.username = ||row[0]
|
c.username = row[0]
|
||||||
c.email = ||row[1]
|
c.email = row[1]
|
||||||
c.rank = parseEnum[Rank](||row[2])
|
c.rank = parseEnum[Rank](row[2])
|
||||||
|
|
||||||
# In order to handle the "last visit" line appropriately, i.e.
|
# In order to handle the "last visit" line appropriately, i.e.
|
||||||
# it shouldn't disappear after a refresh, we need to manage a
|
# it shouldn't disappear after a refresh, we need to manage a
|
||||||
|
|
@ -463,7 +462,7 @@ proc executeReply(c: TForumData, threadId: int, content: string,
|
||||||
crud(crCreate, "post", "author", "ip", "content", "thread", "replyingTo"),
|
crud(crCreate, "post", "author", "ip", "content", "thread", "replyingTo"),
|
||||||
c.userId, c.req.ip, content, $threadId,
|
c.userId, c.req.ip, content, $threadId,
|
||||||
if replyingTo.isSome(): $replyingTo.get()
|
if replyingTo.isSome(): $replyingTo.get()
|
||||||
else: nil
|
else: "-1"
|
||||||
)
|
)
|
||||||
discard tryExec(
|
discard tryExec(
|
||||||
db,
|
db,
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ when defined(js):
|
||||||
|
|
||||||
state.error = some(error)
|
state.error = some(error)
|
||||||
except:
|
except:
|
||||||
kout(getCurrentExceptionMsg().cstring)
|
echo getCurrentExceptionMsg()
|
||||||
state.error = some(PostError(
|
state.error = some(PostError(
|
||||||
errorFields: @[],
|
errorFields: @[],
|
||||||
message: "Unknown error occurred."
|
message: "Unknown error occurred."
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ proc onPopState(event: dom.Event) =
|
||||||
# This event is usually only called when the user moves back in their
|
# This event is usually only called when the user moves back in their
|
||||||
# history. I fire it in karaxutils.anchorCB as well to ensure the URL is
|
# history. I fire it in karaxutils.anchorCB as well to ensure the URL is
|
||||||
# always updated. This should be moved into Karax in the future.
|
# always updated. This should be moved into Karax in the future.
|
||||||
kout(kstring"New URL: ", window.location.href, " ", state.url.href)
|
echo "New URL: ", window.location.href, " ", state.url.href
|
||||||
document.title = state.originalTitle
|
document.title = state.originalTitle
|
||||||
if state.url.href != window.location.href:
|
if state.url.href != window.location.href:
|
||||||
state = newState() # Reload the state to remove stale data.
|
state = newState() # Reload the state to remove stale data.
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ proc getInt64*(s: string, default = 0): int64 =
|
||||||
|
|
||||||
when defined(js):
|
when defined(js):
|
||||||
include karax/prelude
|
include karax/prelude
|
||||||
import karax / [kdom]
|
import karax / [kdom, kajax]
|
||||||
|
|
||||||
from dom import nil
|
from dom import nil
|
||||||
|
|
||||||
|
|
@ -87,16 +87,10 @@ when defined(js):
|
||||||
|
|
||||||
navigateTo(url)
|
navigateTo(url)
|
||||||
|
|
||||||
type
|
|
||||||
FormData* = ref object
|
|
||||||
proc newFormData*(): FormData
|
|
||||||
{.importcpp: "new FormData()", constructor.}
|
|
||||||
proc newFormData*(form: dom.Element): FormData
|
proc newFormData*(form: dom.Element): FormData
|
||||||
{.importcpp: "new FormData(@)", constructor.}
|
{.importcpp: "new FormData(@)", constructor.}
|
||||||
proc get*(form: FormData, key: cstring): cstring
|
proc get*(form: FormData, key: cstring): cstring
|
||||||
{.importcpp: "#.get(@)".}
|
{.importcpp: "#.get(@)".}
|
||||||
proc append*(form: FormData, key, val: cstring)
|
|
||||||
{.importcpp: "#.append(@)".}
|
|
||||||
|
|
||||||
proc renderProfileUrl*(username: string): string =
|
proc renderProfileUrl*(username: string): string =
|
||||||
makeUri(fmt"/profile/{username}")
|
makeUri(fmt"/profile/{username}")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
when defined(js):
|
when defined(js):
|
||||||
import sugar, httpcore, options, json
|
import sugar, httpcore, options, json
|
||||||
import dom except Event
|
import dom except Event, KeyboardEvent
|
||||||
|
|
||||||
include karax/prelude
|
include karax/prelude
|
||||||
import karax / [kajax, kdom]
|
import karax / [kajax, kdom]
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ when defined(js):
|
||||||
|
|
||||||
proc performScroll() =
|
proc performScroll() =
|
||||||
let replyBox = dom.document.getElementById("reply-box")
|
let replyBox = dom.document.getElementById("reply-box")
|
||||||
replyBox.scrollIntoView(false)
|
replyBox.scrollIntoView()
|
||||||
|
|
||||||
proc show*(state: ReplyBox) =
|
proc show*(state: ReplyBox) =
|
||||||
# Scroll to the reply box.
|
# Scroll to the reply box.
|
||||||
|
|
@ -44,7 +44,7 @@ when defined(js):
|
||||||
|
|
||||||
proc onPreviewPost(httpStatus: int, response: kstring, state: ReplyBox) =
|
proc onPreviewPost(httpStatus: int, response: kstring, state: ReplyBox) =
|
||||||
postFinished:
|
postFinished:
|
||||||
kout(response)
|
echo response
|
||||||
state.rendering = some[kstring](response)
|
state.rendering = some[kstring](response)
|
||||||
|
|
||||||
proc onPreviewClick(e: Event, n: VNode, state: ReplyBox) =
|
proc onPreviewClick(e: Event, n: VNode, state: ReplyBox) =
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
when defined(js):
|
when defined(js):
|
||||||
import sugar, httpcore, options, json
|
import sugar, httpcore, options, json
|
||||||
import dom except Event
|
import dom except Event, KeyboardEvent
|
||||||
|
|
||||||
include karax/prelude
|
include karax/prelude
|
||||||
import karax / [kajax, kdom]
|
import karax / [kajax, kdom]
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ when defined(js):
|
||||||
if user.isNone(): return not thread.isModerated
|
if user.isNone(): return not thread.isModerated
|
||||||
|
|
||||||
let rank = user.get().rank
|
let rank = user.get().rank
|
||||||
if rank < Moderator and thread.isModerated:
|
if rank < Rank.Moderator and thread.isModerated:
|
||||||
return thread.author == user.get()
|
return thread.author == user.get()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,6 @@ let
|
||||||
import frontend/[karaxutils, error]
|
import frontend/[karaxutils, error]
|
||||||
export parseInt
|
export parseInt
|
||||||
|
|
||||||
proc `%`*[T](opt: Option[T]): JsonNode =
|
|
||||||
## Generic constructor for JSON data. Creates a new ``JNull JsonNode``
|
|
||||||
## if ``opt`` is empty, otherwise it delegates to the underlying value.
|
|
||||||
if opt.isSome: %opt.get else: newJNull()
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Config* = object
|
Config* = object
|
||||||
smtpAddress*: string
|
smtpAddress*: string
|
||||||
|
|
@ -56,7 +51,7 @@ proc loadConfig*(filename = getCurrentDir() / "forum.json"): Config =
|
||||||
smtpPassword: "", mlistAddress: "")
|
smtpPassword: "", mlistAddress: "")
|
||||||
let root = parseFile(filename)
|
let root = parseFile(filename)
|
||||||
result.smtpAddress = root{"smtpAddress"}.getStr("")
|
result.smtpAddress = root{"smtpAddress"}.getStr("")
|
||||||
result.smtpPort = root{"smtpPort"}.getNum(25).int
|
result.smtpPort = root{"smtpPort"}.getInt(25)
|
||||||
result.smtpUser = root{"smtpUser"}.getStr("")
|
result.smtpUser = root{"smtpUser"}.getStr("")
|
||||||
result.smtpPassword = root{"smtpPassword"}.getStr("")
|
result.smtpPassword = root{"smtpPassword"}.getStr("")
|
||||||
result.smtpFromAddr = root{"smtpFromAddr"}.getStr("")
|
result.smtpFromAddr = root{"smtpFromAddr"}.getStr("")
|
||||||
|
|
@ -69,7 +64,7 @@ proc loadConfig*(filename = getCurrentDir() / "forum.json"): Config =
|
||||||
result.name = root["name"].getStr()
|
result.name = root["name"].getStr()
|
||||||
result.title = root["title"].getStr()
|
result.title = root["title"].getStr()
|
||||||
result.ga = root{"ga"}.getStr()
|
result.ga = root{"ga"}.getStr()
|
||||||
result.port = root{"port"}.getNum(5000).int
|
result.port = root{"port"}.getInt(5000)
|
||||||
|
|
||||||
proc processGT(n: XmlNode, tag: string): (int, XmlNode, string) =
|
proc processGT(n: XmlNode, tag: string): (int, XmlNode, string) =
|
||||||
result = (0, newElement(tag), tag)
|
result = (0, newElement(tag), tag)
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ template withBackend(body: untyped): untyped =
|
||||||
|
|
||||||
import browsertests/[scenario1, threads, issue181]
|
import browsertests/[scenario1, threads, issue181]
|
||||||
|
|
||||||
when isMainModule:
|
proc main() =
|
||||||
spawn runProcess("geckodriver -p 4444 --log config")
|
spawn runProcess("geckodriver -p 4444 --log config")
|
||||||
defer:
|
defer:
|
||||||
discard execCmd("killall geckodriver")
|
discard execCmd("killall geckodriver")
|
||||||
|
|
@ -70,3 +70,6 @@ when isMainModule:
|
||||||
except:
|
except:
|
||||||
sleep(10000) # See if we can grab any more output.
|
sleep(10000) # See if we can grab any more output.
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue