diff options
author | Yorhel <git@yorhel.nl> | 2020-05-12 19:04:46 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-05-13 15:33:23 +0200 |
commit | a6814eea0cfe2a0bf9db9779e94c3dd398361522 (patch) | |
tree | a398dcd66c2306d7d535b7746b2788a9fd961f31 /elm/Lib/Api.elm | |
parent | e169129934ac56d0f0758c981da009523bf4619f (diff) |
Chars::Edit: Add image editing
Diffstat (limited to 'elm/Lib/Api.elm')
-rw-r--r-- | elm/Lib/Api.elm | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/elm/Lib/Api.elm b/elm/Lib/Api.elm index 63f519cc..5dfda6d8 100644 --- a/elm/Lib/Api.elm +++ b/elm/Lib/Api.elm @@ -1,6 +1,7 @@ module Lib.Api exposing (..) import Json.Encode as JE +import File exposing (File) import Http import Gen.Api exposing (..) @@ -22,7 +23,7 @@ showResponse res = in case res of HTTPError (Http.Timeout) -> "Network timeout, please try again later." HTTPError (Http.NetworkError) -> "Network error, please try again later." - HTTPError (Http.BadStatus r) -> "Server error " ++ String.fromInt r ++ ", please try again later, or report an issue if this persists." + HTTPError (Http.BadStatus r) -> "Server error " ++ String.fromInt r ++ ", please try again later or report an issue if this persists." HTTPError (Http.BadBody r) -> "Invalid response from the server, please report a bug (debug info: " ++ r ++")." HTTPError (Http.BadUrl _) -> unexp Success -> unexp @@ -42,6 +43,8 @@ showResponse res = DoubleIP -> "You can only register one account from the same IP within 24 hours." BadCurPass -> "Current password is invalid." MailChange -> unexp + ImgFormat -> "Unrecognized image format, only JPEG and PNG are accepted." + Image _ _ _ -> unexp Releases _ -> unexp BoardResult _ -> unexp TagResult _ -> unexp @@ -69,3 +72,23 @@ post name body msg = , body = Http.jsonBody body , expect = expectResponse msg } + + +type ImageType + = Ch + | Cv + | Sf + +postImage : ImageType -> File -> (Response -> msg) -> Cmd msg +postImage ty file msg = + Http.post + { url = "/elm/ImageUpload.json" + , body = Http.multipartBody + [ Http.stringPart "type" <| case ty of + Cv -> "cv" + Sf -> "sf" + Ch -> "ch" + , Http.filePart "img" file + ] + , expect = expectResponse msg + } |