From 516ee7c5599f2c90a636fd9301806bef67830046 Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 19 May 2020 21:06:16 +0200 Subject: compiler: add audio and video extensions --- compiler/src/Processors.hs | 24 ++++++++++++++++++++++-- compiler/src/Resource.hs | 2 ++ viewer/src/@types/gallery.d.ts | 24 ++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/compiler/src/Processors.hs b/compiler/src/Processors.hs index 2988f83..0efbf6d 100644 --- a/compiler/src/Processors.hs +++ b/compiler/src/Processors.hs @@ -47,8 +47,13 @@ data ProcessingException = ProcessingException FilePath String deriving Show instance Exception ProcessingException --- TODO: handle video, music, markdown... -data Format = PictureFormat | PlainTextFormat | PortableDocumentFormat | Unknown +data Format = + PictureFormat + | PlainTextFormat + | PortableDocumentFormat + | VideoFormat + | AudioFormat + | Unknown formatFromPath :: Path -> Format formatFromPath = @@ -69,6 +74,19 @@ formatFromPath = ".txt" -> PlainTextFormat ".md" -> PlainTextFormat -- TODO: handle markdown separately ".pdf" -> PortableDocumentFormat + ".wav" -> AudioFormat + ".oga" -> AudioFormat + ".ogg" -> AudioFormat + ".spx" -> AudioFormat + ".opus" -> AudioFormat + ".flac" -> AudioFormat + ".m4a" -> AudioFormat + ".mp3" -> AudioFormat + ".ogv" -> VideoFormat + ".ogx" -> VideoFormat + ".webm" -> VideoFormat + ".mkv" -> VideoFormat + ".mp4" -> VideoFormat _ -> Unknown @@ -175,6 +193,8 @@ itemFileProcessor maxResolution cached inputBase outputBase resClass inputRes = processorFor PictureFormat Nothing = (copyFileProcessor, getPictureProps) processorFor PlainTextFormat _ = (copyFileProcessor, const $ return . PlainText) processorFor PortableDocumentFormat _ = (copyFileProcessor, const $ return . PDF) + processorFor VideoFormat _ = (copyFileProcessor, const $ return . Video) + processorFor AudioFormat _ = (copyFileProcessor, const $ return . Audio) -- 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 129a817..c08677d 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs @@ -77,6 +77,8 @@ data GalleryItemProps = , resolution :: Resolution } | PlainText { resource :: Resource } | PDF { resource :: Resource } + | Video { resource :: Resource } + | Audio { 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 7345ef9..2407f98 100644 --- a/viewer/src/@types/gallery.d.ts +++ b/viewer/src/@types/gallery.d.ts @@ -43,6 +43,12 @@ declare namespace Gallery { interface PDF extends Item { properties: PDFProperties, } + interface Video extends Item { + properties: VideoProperties, + } + interface Audio extends Item { + properties: AudioProperties, + } interface Directory extends Item { properties: DirectoryProperties, } @@ -53,7 +59,13 @@ declare namespace Gallery { tags: RawTag[], path: string, thumbnail?: Thumbnail - properties: OtherProperties | PictureProperties | PlainTextProperties | PDFProperties | DirectoryProperties, + properties: OtherProperties + | PictureProperties + | PlainTextProperties + | PDFProperties + | VideoProperties + | AudioProperties + | DirectoryProperties, } interface Resolution { width: number, @@ -76,6 +88,14 @@ declare namespace Gallery { type: "pdf", resource: string, } + interface VideoProperties { + type: "video", + resource: string, + } + interface AudioProperties { + type: "audio", + resource: string, + } interface DirectoryProperties { type: "directory", items: Item[] @@ -85,5 +105,5 @@ declare namespace Gallery { resolution: Resolution } type RawTag = string; - type ItemType = "other" | "picture" | "plaintext" | "pdf" | "directory"; + type ItemType = "other" | "picture" | "plaintext" | "pdf" | "video" | "audio" | "directory"; } -- cgit v1.2.3