From e9e46a3b3392ab435f7414729592b2b5af4071b6 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 18 May 2020 20:05:14 +0200 Subject: compiler: add pdf resource type --- compiler/src/Processors.hs | 6 ++++-- compiler/src/Resource.hs | 1 + viewer/src/@types/gallery.d.ts | 11 +++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/compiler/src/Processors.hs b/compiler/src/Processors.hs index ca8a74c..2988f83 100644 --- a/compiler/src/Processors.hs +++ b/compiler/src/Processors.hs @@ -47,8 +47,8 @@ data ProcessingException = ProcessingException FilePath String deriving Show instance Exception ProcessingException --- TODO: handle video, music, markdown, pdf... -data Format = PictureFormat | PlainTextFormat | Unknown +-- TODO: handle video, music, markdown... +data Format = PictureFormat | PlainTextFormat | PortableDocumentFormat | Unknown formatFromPath :: Path -> Format formatFromPath = @@ -68,6 +68,7 @@ formatFromPath = ".gif" -> PictureFormat ".txt" -> PlainTextFormat ".md" -> PlainTextFormat -- TODO: handle markdown separately + ".pdf" -> PortableDocumentFormat _ -> Unknown @@ -173,6 +174,7 @@ itemFileProcessor maxResolution cached inputBase outputBase resClass inputRes = processorFor PictureFormat (Just maxRes) = (resizePictureUpTo maxRes, getPictureProps) processorFor PictureFormat Nothing = (copyFileProcessor, getPictureProps) processorFor PlainTextFormat _ = (copyFileProcessor, const $ return . PlainText) + processorFor PortableDocumentFormat _ = (copyFileProcessor, const $ return . PDF) -- TODO: handle video reencoding and others? processorFor Unknown _ = (copyFileProcessor, const $ return . Other) diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs index 5c175f1..129a817 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs @@ -76,6 +76,7 @@ data GalleryItemProps = { resource :: Resource , resolution :: Resolution } | PlainText { resource :: Resource } + | PDF { resource :: Resource } | Other { resource :: Resource } deriving (Generic, Show) diff --git a/viewer/src/@types/gallery.d.ts b/viewer/src/@types/gallery.d.ts index 04df1bb..7345ef9 100644 --- a/viewer/src/@types/gallery.d.ts +++ b/viewer/src/@types/gallery.d.ts @@ -40,6 +40,9 @@ declare namespace Gallery { interface PlainText extends Item { properties: PlainTextProperties, } + interface PDF extends Item { + properties: PDFProperties, + } interface Directory extends Item { properties: DirectoryProperties, } @@ -50,7 +53,7 @@ declare namespace Gallery { tags: RawTag[], path: string, thumbnail?: Thumbnail - properties: OtherProperties | PictureProperties | PlainTextProperties | DirectoryProperties, + properties: OtherProperties | PictureProperties | PlainTextProperties | PDFProperties | DirectoryProperties, } interface Resolution { width: number, @@ -69,6 +72,10 @@ declare namespace Gallery { type: "plaintext", resource: string, } + interface PDFProperties { + type: "pdf", + resource: string, + } interface DirectoryProperties { type: "directory", items: Item[] @@ -78,5 +85,5 @@ declare namespace Gallery { resolution: Resolution } type RawTag = string; - type ItemType = "other" | "picture" | "plaintext" | "directory"; + type ItemType = "other" | "picture" | "plaintext" | "pdf" | "directory"; } -- cgit v1.2.3