Skip to content

Commit 1ebbbaa

Browse files
committed
make the multipart types better
1 parent cd2002b commit 1ebbbaa

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed

solga-client-ghcjs/src/Solga/Client/GHCJS.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ instance (Client next) => Client (WithIO next) where
200200
type RequestData (WithIO next) = RequestData next
201201
performRequest _p req perf = performRequest (Proxy @next) req perf
202202

203-
instance (Client next) => Client (ReqBodyMultipart fp a next) where
203+
instance (Client next) => Client (ReqBodyMultipart a next) where
204204
type
205-
RequestData (ReqBodyMultipart fp a next) =
206-
WithData [(JSString, Xhr.FormDataVal)] (RequestData next)
207-
performRequest _p req (WithData fd perf) = do
208-
performRequest (Proxy @next) req{reqData = Xhr.FormData fd} perf
205+
RequestData (ReqBodyMultipart a next) =
206+
WithData (a, a -> [(JSString, Xhr.FormDataVal)]) (RequestData next)
207+
performRequest _p req (WithData (x, f) perf) = do
208+
performRequest (Proxy @next) req{reqData = Xhr.FormData (f x)} perf

solga-client/src/Solga/Client.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ instance (Client next, ToSegment a) => Client (Capture a next) where
131131
performRequest (Proxy @next) (addSegment req (toSegment x)) mgr perf
132132

133133
instance (Client next, KnownSymbol method) => Client (Method method next) where
134-
type RequestData (Method seg next) = RequestData next
134+
type RequestData (Method method next) = RequestData next
135135
performRequest _p req mgr perf = performRequest
136136
(Proxy @next) req{Http.method = BSC8.pack (symbolVal (Proxy @method))} mgr perf
137137

@@ -164,11 +164,12 @@ instance (Client next) => Client (WithIO next) where
164164
type RequestData (WithIO next) = RequestData next
165165
performRequest _p req mgr perf = performRequest (Proxy @next) req mgr perf
166166

167-
instance (Client next) => Client (ReqBodyMultipart fp a next) where
167+
instance (Client next) => Client (ReqBodyMultipart a next) where
168168
type
169-
RequestData (ReqBodyMultipart fp a next) =
170-
WithData ([Http.Part], Maybe ByteString) (RequestData next)
171-
performRequest _p req mgr (WithData (parts, mbBoundary) perf) = do
169+
RequestData (ReqBodyMultipart a next) =
170+
WithData (a, a -> ([Http.Part], Maybe ByteString)) (RequestData next)
171+
performRequest _p req mgr (WithData (x, f) perf) = do
172+
let (parts, mbBoundary) = f x
172173
req' <- case mbBoundary of
173174
Nothing -> Http.formDataBody parts req
174175
Just x -> Http.formDataBodyWithBoundary x parts req

solga-client/test/Test.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ spec port = do
9797
Right seg' <- return decodeSeg
9898
return (seg == seg')
9999

100-
deriving instance Generic Value
101-
102100
instance Arbitrary Value where
103101
arbitrary = sized arbJSON
104102
where

solga-core/src/Solga/Core.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,22 @@ newtype ReqBodyJSON a next = ReqBodyJSON { reqBodyJSONNext :: a -> next }
113113
newtype WithIO next = WithIO { withIONext :: IO next }
114114

115115
type MultiPartParam = (ByteString, ByteString)
116-
type MultiPartFile y = (ByteString, MultiPartFileInfo y)
116+
type MultiPartFile = (ByteString, MultiPartFileInfo)
117117

118-
data MultiPartFileInfo c = MultiPartFileInfo
118+
data MultiPartFileInfo = MultiPartFileInfo
119119
{ mpfiName :: ByteString
120120
, mpfiContentType :: ByteString
121121
, mpfiContent :: FilePath
122122
}
123123

124124
-- | A parsed "multipart/form-data" request.
125-
type MultiPartData y = ([MultiPartParam], [MultiPartFile y])
125+
type MultiPartData = ([MultiPartParam], [MultiPartFile])
126126

127127
-- | Accept a "multipart/form-data" request.
128128
-- Files will be stored in a temporary directory and will be deleted
129129
-- automatically after the request is processed.
130-
data ReqBodyMultipart y a next = ReqBodyMultipart
131-
{ reqMultiPartParse :: MultiPartData y -> Either String a
130+
data ReqBodyMultipart a next = ReqBodyMultipart
131+
{ reqMultiPartParse :: MultiPartData -> Either String a
132132
, reqMultiPartNext :: a -> next
133133
}
134134

solga-router/src/Solga/Router.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ instance (Aeson.FromJSON a, Router next) => Router (ReqBodyJSON a next) where
172172
instance Router next => Router (WithIO next) where
173173
tryRoute = tryRouteNextIO withIONext
174174

175-
instance (fp ~ FilePath, Router next) => Router (ReqBodyMultipart fp a next) where
175+
instance (Router next) => Router (ReqBodyMultipart a next) where
176176
tryRoute req = flip fmap (tryRoute req) $ \nextRouter rmp cont ->
177177
runResourceT $ withInternalState $ \s -> do
178178
(params, fileInfos0) <- Wai.parseRequestBody (Wai.tempFileBackEnd s) req
@@ -186,7 +186,7 @@ instance (fp ~ FilePath, Router next) => Router (ReqBodyMultipart fp a next) whe
186186
, mpfiContent = fileContent
187187
}
188188
)
189-
let multiPart :: MultiPartData FilePath = (params, fileInfos)
189+
let multiPart :: MultiPartData = (params, fileInfos)
190190
case reqMultiPartParse rmp multiPart of
191191
Left err -> throwIO $ badRequest $ "Could not decode form request: " <> Text.pack err
192192
Right val -> nextRouter (reqMultiPartNext rmp val) cont
@@ -251,7 +251,7 @@ instance Abbreviated next => Abbreviated (WithIO next) where
251251
type Brief (WithIO next) = IO (Brief next)
252252
brief = WithIO . fmap brief
253253

254-
instance Abbreviated (ReqBodyMultipart fp a next)
254+
instance Abbreviated (ReqBodyMultipart a next)
255255

256256
-- Generic routers
257257

solga-swagger/src/Solga/Swagger.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ instance RouterSwagger next => RouterSwagger (NoCache next) where
136136
instance RouterSwagger next => RouterSwagger (ExtraHeaders next) where
137137
genPaths = passPaths
138138

139-
instance RouterSwagger (ReqBodyMultipart fp a next) where
139+
instance RouterSwagger (ReqBodyMultipart a next) where
140140
genPaths = noPaths
141141

142142
instance RouterSwagger (OneOfSegs '[] next) where

0 commit comments

Comments
 (0)