Compare commits

..

No commits in common. "main" and "1.0.9" have entirely different histories.
main ... 1.0.9

6 changed files with 26 additions and 30 deletions

View File

@ -1 +0,0 @@
nim 1.6.20

View File

@ -1,7 +1,7 @@
## Personal Time Keeping API Interface
## ===================================
import asyncdispatch, base64, bcrypt, cliutils, docopt, httpcore, jester, json, logging,
import asyncdispatch, base64, bcrypt, cliutils, docopt, jester, json, logging,
sequtils, strutils, os, tables, times, uuids
import nre except toSeq
@ -61,10 +61,10 @@ template checkAuth(cfg: PtkApiCfg) =
var user {.inject.}: PtkUser = PtkUser()
try:
if not headers(request).hasKey("Authorization"):
if not request.headers.hasKey("Authorization"):
raiseEx "No auth token."
let headerVal = headers(request)["Authorization"]
let headerVal = request.headers["Authorization"]
if not headerVal.startsWith("Basic "):
raiseEx "Invalid Authorization type (only 'Basic' is supported)."

View File

@ -22,18 +22,10 @@ const ISO_TIME_FORMAT* = "yyyy-MM-dd'T'HH:mm:ss"
## The canonical time format used by PTK.
const TIME_FORMATS* = @[
(fmtStr: "yyyy-MM-dd'T'HH:mm:sszzz", offsetFrom: OffsetFrom.None),
(fmtStr: "yyyy-MM-dd HH:mm:sszzz", offsetFrom: OffsetFrom.None),
(fmtStr: "yyyy-MM-dd'T'HH:mm:sszz", offsetFrom: OffsetFrom.None),
(fmtStr: "yyyy-MM-dd HH:mm:sszz", offsetFrom: OffsetFrom.None),
(fmtStr: "yyyy-MM-dd'T'HH:mm:ssz", offsetFrom: OffsetFrom.None),
(fmtStr: "yyyy-MM-dd HH:mm:ssz", offsetFrom: OffsetFrom.None),
(fmtStr: "yyyy-MM-dd'T'HH:mm:ss", offsetFrom: OffsetFrom.None),
(fmtStr: "yyyy-MM-dd HH:mm:ss", offsetFrom: OffsetFrom.None),
(fmtStr: "yyyy-MM-dd'T'HH:mm", offsetFrom: OffsetFrom.None),
(fmtStr: "yyyy-MM-dd HH:mm", offsetFrom: OffsetFrom.None),
(fmtStr: "yyyy-MM-dd", offsetFrom: OffsetFrom.None),
(fmtStr: "yyyy-MM", offsetFrom: OffsetFrom.None),
(fmtStr: "MM-dd'T'HH:mm:ss", offsetFrom: OffsetFrom.Year),
(fmtStr: "MM-dd HH:mm:ss", offsetFrom: OffsetFrom.Year),
(fmtStr: "MM-dd'T'HH:mm", offsetFrom: OffsetFrom.Year),
@ -56,16 +48,15 @@ proc getIfExists*(n: JsonNode, key: string): JsonNode =
proc parseTime*(timeStr: string): DateTime =
## Helper to parse time strings trying multiple known formats.
let now = now()
for fmt in TIME_FORMATS:
try:
let now = now()
let parsed = parse(timeStr, fmt.fmtStr)
case fmt.offsetFrom:
of OffsetFrom.None:
return parsed
of OffsetFrom.Year:
return dateTime(now.year, parsed.month, parsed.monthday,
return initDateTime(parsed.monthday, parsed.month, now.year,
parsed.hour, parsed.minute, parsed.second, parsed.nanosecond,
now.timezone)
of OffsetFrom.Month:

View File

@ -1 +1 @@
const PTK_VERSION* = "1.0.14"
const PTK_VERSION* = "1.0.9"

24
ptk.nim
View File

@ -307,21 +307,27 @@ Options:
quit()
# Find and parse the .ptkrc file
let ptkrcLocations =
if args["--config"]: @[$args["--config"]]
else: @[".ptkrc", $getEnv("PTKRC"), $getEnv("HOME") & "/.ptkrc"]
let ptkrcLocations = @[
if args["--config"]: $args["--config"] else:"",
".ptkrc", $getEnv("PTKRC"), $getEnv("HOME") & "/.ptkrc"]
let foundPtkrcLocations =
ptkrcLocations.filterIt(it.len > 0 and fileExists(it))
var ptkrcFilename: string =
foldl(ptkrcLocations, if len(a) > 0: a elif fileExists(b): b else: "")
var cfg: JsonNode
if foundPtkrcLocations.len < 1:
var cfgFile: File
if not fileExists(ptkrcFilename):
warn "ptk: could not find .ptkrc file."
debug "ptk: considered the following locations:\n\t" & ptkrcLocations.join("\n\t")
ptkrcFilename = $getEnv("HOME") & "/.ptkrc"
try:
cfgFile = open(ptkrcFilename, fmWrite)
cfgFile.write("{\"timelineLogFile\": \"timeline.log.json\"}")
except: warn "ptk: could not write default .ptkrc to " & ptkrcFilename
finally: close(cfgFile)
try: cfg = parseFile(foundPtkrcLocations[0])
try: cfg = parseFile(ptkrcFilename)
except: raise newException(IOError,
"unable to read config file: " & foundPtkrcLocations[0] &
"unable to read config file: " & ptkrcFilename &
"\x0D\x0A" & getCurrentExceptionMsg())
# Find the time log file

View File

@ -1,6 +1,6 @@
# Package
version = "1.0.14"
version = "1.0.9"
author = "Jonathan Bernard"
description = "Personal Time Keeper"
license = "MIT"
@ -16,10 +16,10 @@ requires @[
"isaac >= 0.1.3",
"bcrypt",
"jester 0.5.0",
"https://git.jdb-software.com/jdb/nim-lang-utils.git",
"https://git.jdb-software.com/jdb/nim-cli-utils.git >= 0.6.5",
"https://git.jdb-software.com/jdb/nim-time-utils.git >= 0.5.2",
"https://git.jdb-software.com/jdb/update-nim-package-version"
"https://git.jdb-labs.com/jdb/nim-lang-utils.git",
"https://git.jdb-labs.com/jdb/nim-cli-utils.git >= 0.6.5",
"https://git.jdb-labs.com/jdb/nim-time-utils.git >= 0.5.2",
"https://git.jdb-labs.com/jdb/update-nim-package-version"
]
task updateVersion, "Update the version of this package.":