improve gemini protocol cases
This commit is contained in:
parent
1809a0d13a
commit
92f356e09f
|
@ -8,13 +8,16 @@ import System.Directory (doesDirectoryExist, doesFileExist)
|
|||
import Text.Regex
|
||||
import Text.Regex.PCRE
|
||||
|
||||
|
||||
getFile :: FilePath -> IO (Maybe String)
|
||||
getFile s = do
|
||||
result <- try (readFile s) :: IO (Either SomeException String)
|
||||
case result of
|
||||
Left ex -> return Nothing
|
||||
Right ex -> return (pure ex)
|
||||
exists <- doesFileExist s
|
||||
case exists of
|
||||
True -> do
|
||||
result <- try (readFile s) :: IO (Either SomeException String)
|
||||
case result of
|
||||
Left ex -> return Nothing
|
||||
Right ex -> return (Just ex)
|
||||
False -> return Nothing
|
||||
|
||||
-- return components of the url
|
||||
-- gemini:// | hostname | uri | ? | query
|
||||
|
@ -66,9 +69,14 @@ parse_to_gemini tab =
|
|||
query = tab !! 0 !! 5
|
||||
}
|
||||
|
||||
create_answer :: Gemini -> String -> String -> IO Answer
|
||||
create_answer (MkGemini domain file query) language basedir = do
|
||||
content <- getFile $ basedir ++ file
|
||||
create_answer :: Gemini -> String -> String -> Bool -> IO Answer
|
||||
create_answer (MkGemini domain file query) language baseDir vhost = do
|
||||
let baseDir' =
|
||||
if vhost
|
||||
then domain ++ "/" ++ baseDir
|
||||
else baseDir
|
||||
|
||||
content <- getFile $ baseDir' ++ file
|
||||
case content of
|
||||
Just x ->
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue