44 lines
1.4 KiB
Haskell
44 lines
1.4 KiB
Haskell
module Feature.Sharing.HTTP ( routes ) where
|
|
|
|
import Core.Configuration (dbPath, adminEmail, confLinkLength)
|
|
import Core.Templates (renderIndex)
|
|
import Core.Types
|
|
|
|
import Feature.Generation.Links (genLink)
|
|
import Feature.Sharing.SQLite (findByLink, insertNewSecret)
|
|
import Feature.Sharing.Templates (renderPw)
|
|
|
|
import Control.Monad.Trans (liftIO)
|
|
import Data.List.Split (splitOn)
|
|
import Data.Maybe (listToMaybe)
|
|
import Prelude
|
|
import System.Environment
|
|
import Web.Scotty
|
|
|
|
import qualified Data.Text as T
|
|
import qualified Data.Text.Lazy as LT
|
|
|
|
|
|
routes :: PurrApp ()
|
|
routes = do
|
|
|
|
get "/pw/:id" $ do
|
|
reqId <- param "id"
|
|
email <- liftIO adminEmail
|
|
html $ renderIndex reqId email
|
|
|
|
post "/pw" $ do
|
|
reqId <- param "userLink"
|
|
res <- findByLink reqId
|
|
html $ renderPw (last $ splitOn "/" reqId) res
|
|
|
|
post "/new" $ do
|
|
reqSecret <- param "newSec"
|
|
reqDur <- param "newSecDuration"
|
|
reqViews <- param "newSecViews"
|
|
cLengthStr <- liftIO confLinkLength
|
|
let cLength = read cLengthStr :: Int
|
|
link <- liftIO $ genLink cLength
|
|
insertNewSecret reqSecret reqDur (T.pack $ show link) reqViews
|
|
html $ renderPw (show link) (Just reqSecret)
|