From b3741580dafae4c3bd1f356ca28232f5a6dfb1cb Mon Sep 17 00:00:00 2001 From: ljf Date: Tue, 29 Jun 2021 18:34:40 +0200 Subject: [PATCH] [fix] dash filename, mime types, ynh_userinfo.json --- access.lua | 3 ++- helpers.lua | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/access.lua b/access.lua index ea67df4..f85e1c0 100644 --- a/access.lua +++ b/access.lua @@ -208,6 +208,7 @@ end if is_logged_in then assets = { ["/ynh_portal.js"] = "js/ynh_portal.js", + ["/ynh_userinfo.js"] = "ynh_userinfo.json", ["/ynh_overlay.css"] = "css/ynh_overlay.css" } theme_dir = "/usr/share/ssowat/portal/assets/themes/"..conf.theme @@ -218,7 +219,7 @@ if is_logged_in then pfile:close() for shortcut, full in pairs(assets) do - if string.match(ngx.var.uri, "^"..shortcut.."$") then + if ngx.var.uri == shortcut then logger.debug("Serving static asset "..full) return hlp.serve("/yunohost/sso/assets/"..full, "static_asset") end diff --git a/helpers.lua b/helpers.lua index 26b4fc5..d56f0ce 100644 --- a/helpers.lua +++ b/helpers.lua @@ -550,13 +550,24 @@ function serve(uri, cache) png = "image/png", svg = "image/svg+xml", ico = "image/vnd.microsoft.icon", - woff = "application/x-font-woff", + woff = "font/woff", + woff2 = "font/woff2", + ttf = "font/ttf", json = "application/json" } + -- Allow .ms to specify mime type + mime = ext + if ext == "ms" then + subext = string.match(file, "^.+%.(.+)%.ms$") + if subext then + mime = subext + end + end + -- Set Content-Type - if mime_types[ext] then - ngx.header["Content-Type"] = mime_types[ext] + if mime_types[mime] then + ngx.header["Content-Type"] = mime_types[mime] else ngx.header["Content-Type"] = "text/plain" end @@ -570,9 +581,10 @@ function serve(uri, cache) elseif ext == "ms" then local data = get_data_for(file) content = lustache:render(content, data) - elseif ext == "json" then + elseif uri == "/ynh_userinfo.json" then local data = get_data_for(file) content = json.encode(data) + cache = "dynamic" end -- Reset flash messages @@ -612,7 +624,7 @@ function get_data_for(view) elseif view == "portal.html" or view == "edit.html" or view == "password.html" - or view == "ynhpanel.json" then + or view == "ynh_userinfo.json" then -- Invalidate cache before loading these views. -- Needed if the LDAP db is changed outside ssowat (from the cli for example).