summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2015-05-14 15:36:48 +0200
committerFélix Sipma <felix.sipma@no-log.org>2015-05-14 18:38:29 +0200
commit9838578634a8d8c4b2c669d7ea6377b212732219 (patch)
tree81142f819c60a9883ca9f3d5b89dc89f1c45fd77
parentd2208d48fd2b3f75f1ed8aeef6d86c1454d486cc (diff)
Drop system-filepath and system-fileio
-rw-r--r--Import/NoFoundation.hs9
-rw-r--r--Shop/Image/Functions.hs57
-rw-r--r--mokupona.cabal3
3 files changed, 31 insertions, 38 deletions
diff --git a/Import/NoFoundation.hs b/Import/NoFoundation.hs
index e4bf5f0..e8f6deb 100644
--- a/Import/NoFoundation.hs
+++ b/Import/NoFoundation.hs
@@ -2,7 +2,8 @@ module Import.NoFoundation
( module Import
) where
-import ClassyPrelude.Yesod as Import
+-- temporary fix: do not use system-filepath
+import ClassyPrelude.Yesod as Import hiding (FilePath, (</>), (<.>))
import Settings as Import
import Settings.StaticFiles as Import
import Yesod.Core.Types as Import (loggerSet)
@@ -16,3 +17,9 @@ import Data.Time as Import ( NominalDiffTime
)
import Model.UTCTime as Import
import Model.Quantity as Import
+import System.FilePath as Import ( FilePath
+ , (<.>)
+ , (</>)
+ , takeFileName
+ , dropExtensions
+ )
diff --git a/Shop/Image/Functions.hs b/Shop/Image/Functions.hs
index df5c4af..d69b1b8 100644
--- a/Shop/Image/Functions.hs
+++ b/Shop/Image/Functions.hs
@@ -6,52 +6,39 @@ module Shop.Image.Functions
, getImageId
) where
-import Import hiding ( FilePath )
-import Filesystem.Path.CurrentOS ( encodeString
- , decodeString
- , fromText
- , toText
- , FilePath
- , dropExtensions
- )
-import System.Process ( readProcessWithExitCode )
-import Filesystem ( removeFile, isFile )
-import System.Exit ( ExitCode (..) )
-import System.Random ( randomRIO )
+import Import
+import System.Process ( readProcessWithExitCode )
+import System.Exit ( ExitCode (..) )
+import System.Random ( randomRIO )
+import System.Directory ( removeFile, doesFileExist )
writeToServer :: FileInfo -> Int -> Int -> Handler Text
writeToServer file twidth theight = do
path <- randomFileName
- liftIO $ fileMove file $ encodeString path
+ liftIO $ fileMove file path
let tpath = thumbnailFilePath path thumbext
(errcode, _, stderr') <- liftIO $ imageResize path tpath twidth theight
case errcode of
- ExitSuccess ->
- case toText $ filename tpath of
- Right text -> return text
- Left text -> do
- let err = "Invalid toText FilePath: " ++ text
- $logError err
- error $ show err
+ ExitSuccess -> return $ pack $ takeFileName tpath
ExitFailure errno -> do
- let err = "Error" ++ pack (show errno)
+ let err = "Error" ++ show errno
++ " resizing image \""
- ++ pack (encodeString path)
- ++ "\": " ++ pack stderr'
- $logError err
- error $ show err
+ ++ show path
+ ++ "\": " ++ stderr'
+ $logError (pack err)
+ error err
where
thumbext = pack $ show twidth ++ "x" ++ show theight
-imageFilePath :: Text -> Handler FilePath
+imageFilePath :: FilePath -> Handler FilePath
imageFilePath f = do
master <- getYesod
let uploadDir = appMediaDir $ appSettings master
- return $ decodeString uploadDir </> fromText f
+ return $ uploadDir </> f
thumbnailFilePath :: FilePath -> Text -> FilePath
thumbnailFilePath filepath thumbext =
- dropExtensions filepath <.> thumbext <.> imageExt
+ dropExtensions filepath <.> unpack thumbext <.> unpack imageExt
imageResize :: FilePath -> FilePath -> Int -> Int -> IO (ExitCode, String, String)
imageResize orig dest twidth theight = do
@@ -67,28 +54,28 @@ imageResize orig dest twidth theight = do
, "center"
, "-extent"
, show twidth ++ "x" ++ show theight
- , encodeString orig
- , encodeString dest
+ , show orig
+ , show dest
]
stdin' = ""
removeImage :: Text -> Handler ()
-removeImage f = liftIO <$> removeFile =<< imageFilePath f
+removeImage f = liftIO <$> removeFile =<< imageFilePath (unpack f)
imageExists :: Text -> Handler Bool
-imageExists f = liftIO <$> isFile =<< imageFilePath f
+imageExists f = liftIO <$> doesFileExist =<< imageFilePath (unpack f)
sendImage :: Text -> Handler ()
sendImage f = do
- fpath <- imageFilePath f
- sendFile imageCT (encodeString fpath)
+ fpath <- imageFilePath $ unpack f
+ sendFile imageCT fpath
randomFileName :: Handler FilePath
randomFileName = do
base <- liftIO $ replicateM 32 (randomRIO ('a','z'))
master <- getYesod
let uploadDir = appMediaDir $ appSettings master
- return $ decodeString uploadDir </> decodeString base <.> imageExt
+ return $ uploadDir </> base <.> unpack imageExt
getImageId :: Maybe ImageId
-> Maybe FileInfo
diff --git a/mokupona.cabal b/mokupona.cabal
index be9b73c..f72a0f6 100644
--- a/mokupona.cabal
+++ b/mokupona.cabal
@@ -133,11 +133,10 @@ library
, containers
, vector
, time
+ , filepath >= 1.1
, mime-mail >= 0.4.4.1
, blaze-markup >= 0.5.1.5
, blaze-html >= 0.6.1.1
- , system-filepath >= 0.4.10
- , system-fileio >= 0.3.12
, process >= 1.1.0.2
, random >= 1.0.1.1
, esqueleto >= 1.4.1