From 2a336b297237b546f065f706838f4cefad4c3e7c Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 25 Jan 2020 13:47:27 +0100 Subject: compiler: add resource timestamp in generated index Add a timestamp to resource paths in the gallery index to invalidate elements in the browser's cache when necessary. Timestamps are added to resource URLs as a dummy numeric parameter. GitHub: closes #40 --- compiler/src/Processors.hs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'compiler/src/Processors.hs') diff --git a/compiler/src/Processors.hs b/compiler/src/Processors.hs index 1c4a791..2abdec5 100644 --- a/compiler/src/Processors.hs +++ b/compiler/src/Processors.hs @@ -38,7 +38,7 @@ import Codec.Picture.Extra -- TODO: compare DCT and bilinear (and Lanczos, but i import Resource ( ItemProcessor, ThumbnailProcessor - , GalleryItemProps(..), Resolution(..) ) + , GalleryItemProps(..), Resolution(..), Resource(..) ) import Files @@ -150,6 +150,10 @@ withCached processor inputPath outputPath = skip = putStrLn $ "Skipping:\t" ++ outputPath +resourceAt :: FilePath -> Path -> IO Resource +resourceAt fsPath resPath = getModificationTime fsPath >>= return . Resource resPath + + type ItemFileProcessor = FileName -- ^ Input base path -> FileName -- ^ Output base path @@ -159,14 +163,15 @@ type ItemFileProcessor = itemFileProcessor :: Maybe Resolution -> LossyExportQuality -> Cache -> ItemFileProcessor itemFileProcessor maxResolution jpegExportQuality cached inputBase outputBase resClass inputRes = cached processor inPath outPath - >> return (props relOutPath) + >> resourceAt outPath relOutPath + >>= return . props where relOutPath = resClass /> inputRes inPath = localPath $ inputBase /> inputRes outPath = localPath $ outputBase /> relOutPath (processor, props) = processorFor maxResolution $ formatFromPath inputRes - processorFor :: Maybe Resolution -> Format -> (FileProcessor, Path -> GalleryItemProps) + processorFor :: Maybe Resolution -> Format -> (FileProcessor, Resource -> GalleryItemProps) processorFor Nothing _ = (copyFileProcessor, Other) processorFor _ (PictureFormat Gif) = @@ -192,11 +197,12 @@ thumbnailFileProcessor maxRes jpegExportQuality cached inputBase outputBase resC inPath = localPath $ inputBase /> inputRes outPath = localPath $ outputBase /> relOutPath - process :: Maybe FileProcessor -> IO (Maybe Path) + process :: Maybe FileProcessor -> IO (Maybe Resource) process Nothing = return Nothing process (Just proc) = proc inPath outPath - >> return (Just relOutPath) + >> resourceAt outPath relOutPath + >>= return . Just processorFor :: Format -> Maybe FileProcessor processorFor (PictureFormat picFormat) = -- cgit v1.2.3