Make files in current theme's directory accessibles under "https://server.tld/ynhtheme/".

This commit is contained in:
chateau 2019-03-09 11:21:12 +01:00
parent afdc7cc73c
commit 9845d99398
2 changed files with 32 additions and 17 deletions

View file

@ -305,24 +305,39 @@ end
-- `/yunohost/sso/assets/js/ynhpanel.js` file. -- `/yunohost/sso/assets/js/ynhpanel.js` file.
-- --
function scandir(directory, callback)
local i, popen = 0, io.popen
-- use find (and not ls) to list only files recursively and with their full path relative to the asked directory
local pfile = popen('cd "'..directory..'" && find * -type f')
for filename in pfile:lines() do
i = i + 1
callback(filename)
end
pfile:close()
end
function serveAsset(shortcut, full)
if string.match(ngx.var.uri, "^"..shortcut.."$") then
hlp.serve("/yunohost/sso/assets/"..full)
end
end
function serveThemeFile(filename)
serveAsset("/ynhtheme/"..filename, "themes/"..conf.theme.."/"..filename)
end
if hlp.is_logged_in() then if hlp.is_logged_in() then
if string.match(ngx.var.uri, "^/ynhpanel.js$") then -- serve ynhpanel files
hlp.serve("/yunohost/sso/assets/js/ynhpanel.js") serveAsset("/ynhpanel.js", "js/ynhpanel.js")
end serveAsset("/ynhpanel.json", "js/ynhpanel.json")
if string.match(ngx.var.uri, "^/ynhpanel.css$") then serveAsset("/ynhpanel.css", "css/ynhpanel.css")
hlp.serve("/yunohost/sso/assets/css/ynhpanel.css") -- serve theme's files
end
if string.match(ngx.var.uri, "^/ynhpanel.json$") then
hlp.serve("/yunohost/sso/assets/js/ynhpanel.json")
end
-- TODO : don't forget to open a PR to enable access to those -- TODO : don't forget to open a PR to enable access to those
-- in yunohost_panel.conf.inc -- in yunohost_panel.conf.inc
if string.match(ngx.var.uri, "^/ynhpanel_custom.js$") then -- FIXME? I think it would be better here not to use an absolute path
hlp.serve("/yunohost/sso/assets/themes/"..conf.theme.."/custom.js") -- but I didn't succeed to figure out where is the current location of the script
end -- if you call it from "portal/assets/themes/" the ls fails
if string.match(ngx.var.uri, "^/ynhpanel_custom.css$") then scandir("/usr/share/ssowat/portal/assets/themes/"..conf.theme, serveThemeFile)
hlp.serve("/yunohost/sso/assets/themes/"..conf.theme.."/custom.css")
end
-- If user has no access to this URL, redirect him to the portal -- If user has no access to this URL, redirect him to the portal
if not hlp.has_access() then if not hlp.has_access() then

View file

@ -266,12 +266,12 @@ function init_portal_button_and_overlay()
var customStyle = document.createElement("link"); var customStyle = document.createElement("link");
customStyle.setAttribute("rel", "stylesheet"); customStyle.setAttribute("rel", "stylesheet");
customStyle.setAttribute("type", "text/css"); customStyle.setAttribute("type", "text/css");
customStyle.setAttribute("href", '/ynhpanel_custom.css'); customStyle.setAttribute("href", '/ynhtheme/custom.css');
document.getElementsByTagName("head")[0].insertBefore(customStyle, null); document.getElementsByTagName("head")[0].insertBefore(customStyle, null);
// Inject custom / theme js // Inject custom / theme js
var customScript = document.createElement("script"); var customScript = document.createElement("script");
customScript.setAttribute("type", "text/javascript"); customScript.setAttribute("type", "text/javascript");
customScript.setAttribute("src", '/ynhpanel_custom.js'); customScript.setAttribute("src", '/ynhtheme/custom.js');
document.getElementsByTagName("head")[0].insertBefore(customScript, null); document.getElementsByTagName("head")[0].insertBefore(customScript, null);
// Bind portal button // Bind portal button