Improved text indexing escaping; other minor fixes.
@@ -20,6 +20,7 @@ var infolist = m(".col-md-6", [m("ul.list-unstyled", [
li("Version", info.version), li("Size", info.size), li("Mounted Directory", info.directory, info.directory.length===0), + li("Log Level", info.log_level), li("Read-Only", readonly), li("Total Documents", m("span.badge", info.total_documents)), li("Total Tags", m("span.badge", info.total_tags)),
@@ -7,10 +7,6 @@
/* Blocks */ -.panel { - margin-bottom: 0; -} - blockquote { border-left: 3px solid #dedede; padding: 0px 10px;@@ -143,11 +139,7 @@
.toolbar { margin: 5px 0; } + .search-result { margin: 5px 0; } - -.popover { - max-width: 800px; - width: auto; -}
@@ -1664,9 +1664,6 @@ margin: auto;
margin-top: 60px; } /* Blocks */ -.panel { - margin-bottom: 0; -} blockquote { border-left: 3px solid #dedede; padding: 0px 10px;@@ -1886,10 +1883,6 @@ margin: 5px 0;
} .search-result { margin: 5px 0; -} -.popover { - max-width: 800px; - width: auto; } .note { -moz-background-clip: padding;
@@ -182,6 +182,7 @@ var content = newJObject()
content["version"] = %(LS.appname & " v" & LS.appversion) content["size"] = %($((LS.file.getFileSize().float/(1024*1024)).formatFloat(ffDecimal, 2)) & " MB") content["read_only"] = %LS.readonly + content["log_level"] = %LS.loglevel content["directory"] = %LS.directory content["mount"] = %LS.mount content["total_documents"] = %total_docs
@@ -17,6 +17,7 @@ port*: int
operation = opRun directory = "" readonly = false + logLevelLabel = "INFO" logLevel = lvlInfo mount = false reset = false@@ -89,7 +90,8 @@ of "log", "l":
if val == "": fail(102, "Log level not specified.") try: - logLevel = logging.LevelNames.find(val.toUpper).Level + logLevelLabel = val.toUpper + logLevel = logging.LevelNames.find(logLevelLabel).Level except: fail(103, "Invalid log level '$1'" % val) of "import":@@ -139,10 +141,12 @@ LS.appversion = version
LS.readonly = readonly LS.appname = appname LS.favicon = favicon +LS.loglevel = logLevelLabel LS.mount = mount LS.reset = reset # Initialize loggers +logging.level = logLevel logging.handlers.add(newConsoleLogger(logLevel, "$date $time - ")) logging.handlers.add(newFileLogger("litestore.log.txt", fmAppend, logLevel, fmtStr = "$date $time - "))
@@ -121,9 +121,9 @@ var res = store.db.execAffectedRows(SQL_INSERT_DOCUMENT, id, data, contenttype, binary, searchable, currentTime())
if res > 0: if binary <= 0 and searchable >= 0: # Add to search index - store.db.exec(SQL_INSERT_SEARCHCONTENT, id, data.stripXml) + store.db.exec(SQL_INSERT_SEARCHCONTENT, id, data.toPlainText) store.addDocumentSystemTags(id, contenttype) - if store.hasMirror: + if store.hasMirror and id.startsWith(store.mount): # Add dir tag store.createTag("$dir:"&store.mount, id, true) var filename = id.unixToNativePath@@ -142,8 +142,8 @@ if binary == 1:
data = data.encode(data.len*2) var res = store.db.execAffectedRows(SQL_UPDATE_DOCUMENT, data, contenttype, binary, searchable, currentTime(), id) if res > 0: - store.db.exec(SQL_UPDATE_SEARCHCONTENT, data.stripXml, id) - if store.hasMirror: + store.db.exec(SQL_UPDATE_SEARCHCONTENT, data.toPlainText, id) + if store.hasMirror and id.startsWith(store.mount): var filename = id.unixToNativePath if fileExists(filename): filename.writeFile(rawdata)@@ -161,7 +161,7 @@ result = store.db.execAffectedRows(SQL_DELETE_DOCUMENT, id)
if result > 0: store.db.exec(SQL_DELETE_SEARCHCONTENT, id) store.db.exec(SQL_DELETE_DOCUMENT_TAGS, id) - if store.hasMirror: + if store.hasMirror and id.startsWith(store.mount): var filename = id.unixToNativePath if fileExists(filename): removeFile(id.unixToNativePath)
@@ -40,6 +40,7 @@ readonly*: bool
appname*: string appversion*: string favicon*:string + loglevel*:string reset*: bool Response* = tuple[ code: HttpCode,
@@ -2,7 +2,8 @@ import json, db_sqlite, strutils, pegs, asyncdispatch, asynchttpserver2, times, logging, math, sqlite3
import types, queries, contenttypes proc dbg*(args: varargs[string, `$`]) = - echo "DEBUG - "&args.join(" ") + if logging.level <= lvlDebug: + echo "DEBUG - "&args.join(" ") proc dbQuote*(s: string): string = result = "'"@@ -81,9 +82,12 @@ count.inc
res.add(("tags", %tags)) return %res -proc stripXml*(s: string): string = - let pTag = "\\<\\/?[a-zA-Z!$?%][^<>]+\\>".peg - return s.replace(pTag) +proc toPlainText*(s: string): string = + let subs = @[ + (pattern: peg"""\<\/?[^<>]+\>""", repl: ""), + (pattern: peg"""{[_*/+!=?%$^-]+} {(!$1 .)+} $1""", repl: "$2") + ] + return s.parallelReplace(subs) proc checkIfBinary*(binary:int, contenttype:string): int = if binary == -1 and contenttype.isBinary: