2026-08-02 22:39:29 +02:00
|
|
|
local util = require('util')
|
|
|
|
|
|
|
|
|
|
app.on('scan_experience', function(exp)
|
|
|
|
|
--print_r(exp)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
app.on('scan_experience_file', function(exp)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
app.on('set', function(k,v)
|
|
|
|
|
print("content was updated")
|
|
|
|
|
end)
|
|
|
|
|
|
2026-08-03 19:19:07 +02:00
|
|
|
--app.on('dir', function(opts)
|
|
|
|
|
-- local me = app.plugin.federation
|
|
|
|
|
-- if opts.urlpath == '/' then
|
|
|
|
|
-- foreach( me.portals, function(k,portal)
|
|
|
|
|
-- print("JAAA")
|
|
|
|
|
-- table.insert( opts.data.items,{
|
|
|
|
|
-- url = portal.url,
|
|
|
|
|
-- name = portal.name,
|
|
|
|
|
-- thumbnail = portal.thumbnail
|
|
|
|
|
-- })
|
|
|
|
|
-- end)
|
|
|
|
|
-- end
|
|
|
|
|
--end)
|
2026-08-02 22:39:29 +02:00
|
|
|
|
|
|
|
|
local plugin = {
|
2026-08-03 19:19:07 +02:00
|
|
|
name = 'Federation <b class="tag">disabled</b>',
|
|
|
|
|
info = 'updating values requires a xrforge restart',
|
2026-08-02 22:39:29 +02:00
|
|
|
opts = { -- TODO populate this based on xrforge-federation.json
|
|
|
|
|
{
|
2026-08-03 19:19:07 +02:00
|
|
|
key='app.opts.plugin_federation_url_1',
|
|
|
|
|
title='Federation URL 1',
|
|
|
|
|
info="a json with (janus)xr(forge) URLs",
|
|
|
|
|
default="./federation.json",
|
|
|
|
|
values=''
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key='app.opts.plugin_federation_url_2',
|
|
|
|
|
title='Federation URL 1',
|
|
|
|
|
info="a json with (janus)xr(forge) URLs",
|
|
|
|
|
default="",
|
|
|
|
|
values=''
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key='app.opts.plugin_federation_url_3',
|
|
|
|
|
title='Federation URL 1',
|
|
|
|
|
info="a json with (janus)xr(forge) URLs",
|
|
|
|
|
default="",
|
|
|
|
|
values=''
|
2026-08-02 22:39:29 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-03 19:19:07 +02:00
|
|
|
--
|
|
|
|
|
-- PROBLEM: every request has its own app context
|
|
|
|
|
-- so the util.fetch() didn't help here
|
|
|
|
|
-- sqlite is needed to share state
|
|
|
|
|
|
|
|
|
|
app.on('init', function()
|
|
|
|
|
local me = app.plugin.federation
|
|
|
|
|
me.portals = {}
|
|
|
|
|
local federations = {}
|
|
|
|
|
-- load previous federations if any
|
|
|
|
|
for k=1,3 do
|
|
|
|
|
if app.opts['plugin_federation_url_'..k] and #app.opts['plugin_federation_url_'..k] > 0 then
|
|
|
|
|
table.insert(federations, app.opts['plugin_federation_url_'..k])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
foreach(federations, function(k,url)
|
|
|
|
|
if url:match('^[./]') then
|
|
|
|
|
url = util.getURL( url:gsub('^[./]',''), {server=true} )
|
|
|
|
|
end
|
|
|
|
|
util.fetch(url, nil, function(req,res,next)
|
|
|
|
|
if req.body then
|
|
|
|
|
local t = DecodeJson(req.body)
|
|
|
|
|
if t then
|
|
|
|
|
foreach( t, function(k,opt)
|
|
|
|
|
table.insert( me.portals, opts )
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- this registers the plugin UI
|
2026-08-02 22:39:29 +02:00
|
|
|
return plugin
|