File tree Expand file tree Collapse file tree 3 files changed +17
-9
lines changed
Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,8 @@ enable = true
8686enable = true
8787filenames = [" cover.jpg" , " cover.png" , " cover.gif" ]
8888# optional size constraints in pixels, not taken into account if left
89- # unspecified
89+ # unspecified.
90+ # Warning: this makes the check significantly slower
9091min_size = { width = 300 , height = 300 }
9192max_size = { width = 1000 , height = 1000 }
9293
Original file line number Diff line number Diff line change @@ -73,15 +73,18 @@ check (HaveCover cover@Cover {..}) album
7373 maybeToExceptT (MissingCover dir) $
7474 MaybeT $
7575 Monad. findM Path. doesFileExist (toList absFiles)
76- picture <-
77- Except. withExceptT (UnableToReadCover coverFile . toText) $
78- ExceptT $
79- readImage coverFile
76+ -- Reading the image is very slow, so only do it if we have size
77+ -- constraints
78+ when (Cover. haveRange cover) $ do
79+ picture <-
80+ Except. withExceptT (UnableToReadCover coverFile . toText) $
81+ ExceptT $
82+ readImage coverFile
8083
81- let size = Cover. pictureSize picture
82- unless (Cover. withinRange cover size) $
83- Except. throwE $
84- BadCoverSize coverFile size
84+ let size = Cover. pictureSize picture
85+ unless (Cover. withinRange cover size) $
86+ Except. throwE $
87+ BadCoverSize coverFile size
8588 | otherwise = pure $ Left NotInSameDir
8689 where
8790 readImage = liftIO . Picture. readImage . Path. toFilePath
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ module Model.Cover
33 Size (.. ),
44 sizeToText ,
55 pictureSize ,
6+ haveRange ,
67 withinRange ,
78 )
89where
@@ -38,6 +39,9 @@ pictureSize picture =
3839 siHeight = Picture. dynamicMap Picture. imageHeight picture
3940 }
4041
42+ haveRange :: Cover -> Bool
43+ haveRange Cover {.. } = isJust coMinSize || isJust coMaxSize
44+
4145withinRange :: Cover -> Size -> Bool
4246withinRange Cover {.. } size =
4347 maybe True (size `greaterThan` ) coMinSize
You can’t perform that action at this time.
0 commit comments