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
function configure(...)
return oldconfigure(...)
end

View File

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

View File

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

View File

@ -1,7 +1,7 @@
local config = require("config")
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")
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(req,200,archive:read("*a"))
archive:close()
http_response(req,200,archive_fp:read("*a"))
archive_fp:close()
end
return archive

View File

@ -3,7 +3,6 @@ local sql = require("lsqlite3")
local db = require("db")
local queries = require("queries")
local util = require("util")
local pages = require("pages")
local session = require("session")
local config = require("config")
@ -16,8 +15,6 @@ function configure(...)
end
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)
http_request_populate_qs(req)

View File

@ -19,8 +19,6 @@ function configure(...)
end
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)
if not (author and author_id) then
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 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", 2, author_id)

View File

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

View File

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

View File

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

View File

@ -30,8 +30,6 @@ api.get.page_owner = function(env)
end
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)
http_request_populate_qs(req)
@ -60,8 +58,8 @@ local function edit_get(req)
local data = stmnt_edit:get_values()
local txt_compressed, markup, isanon, title, unlisted = unpack(data)
local text = zlib.decompress(txt_compressed)
local tags = tags.get(story_id)
local tags_txt = table.concat(tags,";")
local tags_raw = tags.get(story_id)
local tags_txt = table.concat(tags_raw,";")
stmnt_edit:reset()
ret = pages.edit{
title = title,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -93,7 +93,6 @@ end
local function author_paste(req,ps)
--Author paste
local author, authorid = session.get(req)
local ret
if author == nil then
ret = pages.author_paste{
domain = config.domain,
@ -161,18 +160,8 @@ local function author_paste(req,ps)
stmnt_paste:reset()
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 host = http_request_get_host(req)
local path = http_request_get_path(req)
local ps = {}
--We're creating a new paste
@ -186,7 +175,6 @@ local function paste_post(req)
if tag_str then
ps.tags = util.parse_tags(tag_str)
end
local pasteas
ps.raw = zlib.compress(text)
text = util.decodeentities(text)
text = parsers[ps.markup](text)

View File

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

View File

@ -10,13 +10,12 @@ local pages = require("pages")
local config = require("config")
local zlib = require("zlib")
local stmnt_read, stmnt_update_views, stmnt_comments
local stmnt_read, stmnt_update_views
local oldconfigure = configure
function configure(...)
stmnt_read = db.sqlassert(db.conn:prepare(queries.select_post))
stmnt_update_views = db.sqlassert(db.conn:prepare(queries.update_views))
stmnt_comments = db.sqlassert(db.conn:prepare(queries.select_comments))
return oldconfigure(...)
end
@ -160,7 +159,7 @@ local function read_get(req)
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/%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

View File

@ -1,5 +1,3 @@
local sql = require("lsqlite3")
local db = require("db")
local queries = require("queries")
local util = require("util")
@ -8,18 +6,9 @@ local pages = require("pages")
local config = require("config")
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 host = http_request_get_host(req)
local path = http_request_get_path(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
local ret = pages.search{
domain = config.domain,

View File

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

View File

@ -42,7 +42,7 @@ local global_env_m = {
}
local pages = {}
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 parser = et.Parser()
local f = assert(io.open(path,"r"))

View File

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

View File

@ -13,7 +13,6 @@ local sql = require("lsqlite3")
local db = require("db")
local queries = require("queries")
local util = require("util")
local tags = {}
local stmnt_get_tags, stmnt_ins_tag, stmnt_drop_tags
@ -50,12 +49,12 @@ function tags.get(id)
until false
end
function tags.set(storyid,tags)
function tags.set(storyid,tags_list)
assert(stmnt_drop_tags:bind_names{postid = storyid} == sql.OK)
db.do_sql(stmnt_drop_tags)
stmnt_drop_tags:reset()
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(2,tag) == sql.OK)
err = db.do_sql(stmnt_ins_tag)

View File

@ -22,7 +22,7 @@ local builtin_types = {
for _,type_ in pairs(builtin_types) do
types[type_] = function(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)
end
end

View File

@ -5,9 +5,7 @@ used in more than one place.
]]
local sql = require("lsqlite3")
local config = require("config")
local types = require("types")
local db = require("db")
local queries = require("queries")
@ -142,7 +140,7 @@ end
--arbitary data to hex encoded string
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 = {}
for i = 1,#str do
local byte = str:byte(i)
@ -237,7 +235,7 @@ if config.debugging then
end
end
else
function util.checktypes(...)
function util.checktypes()
end
end