Clean up dead code

Use luachheck to remove code that is no longer used
This commit is contained in:
Robin Malley 2023-06-20 01:11:42 +00:00
parent 93cee859ce
commit 4ff9f5bb07
26 changed files with 53 additions and 120 deletions

View File

@ -38,6 +38,5 @@ available.
local oldconfigure = configure local oldconfigure = configure
function configure(...) function configure(...)
return oldconfigure(...) return oldconfigure(...)
end end

View File

@ -9,9 +9,6 @@ and the kore parent process will restart with a fresh, empty cache.
]] ]]
local sql = require("lsqlite3") local sql = require("lsqlite3")
local queries = require("queries")
local util = require("util")
local db = require("db") local db = require("db")
local ret = {} local ret = {}

View File

@ -1,5 +1,3 @@
local cache = require("cache")
local sql = require("lsqlite3")
local db = require("db") local db = require("db")
local queries = require("queries") local queries = require("queries")
local util = require("util") local util = require("util")
@ -26,16 +24,14 @@ local function suggest_tags(req,data)
sufficiently backtrack-ey search/tag combination. sufficiently backtrack-ey search/tag combination.
]] ]]
assert(data:match("^[a-zA-Z0-9,%s-]+$"),string.format("Bad characters in tag: %q",data)) assert(data:match("^[a-zA-Z0-9,%s-]+$"),string.format("Bad characters in tag: %q",data))
stmnt_tags_get:bind_names{ stmnt_tags_get:bind_names{match = data .. "%"}
match = data .. "%" local sug_tags = {data}
}
local tags = {data}
for tag in stmnt_tags_get:rows() do for tag in stmnt_tags_get:rows() do
table.insert(tags,tag[1]) table.insert(sug_tags,tag[1])
end end
stmnt_tags_get:reset() stmnt_tags_get:reset()
http_response_header(req,"Content-Type","text/plain") http_response_header(req,"Content-Type","text/plain")
http_response(req,200,table.concat(tags,";")) http_response(req,200,table.concat(sug_tags,";"))
end end
--[[ --[[

View File

@ -1,7 +1,7 @@
local config = require("config") local config = require("config")
local function archive(req) local function archive(req)
local archive = assert(io.open(config.approot .. "data/archive.zip","rb")) local archive_fp = assert(io.open(config.approot .. "data/archive.zip","rb"))
--[=[ --[=[
local archive_size = archive:seek("end") local archive_size = archive:seek("end")
archive:seek("set") archive:seek("set")
@ -51,7 +51,7 @@ local function archive(req)
]] ]]
]=] ]=]
http_response_header(req,"Content-Disposition","attachment; filename=\"slash_monster_archive.zip\"") http_response_header(req,"Content-Disposition","attachment; filename=\"slash_monster_archive.zip\"")
http_response(req,200,archive:read("*a")) http_response(req,200,archive_fp:read("*a"))
archive:close() archive_fp:close()
end end
return archive return archive

View File

@ -3,7 +3,6 @@ local sql = require("lsqlite3")
local db = require("db") local db = require("db")
local queries = require("queries") local queries = require("queries")
local util = require("util")
local pages = require("pages") local pages = require("pages")
local session = require("session") local session = require("session")
local config = require("config") local config = require("config")
@ -16,13 +15,11 @@ function configure(...)
end end
local function bio_edit_get(req) local function bio_edit_get(req)
local host = http_request_get_host(req)
local path = http_request_get_path(req)
local author, authorid = session.get(req) local author, authorid = session.get(req)
http_request_populate_qs(req) http_request_populate_qs(req)
local ret local ret
if (not author) or (not authorid) then if (not author) or (not authorid) then
ret = pages.error{ ret = pages.error{
errcode = 401, errcode = 401,

View File

@ -19,8 +19,6 @@ function configure(...)
end end
local function edit_bio(req) local function edit_bio(req)
local host = http_request_get_host(req)
local path = http_request_get_path(req)
local author, author_id = session.get(req) local author, author_id = session.get(req)
if not (author and author_id) then if not (author and author_id) then
local response = pages.error{ local response = pages.error{
@ -38,7 +36,6 @@ local function edit_bio(req)
local parsed = parsers.plain(text) -- Make sure the plain parser can deal with it, even though we don't store this result. local parsed = parsers.plain(text) -- Make sure the plain parser can deal with it, even though we don't store this result.
local compr_raw = zlib.compress(text) local compr_raw = zlib.compress(text)
local compr = zlib.compress(parsed)
db.sqlbind(stmnt_update_bio, "bind_blob", 1,compr_raw) db.sqlbind(stmnt_update_bio, "bind_blob", 1,compr_raw)
db.sqlbind(stmnt_update_bio, "bind", 2, author_id) db.sqlbind(stmnt_update_bio, "bind", 2, author_id)

View File

@ -3,7 +3,6 @@ local sql = require("lsqlite3")
local pages = require("pages") local pages = require("pages")
local db = require("db") local db = require("db")
local queries = require("queries") local queries = require("queries")
local util = require("util")
local sessionlib = require("session") local sessionlib = require("session")
local config = require("config") local config = require("config")
@ -54,7 +53,7 @@ local function claim_post(req)
--Give them a file back --Give them a file back
http_response_header(req,"Content-Type","application/octet-stream") http_response_header(req,"Content-Type","application/octet-stream")
http_response_header(req,"Content-Disposition","attachment; filename=\"" .. name .. "." .. config.domain .. ".passfile\"") http_response_header(req,"Content-Disposition","attachment; filename=\"" .. name .. "." .. config.domain .. ".passfile\"")
local session = sessionlib.start(id) sessionlib.start(id)
text = password text = password
http_response(req,200,text) http_response(req,200,text)
return return
@ -67,9 +66,7 @@ local function claim_post(req)
elseif err == sql.ERROR or err == sql.MISUSE then elseif err == sql.ERROR or err == sql.MISUSE then
log(LOG_ALERT,"Account creation failed in an unusual way:" .. err) log(LOG_ALERT,"Account creation failed in an unusual way:" .. err)
--This is bad though --This is bad though
text = pages.claim { text = pages.claim {err = "Failed to claim"}
err = "Failed to claim"
}
end end
stmnt_author_create:reset() stmnt_author_create:reset()
http_response(req,200,text) http_response(req,200,text)

View File

@ -1,4 +1,3 @@
local tags = require("tags")
local util = require("util") local util = require("util")
local pages = require("pages") local pages = require("pages")
local config = require("config") local config = require("config")
@ -29,8 +28,6 @@ api.get.page_owner = function(env)
end end
local function delete_post(req) local function delete_post(req)
local host = http_request_get_host(req)
local path = http_request_get_path(req)
http_request_populate_post(req) http_request_populate_post(req)
local storystr = assert(http_argument_get_string(req,"story")) local storystr = assert(http_argument_get_string(req,"story"))
print("Looking at storystr:",storystr) print("Looking at storystr:",storystr)

View File

@ -33,17 +33,13 @@ api.get.page_reader = function(env)
end end
local function download_get(req) local function download_get(req)
local host = http_request_get_host(req)
local path = http_request_get_path(req)
http_request_populate_qs(req) http_request_populate_qs(req)
local story = assert(http_argument_get_string(req,"story")) local story = assert(http_argument_get_string(req,"story"))
local hashstr = http_argument_get_string(req,"pwd") local hashstr = http_argument_get_string(req,"pwd")
local ihash = hashstr and util.decode_unlisted(hashstr) local ihash = hashstr and util.decode_unlisted(hashstr)
story = util.decodeentities(story) story = util.decodeentities(story)
local story_id = util.decode_id(story) local story_id = util.decode_id(story)
stmnt_download:bind_names{ stmnt_download:bind_names{postid = story_id}
postid = story_id
}
local err = db.do_sql(stmnt_download) local err = db.do_sql(stmnt_download)
if err == sql.DONE then if err == sql.DONE then
--No rows, story not found --No rows, story not found

View File

@ -30,8 +30,6 @@ api.get.page_owner = function(env)
end end
local function edit_get(req) local function edit_get(req)
local host = http_request_get_host(req)
local path = http_request_get_path(req)
local author, authorid = session.get(req) local author, authorid = session.get(req)
http_request_populate_qs(req) http_request_populate_qs(req)
@ -60,8 +58,8 @@ local function edit_get(req)
local data = stmnt_edit:get_values() local data = stmnt_edit:get_values()
local txt_compressed, markup, isanon, title, unlisted = unpack(data) local txt_compressed, markup, isanon, title, unlisted = unpack(data)
local text = zlib.decompress(txt_compressed) local text = zlib.decompress(txt_compressed)
local tags = tags.get(story_id) local tags_raw = tags.get(story_id)
local tags_txt = table.concat(tags,";") local tags_txt = table.concat(tags_raw,";")
stmnt_edit:reset() stmnt_edit:reset()
ret = pages.edit{ ret = pages.edit{
title = title, title = title,

View File

@ -23,8 +23,6 @@ function configure(...)
end end
local function edit_post(req) local function edit_post(req)
local host = http_request_get_host(req)
local path = http_request_get_path(req)
local author, author_id = session.get(req) local author, author_id = session.get(req)
http_request_populate_post(req) http_request_populate_post(req)
@ -86,11 +84,10 @@ local function edit_post(req)
stmnt_update:reset() stmnt_update:reset()
tagslib.set(storyid,tags) tagslib.set(storyid,tags)
local id_enc = util.encode_id(storyid) local id_enc = util.encode_id(storyid)
local hash
local loc = string.format("https://%s/%s",config.domain,id_enc) local loc = string.format("https://%s/%s",config.domain,id_enc)
if unlisted then if unlisted then
stmnt_hash:bind_names{id=storyid} stmnt_hash:bind_names{id=storyid}
local err = db.do_sql(stmnt_hash) err = db.do_sql(stmnt_hash)
if err ~= sql.ROW then if err ~= sql.ROW then
error("Failed to get a post's hash while trying to make it unlisted") error("Failed to get a post's hash while trying to make it unlisted")
end end

View File

@ -56,7 +56,7 @@ local function get_author_home(req, loggedin)
local host = http_request_get_host(req) local host = http_request_get_host(req)
local subdomain = host:match("([^\\.]+)") local subdomain = host:match("([^\\.]+)")
stmnt_author_bio:bind_names{author=subdomain} stmnt_author_bio:bind_names{author=subdomain}
local author, authorid = session.get(req) local author, _ = session.get(req)
local err = db.do_sql(stmnt_author_bio) local err = db.do_sql(stmnt_author_bio)
if err == sql.DONE then if err == sql.DONE then
log(LOG_INFO,"No such author:" .. subdomain) log(LOG_INFO,"No such author:" .. subdomain)
@ -118,7 +118,7 @@ local function index_get(req)
local method = http_method_text(req) local method = http_method_text(req)
local host = http_request_get_host(req) local host = http_request_get_host(req)
local subdomain = host:match("([^\\.]+)") local subdomain = host:match("([^\\.]+)")
local author, authorid = session.get(req) local author, _ = session.get(req)
local text local text
if host == config.domain and author == nil then if host == config.domain and author == nil then
--Default home page --Default home page

View File

@ -1,4 +1,3 @@
local config = require("config")
local cache = require("cache") local cache = require("cache")
local config = require("config") local config = require("config")
local pages = require("pages") local pages = require("pages")

View File

@ -1,7 +1,6 @@
local sql = require("lsqlite3") local sql = require("lsqlite3")
local db = require("db") local db = require("db")
local util = require("util")
local session = require("session") local session = require("session")
local config = require("config") local config = require("config")
local pages = require("pages") local pages = require("pages")
@ -33,6 +32,7 @@ function api.authenticate(data)
if hash == passhash then if hash == passhash then
return id return id
end end
return old_authenticate(data)
end end
local function login_post(req) local function login_post(req)

View File

@ -2,7 +2,7 @@ local session = require("session")
local config = require("config") local config = require("config")
local function logout(req) local function logout(req)
local author, authorid = session.get(req) local _, authorid = session.get(req)
session.finish(authorid) session.finish(authorid)
http_response_header(req,"Location","https://" .. config.domain) http_response_header(req,"Location","https://" .. config.domain)
http_response(req,303,"") http_response(req,303,"")

View File

@ -34,7 +34,7 @@ local function anon_paste(req,ps)
since there are only 32 bits of address. Someone who since there are only 32 bits of address. Someone who
got a copy of the database could got a copy of the database could
just generate all 2^32 hashes and look up who posted just generate all 2^32 hashes and look up who posted
what. Use IPv6, Tor or I2P where possible. (but then I what. Use IPv6, Tor or I2P where possible. (but then I
guess it's harder to ban spammers... hmm..) guess it's harder to ban spammers... hmm..)
]] ]]
--local ip = http_request_get_ip(req) --local ip = http_request_get_ip(req)
@ -93,7 +93,6 @@ end
local function author_paste(req,ps) local function author_paste(req,ps)
--Author paste --Author paste
local author, authorid = session.get(req) local author, authorid = session.get(req)
local ret
if author == nil then if author == nil then
ret = pages.author_paste{ ret = pages.author_paste{
domain = config.domain, domain = config.domain,
@ -161,19 +160,9 @@ local function author_paste(req,ps)
stmnt_paste:reset() stmnt_paste:reset()
end end
local function decodeentities(capture)
local n = tonumber(capture,16)
local c = string.char(n)
if escapes[c] then
return escapes[c]
else
return c
end
end
local function paste_post(req) local function paste_post(req)
local host = http_request_get_host(req) local host = http_request_get_host(req)
local path = http_request_get_path(req)
local ps = {} local ps = {}
--We're creating a new paste --We're creating a new paste
ps.subdomain = host:match("([^\\.]+)") ps.subdomain = host:match("([^\\.]+)")
@ -186,7 +175,6 @@ local function paste_post(req)
if tag_str then if tag_str then
ps.tags = util.parse_tags(tag_str) ps.tags = util.parse_tags(tag_str)
end end
local pasteas
ps.raw = zlib.compress(text) ps.raw = zlib.compress(text)
text = util.decodeentities(text) text = util.decodeentities(text)
text = parsers[ps.markup](text) text = parsers[ps.markup](text)

View File

@ -1,12 +1,9 @@
local parsers = require("parsers") local parsers = require("parsers")
local tags = require("tags")
local util = require("util") local util = require("util")
local pages = require("pages") local pages = require("pages")
local config = require("config") local config = require("config")
local function preview_post(req) local function preview_post(req)
local host = http_request_get_host(req)
local path = http_request_get_path(req)
http_request_populate_post(req) http_request_populate_post(req)
local title = assert(http_argument_get_string(req,"title")) local title = assert(http_argument_get_string(req,"title"))
local text = assert(http_argument_get_string(req,"text")) local text = assert(http_argument_get_string(req,"text"))

View File

@ -10,13 +10,12 @@ local pages = require("pages")
local config = require("config") local config = require("config")
local zlib = require("zlib") local zlib = require("zlib")
local stmnt_read, stmnt_update_views, stmnt_comments local stmnt_read, stmnt_update_views
local oldconfigure = configure local oldconfigure = configure
function configure(...) function configure(...)
stmnt_read = db.sqlassert(db.conn:prepare(queries.select_post)) stmnt_read = db.sqlassert(db.conn:prepare(queries.select_post))
stmnt_update_views = db.sqlassert(db.conn:prepare(queries.update_views)) stmnt_update_views = db.sqlassert(db.conn:prepare(queries.update_views))
stmnt_comments = db.sqlassert(db.conn:prepare(queries.select_comments))
return oldconfigure(...) return oldconfigure(...)
end end
@ -26,7 +25,7 @@ Increases a story's hit counter by 1
]] ]]
local function add_view(storyid) local function add_view(storyid)
stmnt_update_views:bind_names{ stmnt_update_views:bind_names{
id = storyid id = storyid
} }
local err = db.do_sql(stmnt_update_views) local err = db.do_sql(stmnt_update_views)
assert(err == sql.DONE, "Failed to update view counter:"..tostring(err)) assert(err == sql.DONE, "Failed to update view counter:"..tostring(err))
@ -109,21 +108,21 @@ local function read_get(req)
ps.iam = author ps.iam = author
ps.loggedauthorid = authorid ps.loggedauthorid = authorid
end end
--If we need to show comments --If we need to show comments
http_request_populate_qs(req) http_request_populate_qs(req)
ps.show_comments = true ps.show_comments = true
if ps.show_comments then if ps.show_comments then
ps.comments = util.get_comments(ps.storyid) ps.comments = util.get_comments(ps.storyid)
end end
--If this post is unlisted, get the hash --If this post is unlisted, get the hash
local hashstr = http_argument_get_string(req,"pwd") local hashstr = http_argument_get_string(req,"pwd")
if hashstr then if hashstr then
ps.hash = util.decode_unlisted(hashstr) ps.hash = util.decode_unlisted(hashstr)
ps.hashstr = hashstr ps.hashstr = hashstr
end end
local text local text
--normal story display --normal story display
if (not ps.loggedauthor) then if (not ps.loggedauthor) then
@ -159,11 +158,11 @@ local function read_get(req)
text = pages.read(ps) text = pages.read(ps)
end end
end end
--If this isn't unlisted, dirty everywhere the hit counter is shown --Dirty everywhere the hit counter is shown
cache.dirty(string.format("%s",config.domain)) cache.dirty(string.format("%s",config.domain))
cache.dirty(string.format("%s/%s",config.domain,ps.short)) -- This place to read this post cache.dirty(string.format("%s/%s",config.domain,ps.short)) -- This place to read this post
cache.dirty(string.format("%s.%s",config.domain,ps.short)) -- The author's index page cache.dirty(string.format("%s.%s",config.domain,ps.short)) -- The author's index page
assert(text) assert(text)
http_response(req,200,text) http_response(req,200,text)

View File

@ -1,5 +1,3 @@
local sql = require("lsqlite3")
local db = require("db") local db = require("db")
local queries = require("queries") local queries = require("queries")
local util = require("util") local util = require("util")
@ -8,18 +6,9 @@ local pages = require("pages")
local config = require("config") local config = require("config")
local search_parser = require("parser_search") local search_parser = require("parser_search")
local stmnt_search
local oldconfigure = configure
function configure(...)
stmnt_search = assert(db.conn:prepare(queries.select_post_tags))
return oldconfigure(...)
end
local function search_get(req) local function search_get(req)
local host = http_request_get_host(req)
local path = http_request_get_path(req)
http_request_populate_qs(req) http_request_populate_qs(req)
local searchq, err = http_argument_get_string(req,"q") local searchq, _ = http_argument_get_string(req,"q")
if not searchq then if not searchq then
local ret = pages.search{ local ret = pages.search{
domain = config.domain, domain = config.domain,

View File

@ -36,7 +36,7 @@ local api = {}
Called before any request processing. Returning true "traps" the request, and Called before any request processing. Returning true "traps" the request, and
does not continue calling smr logic. Well-behaved addons should check for does not continue calling smr logic. Well-behaved addons should check for
"true" from the detoured function, and return true immediately if the check "true" from the detoured function, and return true immediately if the check
succeeds. succeeds.
@param req {{http_request}} - The request about to be processed @param req {{http_request}} - The request about to be processed
@ -44,7 +44,7 @@ succeeds.
]] ]]
api.pre_request = function(req) end api.pre_request = function(req) end
-- Called after smr request processing. Returning true "traps" the request. -- Called after smr request processing. Returning true "traps" the request.
-- Well-behaved addons should check for true from the detoured function, and -- Well-behaved addons should check for true from the detoured function, and
-- immediately return true if the check succeeds. This will not stop smr from -- immediately return true if the check succeeds. This will not stop smr from
-- responding to the request, since by this time http_request_response() has -- responding to the request, since by this time http_request_response() has

View File

@ -37,8 +37,6 @@ Be sure to always {{doc/appendix/detourin}}
print("Really fast print from init.lua") print("Really fast print from init.lua")
--Luarocks libraries --Luarocks libraries
local et = require("etlua")
local sql = require("lsqlite3")
local zlib = require("zlib") local zlib = require("zlib")
local api = require("hooks") local api = require("hooks")
@ -48,9 +46,7 @@ function configure(...) end
--smr code --smr code
require("global") require("global")
local cache = require("cache") local cache = require("cache")
local pages = require("pages") require("pages")
local util = require("util")
local config = require("config")
local db = require("db") local db = require("db")
print("Hello from init.lua") print("Hello from init.lua")
@ -69,7 +65,7 @@ print("Created configure function")
-- TODO: Fill this out -- TODO: Fill this out
local http_methods = {"GET","POST"} local http_methods = {"GET","POST"}
local http_m_rev = {} local http_m_rev = {}
for k,v in pairs(http_methods) do for _,v in pairs(http_methods) do
http_m_rev[v] = true http_m_rev[v] = true
end end

View File

@ -42,7 +42,7 @@ local global_env_m = {
} }
local pages = {} local pages = {}
local etlua_short_pat = '%[string "etlua"%]' local etlua_short_pat = '%[string "etlua"%]'
for k,v in pairs(pagenames) do for _,v in pairs(pagenames) do
local path = string.format(config.approot .. "pages/%s.etlua",v) local path = string.format(config.approot .. "pages/%s.etlua",v)
local parser = et.Parser() local parser = et.Parser()
local f = assert(io.open(path,"r")) local f = assert(io.open(path,"r"))

View File

@ -1,7 +1,6 @@
local sql = require("lsqlite3") local sql = require("lsqlite3")
local db = require("db") local db = require("db")
local util = require("util")
local queries = require("queries") local queries = require("queries")
local stmnt_get_session, stmnt_insert_session, stmnt_delete_session local stmnt_get_session, stmnt_insert_session, stmnt_delete_session
@ -13,7 +12,7 @@ function configure(...)
stmnt_delete_session = db.sqlassert(db.conn:prepare(queries.delete_session)) stmnt_delete_session = db.sqlassert(db.conn:prepare(queries.delete_session))
return oldconfigure(...) return oldconfigure(...)
end end
local session = {} local session = {}
--[[ --[[
@ -36,9 +35,7 @@ function session.get(req)
end end
local data = stmnt_get_session:get_values() local data = stmnt_get_session:get_values()
stmnt_get_session:reset() stmnt_get_session:reset()
local author = data[1] return data[1],data[2]
local authorid = data[2]
return author,authorid
end end
--[[ --[[
@ -47,21 +44,21 @@ Start a session for someone who logged in
function session.start(who) function session.start(who)
local rngf = assert(io.open("/dev/urandom","rb")) local rngf = assert(io.open("/dev/urandom","rb"))
local session_t = {} local session_t = {}
for i = 1,64 do for _ = 1,64 do
local r = string.byte(rngf:read(1)) local r = string.byte(rngf:read(1))
local s = string.char((r % 26) + 65) local s = string.char((r % 26) + 65)
table.insert(session_t,s) table.insert(session_t,s)
end end
local session = table.concat(session_t) local session_str = table.concat(session_t)
rngf:close() rngf:close()
stmnt_insert_session:bind_names{ stmnt_insert_session:bind_names{
sessionid = session, sessionid = session_str,
authorid = who authorid = who
} }
local err = db.do_sql(stmnt_insert_session) local err = db.do_sql(stmnt_insert_session)
stmnt_insert_session:reset() stmnt_insert_session:reset()
assert(err == sql.DONE, "Error should have been 'DONE', was: " .. tostring(err)) assert(err == sql.DONE, "Error should have been 'DONE', was: " .. tostring(err))
return session return session_str
end end
--[[ --[[

View File

@ -1,7 +1,7 @@
--[[ md --[[ md
@name lua/tags @name lua/tags
Helper methods for cleaning story tags. Helper methods for cleaning story tags.
Tags are the main way to search smr, a simple `+<tag>` or `-<tag>` will show all Tags are the main way to search smr, a simple `+<tag>` or `-<tag>` will show all
stories that include (+) or do not include (-) a particular tag. stories that include (+) or do not include (-) a particular tag.
@ -13,7 +13,6 @@ local sql = require("lsqlite3")
local db = require("db") local db = require("db")
local queries = require("queries") local queries = require("queries")
local util = require("util")
local tags = {} local tags = {}
local stmnt_get_tags, stmnt_ins_tag, stmnt_drop_tags local stmnt_get_tags, stmnt_ins_tag, stmnt_drop_tags
@ -24,7 +23,7 @@ function configure(...)
stmnt_ins_tag = assert(db.conn:prepare(queries.insert_tag)) stmnt_ins_tag = assert(db.conn:prepare(queries.insert_tag))
stmnt_get_tags = assert(db.conn:prepare(queries.select_tags)) stmnt_get_tags = assert(db.conn:prepare(queries.select_tags))
stmnt_drop_tags = assert(db.conn:prepare(queries.delete_tags)) stmnt_drop_tags = assert(db.conn:prepare(queries.delete_tags))
return oldconfigure(...) return oldconfigure(...)
end end
@ -50,12 +49,12 @@ function tags.get(id)
until false until false
end end
function tags.set(storyid,tags) function tags.set(storyid,tags_list)
assert(stmnt_drop_tags:bind_names{postid = storyid} == sql.OK) assert(stmnt_drop_tags:bind_names{postid = storyid} == sql.OK)
db.do_sql(stmnt_drop_tags) db.do_sql(stmnt_drop_tags)
stmnt_drop_tags:reset() stmnt_drop_tags:reset()
local err local err
for _,tag in pairs(tags) do for _,tag in pairs(tags_list) do
assert(stmnt_ins_tag:bind(1,storyid) == sql.OK) assert(stmnt_ins_tag:bind(1,storyid) == sql.OK)
assert(stmnt_ins_tag:bind(2,tag) == sql.OK) assert(stmnt_ins_tag:bind(2,tag) == sql.OK)
err = db.do_sql(stmnt_ins_tag) err = db.do_sql(stmnt_ins_tag)

View File

@ -22,7 +22,7 @@ local builtin_types = {
for _,type_ in pairs(builtin_types) do for _,type_ in pairs(builtin_types) do
types[type_] = function(arg) types[type_] = function(arg)
local argtype = type(arg) local argtype = type(arg)
if not argtype == type_ then if argtype ~= type_ then
return false, string.format("was not a %s, was a %s",type_,argtype) return false, string.format("was not a %s, was a %s",type_,argtype)
end end
end end

View File

@ -5,9 +5,7 @@ used in more than one place.
]] ]]
local sql = require("lsqlite3")
local config = require("config") local config = require("config")
local types = require("types")
local db = require("db") local db = require("db")
local queries = require("queries") local queries = require("queries")
@ -38,15 +36,15 @@ see https://perishablepress.com/stop-using-unsafe-characters-in-urls/
no underscore because we use that for our operative pages no underscore because we use that for our operative pages
A set of legacy characters that are no longer in use (because they were invalid A set of legacy characters that are no longer in use (because they were invalid
to use in URL's) is also defined, but unused as long as to use in URL's) is also defined, but unused as long as
{{config/legacy_url_cutoff}} is set to 0. {{config/legacy_url_cutoff}} is set to 0.
]] ]]
local url_characters = local url_characters =
[[abcdefghijklmnopqrstuvwxyz]].. [[abcdefghijklmnopqrstuvwxyz]]..
[[ABCDEFGHIJKLMNOPQRSTUVWXYZ]].. [[ABCDEFGHIJKLMNOPQRSTUVWXYZ]]..
[[0123456789]] [[0123456789]]
local url_characters_legacy = local url_characters_legacy =
url_characters .. url_characters ..
[[$-+!*'(),]] [[$-+!*'(),]]
@ -120,7 +118,7 @@ Legacy code, try to decode with invalid characters in the url first
local new_decode = util.decode_id local new_decode = util.decode_id
function util.decode_id(s) function util.decode_id(s)
local res, id = pcall(function() local res, id = pcall(function()
local n = 0 local n = 0
local charlen = string.len(url_characters_legacy) local charlen = string.len(url_characters_legacy)
for i = 1,string.len(s) do for i = 1,string.len(s) do
local char = string.sub(s,i,i) local char = string.sub(s,i,i)
@ -142,7 +140,7 @@ end
--arbitary data to hex encoded string --arbitary data to hex encoded string
function util.encode_unlisted(str) function util.encode_unlisted(str)
assert(type(str) == "string","Tried to encode something not a string:" .. type(Str)) assert(type(str) == "string","Tried to encode something not a string:" .. type(str))
local safe = {} local safe = {}
for i = 1,#str do for i = 1,#str do
local byte = str:byte(i) local byte = str:byte(i)
@ -237,7 +235,7 @@ if config.debugging then
end end
end end
else else
function util.checktypes(...) function util.checktypes()
end end
end end