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) --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) local plugin = { name = 'Federation disabled', info = 'updating values requires a xrforge restart', opts = { -- TODO populate this based on xrforge-federation.json { 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='' } } } -- -- 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 return plugin