Detect how to display pdf files

Closes: #1099
This commit is contained in:
eikek
2021-10-06 23:20:16 +02:00
parent b6187bb88d
commit f216c472ee
15 changed files with 217 additions and 87 deletions

View File

@ -0,0 +1,67 @@
module Data.Pdf exposing (PdfMode(..), allModes, asString, detectUrl, fromString, serverUrl)
{-| Makes use of the fact, that docspell uses a `/view` suffix on the
path to provide a browser independent PDF view.
-}
import Data.Flags exposing (Flags)
import Html exposing (..)
import Html.Attributes exposing (..)
type PdfMode
= Detect
| Native
| Server
allModes : List PdfMode
allModes =
[ Detect, Native, Server ]
asString : PdfMode -> String
asString mode =
case mode of
Detect ->
"detect"
Native ->
"native"
Server ->
"server"
fromString : String -> Maybe PdfMode
fromString str =
case String.toLower str of
"detect" ->
Just Detect
"native" ->
Just Native
"server" ->
Just Server
_ ->
Nothing
serverUrl : String -> String
serverUrl url =
if String.endsWith "/" url then
url ++ "view"
else
url ++ "/view"
detectUrl : Flags -> String -> String
detectUrl flags url =
if flags.pdfSupported then
url
else
serverUrl url