2024-06-10 23:40:10 +00:00
|
|
|
local migrate = require "migrate"
|
2024-07-05 00:13:09 +00:00
|
|
|
|
2024-07-06 17:41:55 +00:00
|
|
|
local DB_FILENAME = "peachy.db"
|
|
|
|
sqlite3 = require "lsqlite3"
|
|
|
|
local db = sqlite3.open(DB_FILENAME)
|
2024-07-06 19:14:08 +00:00
|
|
|
db:exec("PRAGMA journal_mode=WAL")
|
|
|
|
db:exec("PRAGMA foreign_keys")
|
2024-07-18 06:46:33 +00:00
|
|
|
-- migrate.migrate(db)
|
2024-06-10 23:40:10 +00:00
|
|
|
|
2024-06-10 04:28:01 +00:00
|
|
|
fm = require "fullmoon"
|
2024-07-29 20:44:06 +00:00
|
|
|
fm.sessionOptions.secret = false
|
|
|
|
fm.setTemplate({ "/tmpl/", tmpl = "fmt" })
|
|
|
|
|
|
|
|
fm.setRoute("/static/*", fm.servePath)
|
|
|
|
|
|
|
|
fm.setRoute(fm.POST "/open", function(r)
|
|
|
|
local filename = r.params.filename
|
|
|
|
if filename == "" then filename = nil end
|
|
|
|
r.session.filename = filename
|
|
|
|
return false
|
|
|
|
end)
|
|
|
|
fm.setRoute("/open", function(r)
|
|
|
|
local files = {}
|
|
|
|
local filename = r.session.filename or ""
|
|
|
|
return fm.serveContent("opendb", { filename = filename, dir = files })
|
|
|
|
end)
|
|
|
|
fm.setRoute("/dirlist", function(r)
|
|
|
|
local function isSpecial(name)
|
|
|
|
return name == "." or name == ".." or string.sub(name, 1, 1) == "$"
|
|
|
|
end
|
|
|
|
local dirpath = r.params.dirpath
|
|
|
|
local files, directories = {}, {}
|
|
|
|
for name, kind in assert(unix.opendir(dirpath)) do
|
|
|
|
if not isSpecial(name) then
|
|
|
|
local file = { name = name, path = path.join(dirpath, name) }
|
|
|
|
if kind == unix.DT_REG then
|
|
|
|
table.insert(files, file)
|
|
|
|
elseif kind == unix.DT_DIR then
|
|
|
|
table.insert(directories, file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local function compareName(f1, f2)
|
|
|
|
return f1.name < f2.name
|
|
|
|
end
|
|
|
|
table.sort(directories, compareName)
|
|
|
|
table.sort(files, compareName)
|
|
|
|
return fm.serveContent("fragment/dirlist", { files = files, directories = directories })
|
|
|
|
end)
|
|
|
|
|
|
|
|
fm.setRoute("/", fm.serveContent "home")
|
|
|
|
fm.run()
|