module WaiAppStatic.Types
(
Piece
, toPiece
, fromPiece
, unsafeToPiece
, Pieces
, toPieces
, MaxAge (..)
, FolderName
, Folder (..)
, File (..)
, LookupResult (..)
, Listing
, StaticSettings (..)
) where
import Data.Text (Text)
import qualified Network.HTTP.Types as H
import qualified Network.Wai as W
import Data.ByteString (ByteString)
import System.Posix.Types (EpochTime)
import qualified Data.Text as T
import Data.ByteString.Builder (Builder)
import Network.Mime (MimeType)
newtype Piece = Piece { Piece -> Text
fromPiece :: Text }
deriving (Int -> Piece -> ShowS
[Piece] -> ShowS
Piece -> String
(Int -> Piece -> ShowS)
-> (Piece -> String) -> ([Piece] -> ShowS) -> Show Piece
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Piece] -> ShowS
$cshowList :: [Piece] -> ShowS
show :: Piece -> String
$cshow :: Piece -> String
showsPrec :: Int -> Piece -> ShowS
$cshowsPrec :: Int -> Piece -> ShowS
Show, Piece -> Piece -> Bool
(Piece -> Piece -> Bool) -> (Piece -> Piece -> Bool) -> Eq Piece
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Piece -> Piece -> Bool
$c/= :: Piece -> Piece -> Bool
== :: Piece -> Piece -> Bool
$c== :: Piece -> Piece -> Bool
Eq, Eq Piece
Eq Piece
-> (Piece -> Piece -> Ordering)
-> (Piece -> Piece -> Bool)
-> (Piece -> Piece -> Bool)
-> (Piece -> Piece -> Bool)
-> (Piece -> Piece -> Bool)
-> (Piece -> Piece -> Piece)
-> (Piece -> Piece -> Piece)
-> Ord Piece
Piece -> Piece -> Bool
Piece -> Piece -> Ordering
Piece -> Piece -> Piece
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Piece -> Piece -> Piece
$cmin :: Piece -> Piece -> Piece
max :: Piece -> Piece -> Piece
$cmax :: Piece -> Piece -> Piece
>= :: Piece -> Piece -> Bool
$c>= :: Piece -> Piece -> Bool
> :: Piece -> Piece -> Bool
$c> :: Piece -> Piece -> Bool
<= :: Piece -> Piece -> Bool
$c<= :: Piece -> Piece -> Bool
< :: Piece -> Piece -> Bool
$c< :: Piece -> Piece -> Bool
compare :: Piece -> Piece -> Ordering
$ccompare :: Piece -> Piece -> Ordering
$cp1Ord :: Eq Piece
Ord)
toPiece :: Text -> Maybe Piece
toPiece :: Text -> Maybe Piece
toPiece Text
t
| Text -> Bool
T.null Text
t = Piece -> Maybe Piece
forall a. a -> Maybe a
Just (Piece -> Maybe Piece) -> Piece -> Maybe Piece
forall a b. (a -> b) -> a -> b
$ Text -> Piece
Piece Text
t
| Text -> Char
T.head Text
t Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.' = Maybe Piece
forall a. Maybe a
Nothing
| (Char -> Bool) -> Text -> Bool
T.any (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'/') Text
t = Maybe Piece
forall a. Maybe a
Nothing
| Bool
otherwise = Piece -> Maybe Piece
forall a. a -> Maybe a
Just (Piece -> Maybe Piece) -> Piece -> Maybe Piece
forall a b. (a -> b) -> a -> b
$ Text -> Piece
Piece Text
t
unsafeToPiece :: Text -> Piece
unsafeToPiece :: Text -> Piece
unsafeToPiece = Text -> Piece
Piece
toPieces :: [Text] -> Maybe Pieces
toPieces :: [Text] -> Maybe [Piece]
toPieces = (Text -> Maybe Piece) -> [Text] -> Maybe [Piece]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Text -> Maybe Piece
toPiece
type Pieces = [Piece]
data MaxAge = NoMaxAge
| MaxAgeSeconds Int
| MaxAgeForever
type FolderName = Piece
data Folder = Folder
{ Folder -> [Either Piece File]
folderContents :: [Either FolderName File]
}
data File = File
{
File -> Integer
fileGetSize :: Integer
, File -> Status -> ResponseHeaders -> Response
fileToResponse :: H.Status -> H.ResponseHeaders -> W.Response
, File -> Piece
fileName :: Piece
, File -> IO (Maybe ByteString)
fileGetHash :: IO (Maybe ByteString)
, File -> Maybe EpochTime
fileGetModified :: Maybe EpochTime
}
data LookupResult = LRFile File
| LRFolder Folder
| LRNotFound
type Listing = Pieces -> Folder -> IO Builder
data StaticSettings = StaticSettings
{
StaticSettings -> [Piece] -> IO LookupResult
ssLookupFile :: Pieces -> IO LookupResult
, StaticSettings -> File -> IO ByteString
ssGetMimeType :: File -> IO MimeType
, StaticSettings -> [Piece]
ssIndices :: [Piece]
, StaticSettings -> Maybe Listing
ssListing :: Maybe Listing
, StaticSettings -> MaxAge
ssMaxAge :: MaxAge
, StaticSettings -> [Piece] -> ByteString -> ByteString
ssMkRedirect :: Pieces -> ByteString -> ByteString
, StaticSettings -> Bool
ssRedirectToIndex :: Bool
, StaticSettings -> Bool
ssUseHash :: Bool
, StaticSettings -> Bool
ssAddTrailingSlash :: Bool
, StaticSettings -> Maybe Application
ss404Handler :: Maybe W.Application
}