Shorter URLs for static hashes

This commit is contained in:
Michael Snoyman 2010-08-11 15:03:25 +03:00
parent b11a05d9eb
commit 13d3d020a7

View File

@ -153,7 +153,7 @@ staticFiles fp = do
f' <- lift f
let sr = ConE $ mkName "StaticRoute"
hash <- qRunIO $ fmap base64md5 $ L.readFile $ fp ++ '/' : intercalate "/" f
let qs = ListE [TupE [LitE $ StringL "hash", LitE $ StringL hash]]
let qs = ListE [TupE [LitE $ StringL hash, ListE []]]
return
[ SigD name $ ConT ''Route `AppT` ConT ''Static
, FunD name
@ -177,8 +177,11 @@ caseGetFileList = do
-- | md5-hashes the given lazy bytestring and returns the hash as
-- base64url-encoded string.
--
-- This function returns the first 8 characters of the hash.
base64md5 :: L.ByteString -> String
base64md5 = Codec.Binary.Base64Url.encode
base64md5 = take 8
. Codec.Binary.Base64Url.encode
. S.unpack
. Data.Serialize.encode
. md5