Skip to content

Commit 45dfda7

Browse files
committed
Extracted IHP.FileStorage.Preprocessor.ImageMagick to ihp-imagemagick package
1 parent c2b8a7c commit 45dfda7

File tree

5 files changed

+53
-7
lines changed

5 files changed

+53
-7
lines changed

NixSupport/overlay.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ final: prev: {
2424
ihp-job-dashboard = localPackage"ihp-job-dashboard";
2525
wai-asset-path = localPackage "wai-asset-path";
2626
wai-flash-messages = localPackage "wai-flash-messages";
27+
ihp-imagemagick = localPackage "ihp-imagemagick";
2728

2829
fsnotify = final.haskell.lib.dontCheck (super.callHackageDirect { pkg = "fsnotify"; ver = "0.4.3.0"; sha256 = "sha256-6SJ8w2p0HNhMPjdQzxx4oqsyI48/C/K7wh+kLNy9/fM="; } {});
2930

devenv-module.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ that is defined in flake-module.nix
144144
ihp-job-dashboard = pkgs.ghc.ihp-job-dashboard;
145145
wai-asset-path = pkgs.ghc.wai-asset-path;
146146
wai-flash-messages = pkgs.ghc.wai-flash-messages;
147+
ihp-imagemagick = pkgs.ghc.ihp-imagemagick;
147148

148149
run-script = pkgs.stdenv.mkDerivation {
149150
pname = "run-script";

ihp/IHP/FileStorage/Preprocessor/ImageMagick.hs renamed to ihp-imagemagick/IHP/FileStorage/Preprocessor/ImageMagick.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ module IHP.FileStorage.Preprocessor.ImageMagick
77
( applyImageMagick
88
) where
99

10-
import IHP.Prelude
10+
import Prelude
1111

12+
import Data.Text (Text)
13+
import qualified Data.Text as Text
1214
import qualified Network.Wai.Parse as Wai
1315
import qualified Data.ByteString.Lazy as LBS
1416
import qualified System.IO.Temp as Temp
@@ -48,15 +50,13 @@ import qualified System.Process as Process
4850
-- > company <- company |> updateRecord
4951
-- > redirectTo EditCompanyAction { .. }
5052
--
51-
applyImageMagick :: Text -> [String] -> Wai.FileInfo LByteString -> IO (Wai.FileInfo LByteString)
53+
applyImageMagick :: Text -> [String] -> Wai.FileInfo LBS.LazyByteString -> IO (Wai.FileInfo LBS.LazyByteString)
5254
applyImageMagick convertTo otherParams fileInfo = do
5355
Temp.withTempDirectory "/tmp" "ihp-upload" $ \tempPath -> do
5456
let tempFilePath = tempPath <> "/image"
55-
let convertedFilePath = tempPath <> "/converted." <> cs convertTo
57+
let convertedFilePath = tempPath <> "/converted." <> Text.unpack convertTo
5658

57-
fileInfo
58-
|> (.fileContent)
59-
|> LBS.writeFile tempFilePath
59+
LBS.writeFile tempFilePath fileInfo.fileContent
6060

6161
let params :: [String] = [tempFilePath] <> otherParams <> [convertedFilePath]
6262
Process.callProcess "magick" params
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
cabal-version: 2.2
2+
name: ihp-imagemagick
3+
version: 1.4.0
4+
synopsis: ImageMagick preprocessing for IHP file uploads
5+
description: Preprocess uploaded images with ImageMagick in IHP apps
6+
license: MIT
7+
author: digitally induced GmbH
8+
maintainer: [email protected]
9+
bug-reports: https://github.com/digitallyinduced/ihp/issues
10+
category: Web
11+
build-type: Simple
12+
13+
source-repository head
14+
type: git
15+
location: https://github.com/digitallyinduced/ihp.git
16+
17+
common ihp-std
18+
default-language: GHC2021
19+
default-extensions:
20+
NoImplicitPrelude
21+
OverloadedLabels
22+
OverloadedRecordDot
23+
DuplicateRecordFields
24+
DisambiguateRecordFields
25+
TypeApplications
26+
TemplateHaskell
27+
QuasiQuotes
28+
PackageImports
29+
ScopedTypeVariables
30+
BlockArguments
31+
OverloadedStrings
32+
ImplicitParams
33+
34+
library
35+
import: ihp-std
36+
build-depends:
37+
base >= 4.17.0 && < 4.22
38+
, text
39+
, bytestring
40+
, wai-extra
41+
, process
42+
, temporary
43+
hs-source-dirs: .
44+
exposed-modules: IHP.FileStorage.Preprocessor.ImageMagick

ihp/ihp.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ common shared-properties
137137
, wai-asset-path
138138
, wai-flash-messages
139139
, slugger
140+
, ihp-imagemagick
140141
default-extensions:
141142
OverloadedStrings
142143
, NoImplicitPrelude
@@ -262,7 +263,6 @@ library
262263
, IHP.FileStorage.Types
263264
, IHP.FileStorage.ControllerFunctions
264265
, IHP.FileStorage.Config
265-
, IHP.FileStorage.Preprocessor.ImageMagick
266266
, IHP.Pagination.ControllerFunctions
267267
, IHP.Pagination.ViewFunctions
268268
, IHP.Pagination.Types

0 commit comments

Comments
 (0)