liquid_feedback_frontend

changeset 1147:24787d0d9317

Updated delivery and cache control of member images
author bsw
date Sun Mar 22 17:32:38 2015 +0100 (2015-03-22)
parents ce9daada32dd
children 8874448bbb7a
files app/main/member_image/show.lua config/init.lua
line diff
     1.1 --- a/app/main/member_image/show.lua	Sun Mar 22 17:32:05 2015 +0100
     1.2 +++ b/app/main/member_image/show.lua	Sun Mar 22 17:32:38 2015 +0100
     1.3 @@ -1,17 +1,30 @@
     1.4  local image_type = param.get("image_type")
     1.5  local record = MemberImage:by_pk(param.get_id(), image_type, true)
     1.6  
     1.7 -if record == nil then
     1.8 -  local default_file = ({ avatar = "avatar.jpg", photo = nil })[image_type] or 'icons/16/lightning.png'
     1.9 -  request.redirect{ static = default_file }
    1.10 -  return
    1.11 +local data, content_type
    1.12 +
    1.13 +if record then
    1.14 +  data = record.data
    1.15 +  assert(record.content_type, "No content-type set for image.")
    1.16 +  content_type = record.content_type
    1.17 +
    1.18 +else
    1.19 +  local default_file = "avatar.jpg"
    1.20 +  content_type = "image/jpeg"
    1.21 +  if image_type == "photo" then
    1.22 +    default_file = "icons/16/lightning.png"
    1.23 +    content_type = "image/png"
    1.24 +  end
    1.25 +  
    1.26 +  local filename = WEBMCP_BASE_PATH .. "static/" .. default_file
    1.27 +  
    1.28 +  local f = assert(io.open(filename), "Cannot open default image file")
    1.29 +  data = f:read("*a")
    1.30 +  f:close()
    1.31 +
    1.32  end
    1.33  
    1.34 -assert(record.content_type, "No content-type set for image.")
    1.35 -
    1.36 -slot.set_layout(nil, record.content_type)
    1.37 +request.allow_caching()
    1.38  
    1.39 -if record then
    1.40 -  request.add_header("Cache-Control", "max-age=300"); -- let the client cache the image for 5 minutes
    1.41 -  slot.put_into("data", record.data)
    1.42 -end
    1.43 +slot.set_layout(nil, content_type)
    1.44 +slot.put_into("data", data)
     2.1 --- a/config/init.lua	Sun Mar 22 17:32:05 2015 +0100
     2.2 +++ b/config/init.lua	Sun Mar 22 17:32:38 2015 +0100
     2.3 @@ -112,7 +112,10 @@
     2.4      end
     2.5    end
     2.6  
     2.7 -  
     2.8 +  function request.allow_caching()
     2.9 +    request.add_header("Cache-Control", "max-age=3600");
    2.10 +  end
    2.11 +
    2.12    return
    2.13  end
    2.14  

Impressum / About Us