mirror of
https://github.com/glimpse-app/server.git
synced 2025-04-02 10:52:45 -04:00
use jsony
This commit is contained in:
parent
c2b326aab6
commit
45c6c95a93
2 changed files with 6 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
||||||
import std/[strutils, os, json, asyncdispatch, httpclient, logging]
|
import std/[strutils, os, asyncdispatch, httpclient, logging]
|
||||||
|
|
||||||
import jester
|
import jester
|
||||||
import checksums/sha3
|
import checksums/sha3
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import std/[strutils, os, json, logging]
|
import std/[strutils, os, logging]
|
||||||
import jester
|
import jester
|
||||||
import jsony
|
import jsony
|
||||||
import norm/model
|
import norm/model
|
||||||
|
@ -27,16 +27,13 @@ proc createUploadRoutes*(cfg: Cfg) =
|
||||||
let fileName = request.formData["file"].fields["filename"]
|
let fileName = request.formData["file"].fields["filename"]
|
||||||
var fileTags: string
|
var fileTags: string
|
||||||
|
|
||||||
# this is a hack, I hate this
|
|
||||||
# convert to JsonNode to ensure we were given a proper JSON
|
|
||||||
# convert back to a string because db doesnt allow for JsonNode
|
|
||||||
try:
|
try:
|
||||||
fileTags = $parseJson(request.formData[
|
# check if tags json sent is of seq[string], otherwise reject it.
|
||||||
"tags"].body) # TODO: sanitize, only an array of strings (e.g. remove nested objects/arrays)
|
fileTags = request.formData["tags"].body.fromJson(seq[string]).toJson()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
fileTags = "[]"
|
fileTags = "[]"
|
||||||
except: # "except JsonError:" doesn't work for some reason
|
except JsonError:
|
||||||
respErr Http400, "Bad JSON.\n"
|
respErr Http400, "Bad JSON, must be an array of strings.\n"
|
||||||
|
|
||||||
# create needed directories if they don't exist already
|
# create needed directories if they don't exist already
|
||||||
let directory = cfg.uploadDir & user.username & "/"
|
let directory = cfg.uploadDir & user.username & "/"
|
||||||
|
|
Loading…
Add table
Reference in a new issue