From f99c2e502f086e09c4330c5e14c726d52666be34 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Tue, 28 Jul 2026 08:50:24 +0200 Subject: [PATCH] wip --- src/.init.lua | 34 ++++++++++++++++++------ src/page/{experiences.html => dir.html} | 0 src/page/dir.lua | 35 +++++++++++++++++++++++++ src/page/experiences.lua | 22 ---------------- src/page/header.html | 3 ++- src/plugin/diskscan.lua | 7 ++++- util/xrforge.sh | 3 +-- 7 files changed, 70 insertions(+), 34 deletions(-) rename src/page/{experiences.html => dir.html} (100%) create mode 100644 src/page/dir.lua delete mode 100644 src/page/experiences.lua diff --git a/src/.init.lua b/src/.init.lua index 1888f5a..08a569e 100644 --- a/src/.init.lua +++ b/src/.init.lua @@ -18,6 +18,7 @@ app = require("soakbean") { cache = { items = {} }, plugin = {}, opts = {}, + forkpids = {}, cmd={ help = {file="cmd/help.lua", info="display all possible flags"}, server = {file="cmd/server.lua", info="starts the webserver"}, @@ -68,7 +69,6 @@ print = function(...) Log(kLogInfo, ... or "''") end -- nice redbean logging fro app.url['^/data'] = '/data.lua' -- setup custom file endpoint app.url['^/$'] = '/page/index.lua' -app.url['^/experiences[/]?$'] = '/page/experiences.lua' app.url['^/admin[/]?$'] = '/page/admin/index.lua' app.get('^/design[/]?$', util.pagerender('page/design.html')) @@ -85,19 +85,33 @@ end) app -- .use( require("middleware/httpauth")() ) +.use( function(req,res,next) + local diskpath = app.opts.plugin_diskscan_dir + local urlpath = GetPath() + print( urlpath .. " => " .. diskpath) + foreach( app.cache.items, function(k,v) + print(v.path) + --local itempath = v.path:gsub("^.","") + --if itempath:sub(0,#diskpath) == diskpath then + -- local _, nslashes = itempath:gsub("/","") + -- local _, diskslashes = diskpath:gsub("/","") + -- if nslashes == diskslashes + 1 then + -- print("slashes = " .. nslashes .. " => " .. diskslashes) + -- table.insert(items,v) + -- end + --end + end) +end) .use( require("json").middleware() ) -- try plug'n'play json API middleware .use( app.router( app.url ) ) -- try url router .use( app.response() ) -- try serve app response (if any) .use( function(req,next) Route() end) -- fallback default redbean fileserver app.on('init', function() - if assert(unix.fork()) == 0 then - app.plugin.diskscan.scan(app.opts.plugin_diskscan_dir) - print_r(app.cache) - --os.execute("ls ; sleep 5") - print("ok") - --local ok, headers, body = Fetch('http://127.0.0.1:8080/test') - end + --if assert(unix.fork()) == 0 then + -- local ok, headers, body = Fetch('http://127.0.0.1:8080/test') + -- print_r({ok=ok,header=headers,body=body}) + --end end) function OnHttpRequest() app.run() end @@ -105,3 +119,7 @@ function OnHttpRequest() app.run() end OnServerStart = function() app.init() -- this triggers init event end + +OnServerStop = function() + print("todo: kill threads") +end diff --git a/src/page/experiences.html b/src/page/dir.html similarity index 100% rename from src/page/experiences.html rename to src/page/dir.html diff --git a/src/page/dir.lua b/src/page/dir.lua new file mode 100644 index 0000000..16f4b66 --- /dev/null +++ b/src/page/dir.lua @@ -0,0 +1,35 @@ +local util = require("util") +local tile = require('page/partial/tile') + +--if not app.cache['experiences.html'] and util.count(app.cache.items) > 0 then +-- print("processing! " .. util.count(app.cache.items) .. " items") +-- app.cache['experiences.html'] = util.memoize( +-- function() +-- local data = util.merge({tiles=''},{ opts = app.opts }) +-- foreach(app.cache.items, function(k,v) +-- data.tiles = data.tiles .. tile( util.flatten(v,"item") ) +-- end) +-- local html = util.template( LoadAsset("page/experiences.html"),data) +-- return html +-- end, +-- 60*5 -- re-run every 5 mins (otherwise return cache) +-- ) +--end + + + +if util.count(app.cache.items) == 0 then + SetStatus(200) + SetHeader('Content-Type', 'text/html; charset=utf-8') + local html = util.template( [[ + ${header} +
+

Indexing files: please try again in few seconds

+ ${footer} + ]],data) + Write( html ) +else + SetStatus(200) + SetHeader('Content-Type', 'text/html; charset=utf-8') + --Write( app.cache['experiences.html']() ) +end diff --git a/src/page/experiences.lua b/src/page/experiences.lua deleted file mode 100644 index dc19a64..0000000 --- a/src/page/experiences.lua +++ /dev/null @@ -1,22 +0,0 @@ -local util = require("util") -local tile = require('page/partial/tile') - -if not app.cache['experiences.html'] then - - print("processing! " .. util.count(app.cache.items) .. " items") - app.cache['experiences.html'] = util.memoize( - function() - local data = util.merge({tiles=''},{ opts = app.opts }) - foreach(app.cache.items, function(k,v) - data.tiles = data.tiles .. tile( util.flatten(v,"item") ) - end) - local html = util.template( LoadAsset("page/experiences.html"),data) - return html - end, - 60*5 -- re-run every 5 mins (otherwise return cache) - ) -end - -SetStatus(200) -SetHeader('Content-Type', 'text/html; charset=utf-8') -Write( app.cache['experiences.html']() ) diff --git a/src/page/header.html b/src/page/header.html index 23304cb..6654ab7 100644 --- a/src/page/header.html +++ b/src/page/header.html @@ -26,7 +26,8 @@
- experiencesaboutHowto
+ /myverse/about + diff --git a/src/plugin/diskscan.lua b/src/plugin/diskscan.lua index 69e7a34..35bb1df 100644 --- a/src/plugin/diskscan.lua +++ b/src/plugin/diskscan.lua @@ -1,5 +1,10 @@ local dir = require "opendirectory" +app.on('init', function() + print("scanning experiences (this make take a while..)") + app.plugin.diskscan.scan(app.opts.plugin_diskscan_dir) +end) + -- this registers the plugin UI /funcs return { name = "Content (from disk)", @@ -28,7 +33,7 @@ return { local dref, derr = dir.foreach( scandir, function(path,stat,state,name,kind,ino,off,attr,fullpath) local experience = { - path = fullpath, + path = fullpath:gsub("^.",""), -- strip . name = name, title = name, tag = {}, diff --git a/util/xrforge.sh b/util/xrforge.sh index 0d3d17b..772e434 100755 --- a/util/xrforge.sh +++ b/util/xrforge.sh @@ -20,9 +20,8 @@ download(){ } janusweb(){ - version=1.7.4 test -f janusweb-${version}.tar.gz || { - wget "https://github.com/jbaicoianu/janusweb/releases/download/v${version}/janusweb-${version}.tar.gz" + wget "https://github.com/coderofsalvation/janusweb/releases/download/v1.7.5-rc/janusweb-1.7.5.tar.gz" tar -xvf janusweb-${version}.tar.gz mv janusweb-${version} src/v }