Clean up prints

This commit is contained in:
Robin Malley 2021-01-04 03:20:55 +00:00
parent 01448dbe34
commit ac24c97d24
4 changed files with 21 additions and 38 deletions

View File

@ -26,7 +26,6 @@ local function get_site_home(req)
stmnt_index:bind_names{} stmnt_index:bind_names{}
local latest = {} local latest = {}
for idr, title, iar, dater, author, hits in util.sql_rows(stmnt_index) do for idr, title, iar, dater, author, hits in util.sql_rows(stmnt_index) do
print("got:",tagsr,idr,title,iar,dater,author)
table.insert(latest,{ table.insert(latest,{
url = util.encode_id(idr), url = util.encode_id(idr),
title = title, title = title,

View File

@ -9,7 +9,6 @@ local function paste_get(req)
local text local text
local author,_ = session.get(req) local author,_ = session.get(req)
if host == config.domain and author then if host == config.domain and author then
print("host:",host,"config.domain:",config.domain,"author:",author)
http_response_header(req,"Location",string.format("https://%s.%s/_paste",author,config.domain)) http_response_header(req,"Location",string.format("https://%s.%s/_paste",author,config.domain))
http_response(req,303,"") http_response(req,303,"")
return return
@ -30,7 +29,6 @@ local function paste_get(req)
text="", text="",
}) })
elseif host ~= config.domain and author == nil then elseif host ~= config.domain and author == nil then
print("host:",host,"config.domain:",config.domain,"author:",author)
http_response_header(req,"Location",string.format("https://%s/_paste",config.domain)) http_response_header(req,"Location",string.format("https://%s/_paste",config.domain))
http_response(req,303,"") http_response(req,303,"")
return return

View File

@ -43,16 +43,23 @@ local function anon_paste(req,ps)
stmnt_paste:reset() stmnt_paste:reset()
if err == sql.DONE then if err == sql.DONE then
local rowid = stmnt_paste:last_insert_rowid() local rowid = stmnt_paste:last_insert_rowid()
local url = util.encode_id(rowid)
assert(stmnt_raw:bind(1,rowid) == sql.OK) assert(stmnt_raw:bind(1,rowid) == sql.OK)
assert(stmnt_raw:bind_blob(2,ps.raw) == sql.OK) assert(stmnt_raw:bind_blob(2,ps.raw) == sql.OK)
assert(stmnt_raw:bind(3,ps.markup) == sql.OK) assert(stmnt_raw:bind(3,ps.markup) == sql.OK)
err = util.do_sql(stmnt_raw) err = util.do_sql(stmnt_raw)
stmnt_raw:reset() stmnt_raw:reset()
if err ~= sql.DONE then if err ~= sql.DONE then
print("Failed to save raw text, but paste still went though") local msg = string.format(
[[Failed to save raw text for %d(%s) but paste still went though: %d: %s]],
rowid,
url,
err,
db.conn:errmsg()
)
log(LOG_CRIT,msg)
end end
tags.set(rowid,ps.tags) tags.set(rowid,ps.tags)
local url = util.encode_id(rowid)
local loc = string.format("https://%s/%s",config.domain,url) local loc = string.format("https://%s/%s",config.domain,url)
http_response_header(req,"Location",loc) http_response_header(req,"Location",loc)
http_response(req,303,"") http_response(req,303,"")
@ -60,7 +67,7 @@ local function anon_paste(req,ps)
cache.dirty(string.format("%s",config.domain)) cache.dirty(string.format("%s",config.domain))
return return
elseif err == sql.ERROR or err == sql.MISUSE then elseif err == sql.ERROR or err == sql.MISUSE then
ret = "Failed to paste: " .. tostring(err) error("Failed to paste:" .. tostring(err))
else else
error("Error pasting:" .. tostring(err)) error("Error pasting:" .. tostring(err))
end end
@ -90,16 +97,23 @@ local function author_paste(req,ps)
stmnt_paste:reset() stmnt_paste:reset()
if err == sql.DONE then if err == sql.DONE then
local rowid = stmnt_paste:last_insert_rowid() local rowid = stmnt_paste:last_insert_rowid()
local url = util.encode_id(rowid)
assert(stmnt_raw:bind(1,rowid) == sql.OK) assert(stmnt_raw:bind(1,rowid) == sql.OK)
assert(stmnt_raw:bind_blob(2,ps.raw) == sql.OK) assert(stmnt_raw:bind_blob(2,ps.raw) == sql.OK)
assert(stmnt_raw:bind(3,ps.markup) == sql.OK) assert(stmnt_raw:bind(3,ps.markup) == sql.OK)
err = util.do_sql(stmnt_raw) err = util.do_sql(stmnt_raw)
stmnt_raw:reset() stmnt_raw:reset()
if err ~= sql.DONE then if err ~= sql.DONE then
print("Failed to save raw text, but paste still went through") local msg = string.format(
[[Failed to save raw text for %d(%s) but paste still went though: %d: %s]],
rowid,
url,
err,
db.conn:errmsg()
)
log(LOG_CRIT,msg)
end end
tags.set(rowid,ps.tags) tags.set(rowid,ps.tags)
local url = util.encode_id(rowid)
local loc local loc
if asanon == "anonymous" then if asanon == "anonymous" then
loc = string.format("https://%s/%s",config.domain,url) loc = string.format("https://%s/%s",config.domain,url)
@ -113,7 +127,7 @@ local function author_paste(req,ps)
cache.dirty(string.format("%s",config.domain)) cache.dirty(string.format("%s",config.domain))
return return
elseif err == sql.ERROR or err == sql.MISUSE then elseif err == sql.ERROR or err == sql.MISUSE then
ret = "Failed to paste: " .. tostring(err) error("Failed to paste: " .. tostring(err) .. " : " .. db.conn:errmsg())
else else
error("Error pasting:",err) error("Error pasting:",err)
end end

View File

@ -96,44 +96,16 @@ local grammar = P{
marked = V"spoiler" + V"bold" + V"italic" + V"underline" + V"heading" + V"strike" + V"spoiler2" + V"code", marked = V"spoiler" + V"bold" + V"italic" + V"underline" + V"heading" + V"strike" + V"spoiler2" + V"code",
plainline = (V"marked" + word)^0, plainline = (V"marked" + word)^0,
line = Cs(V"greentext" + V"pinktext" + V"plainline" + P"") * P"\n" / function(a) line = Cs(V"greentext" + V"pinktext" + V"plainline" + P"") * P"\n" / function(a)
print("Found line:",a)
if a == "\r" then if a == "\r" then
return "<br/>" return "<br/>"
else else
return string.format("<p>%s</p>",a) return string.format("<p>%s</p>",a)
end end
end, end,
ending = C(P(1)^0) / function(a) print("failed with ending:", a) return sanitize(a) end, ending = C(P(1)^0) / function(a) return sanitize(a) end,
chunk = V"line"^0 * V"plainline" * V"ending" chunk = V"line"^0 * V"plainline" * V"ending"
} }
--A chunk of text that the parser chokes on:
local s = [=[
Minor update to the search function, also added a search bar to the front page.
Characters in '''bold''' are literal characters, things in ''<angle brackets and italics>'' are substitutions.
The search utility searches for stories on the site. At it's most simple, it searches stories based on tags, but it can also filter stories based on the fields: '''title''', '''author''', '''date''', and '''hits'''. In general, the syntax for search is {'''+-'''} ''<field>'' ''<operator>'' ''<value>''
The first '''+''' or '''-''' specifies weather to include or exclude results based on this search, the ''<field>'' specifies what field to search for (or search based on tag if this is missing), and ''<operator>'' specifies how to search.
For title and author, the only allowed operator is '''='''. This operator will search for ''<value>'' appearing anywhere in the field, case insensitive. For '''hits''' and '''time''', the allowed operators are '''>''','''<''','''>=''', '''<=''','''=''', which searches for greater than, less than, greater than or equal to, less than or equal to, and strictly equal to respectively. '''tag''' does not need a ''<field>'' or ''<operator>'', and only allows exact matches. As a quirk of this system, it is impossible to search for the tags "author", "title", "hits" or "date".
Examples:
[code]
+author=admin -meta
[/code]
Will return all stories by the users "admin" and "b'''admin'''ton_enthusiast" that do not include the "meta" tag.
[code]
+hits>20 -date>=1609459201
[/code]
Will return all stories with more than 20 hits that were posted before January 1, 2021 (unix timestamp 1609459201).
While the date field is a little hard to use for humans, it may be useful for robots.
]=]
--print(table.concat({grammar:match(s .. "\n")}," "))
return function(text) return function(text)
return table.concat({grammar:match(text .. "\n")}," ") return table.concat({grammar:match(text .. "\n")}," ")
end end