Added auth.json lookup from system documents.
h3rald h3rald@h3rald.com
Sat, 08 Feb 2020 12:40:51 +0100
2 files changed,
15 insertions(+),
4 deletions(-)
M
src/litestore.nim
→
src/litestore.nim
@@ -2,7 +2,8 @@ import
strutils, os, uri, - httpcore + httpcore, + json import litestorepkg/lib/types, litestorepkg/lib/logger,@@ -98,6 +99,13 @@ vacuum LS.file
else: # Open Datastore setup(true) + +if LS.auth == newJNull(): + # Attempt to retrieve auth.json from system documents + let options = newQueryOptions(true) + let rawDoc = LS.store.retrieveRawDocument("auth.json", options) + if rawDoc != "": + LS.auth = rawDoc.parseJson() case LS.operation: of opRun:
M
src/litestorepkg/lib/types.nim
→
src/litestorepkg/lib/types.nim
@@ -121,7 +121,10 @@ "Access-Control-Allow-Headers": "Authorization, Content-Type",
"Server": LS.appname & "/" & LS.appversion } -proc newQueryOptions*(): QueryOptions = - return QueryOptions(select: @["documents.id AS id", "documents.data AS data", "content_type", "binary", "searchable", "created", "modified"], - single: false, limit: 0, offset: 0, orderby: "", tags: "", search: "", folder: "", like: "", +proc newQueryOptions*(system = false): QueryOptions = + var select = @["documents.id AS id", "documents.data AS data", "content_type", "binary", "searchable", "created", "modified"] + if system: + select = @["system_documents.id AS id", "system_documents.data AS data", "content_type", "binary", "created", "modified"] + return QueryOptions(select: select, + single: false, limit: 0, offset: 0, orderby: "", tags: "", search: "", folder: "", like: "", system: system, createdAfter: "", createdBefore: "", modifiedAfter: "", modifiedBefore: "", jsonFilter: "", jsonSelect: newSeq[tuple[path: string, alias: string]](), tables: newSeq[string]())