From 04d5cb917f4288c26a308dfda4ba788d77fda8fd Mon Sep 17 00:00:00 2001 From: pacien Date: Wed, 13 May 2020 00:18:16 +0200 Subject: compiler: add plain text file format support through simple copy --- compiler/src/Processors.hs | 7 +++++-- compiler/src/Resource.hs | 1 + viewer/src/@types/gallery.d.ts | 11 +++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/compiler/src/Processors.hs b/compiler/src/Processors.hs index 02db325..ca8a74c 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, text... -data Format = PictureFormat | Unknown +-- TODO: handle video, music, markdown, pdf... +data Format = PictureFormat | PlainTextFormat | Unknown formatFromPath :: Path -> Format formatFromPath = @@ -66,6 +66,8 @@ formatFromPath = ".tiff" -> PictureFormat ".hdr" -> PictureFormat ".gif" -> PictureFormat + ".txt" -> PlainTextFormat + ".md" -> PlainTextFormat -- TODO: handle markdown separately _ -> Unknown @@ -170,6 +172,7 @@ itemFileProcessor maxResolution cached inputBase outputBase resClass inputRes = processorFor :: Format -> Maybe Resolution -> (FileProcessor, ItemDescriber) processorFor PictureFormat (Just maxRes) = (resizePictureUpTo maxRes, getPictureProps) processorFor PictureFormat Nothing = (copyFileProcessor, getPictureProps) + processorFor PlainTextFormat _ = (copyFileProcessor, const $ return . PlainText) -- 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 e134468..5c175f1 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs @@ -75,6 +75,7 @@ data GalleryItemProps = | Picture { resource :: Resource , resolution :: Resolution } + | PlainText { 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 3246894..04df1bb 100644 --- a/viewer/src/@types/gallery.d.ts +++ b/viewer/src/@types/gallery.d.ts @@ -37,6 +37,9 @@ declare namespace Gallery { interface Picture extends Item { properties: PictureProperties, } + interface PlainText extends Item { + properties: PlainTextProperties, + } interface Directory extends Item { properties: DirectoryProperties, } @@ -47,7 +50,7 @@ declare namespace Gallery { tags: RawTag[], path: string, thumbnail?: Thumbnail - properties: OtherProperties | PictureProperties | DirectoryProperties, + properties: OtherProperties | PictureProperties | PlainTextProperties | DirectoryProperties, } interface Resolution { width: number, @@ -62,6 +65,10 @@ declare namespace Gallery { resource: string, resolution: Resolution } + interface PlainTextProperties { + type: "plaintext", + resource: string, + } interface DirectoryProperties { type: "directory", items: Item[] @@ -71,5 +78,5 @@ declare namespace Gallery { resolution: Resolution } type RawTag = string; - type ItemType = "other" | "picture" | "directory"; + type ItemType = "other" | "picture" | "plaintext" | "directory"; } -- cgit v1.2.3