module WaiAppStatic.Types (
Piece,
toPiece,
fromPiece,
unsafeToPiece,
Pieces,
toPieces,
MaxAge (..),
FolderName,
Folder (..),
File (..),
LookupResult (..),
Listing,
StaticSettings (..),
) where
import Data.ByteString (ByteString)
import Data.ByteString.Builder (Builder)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Network.HTTP.Types as H
import Network.Mime (MimeType)
import qualified Network.Wai as W
import System.Posix.Types (EpochTime)
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
$cshowsPrec :: Int -> Piece -> ShowS
showsPrec :: Int -> Piece -> ShowS
$cshow :: Piece -> String
show :: Piece -> String
$cshowList :: [Piece] -> ShowS
showList :: [Piece] -> ShowS
Show, Piece -> Piece -> Bool
(Piece -> Piece -> Bool) -> (Piece -> Piece -> Bool) -> Eq Piece
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Piece -> Piece -> Bool
== :: Piece -> Piece -> Bool
$c/= :: Piece -> Piece -> Bool
/= :: 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
$ccompare :: Piece -> Piece -> Ordering
compare :: Piece -> Piece -> Ordering
$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
>= :: Piece -> Piece -> Bool
$cmax :: Piece -> Piece -> Piece
max :: Piece -> Piece -> Piece
$cmin :: Piece -> Piece -> Piece
min :: Piece -> Piece -> 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
| HasCallStack => Text -> Char
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)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Text -> Maybe Piece
toPiece
type Pieces = [Piece]
data MaxAge
=
NoMaxAge
|
MaxAgeSeconds Int
|
MaxAgeForever
|
NoStore
|
NoCache
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
}