From 13d3d020a730c0dfa189ba8cbf331df9e2e2e351 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Wed, 11 Aug 2010 15:03:25 +0300 Subject: [PATCH] Shorter URLs for static hashes --- Yesod/Helpers/Static.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Yesod/Helpers/Static.hs b/Yesod/Helpers/Static.hs index 99f85bfe..fcab7875 100644 --- a/Yesod/Helpers/Static.hs +++ b/Yesod/Helpers/Static.hs @@ -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