From fdb3b6d964ea82490d5c5abe94c97144c0d0288d Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Mon, 25 Dec 2023 13:34:22 +0100 Subject: chore: add `addedAt` tag --- apaperless.cabal | 3 ++- app/Main.hs | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/apaperless.cabal b/apaperless.cabal index 0f443ff..141a710 100644 --- a/apaperless.cabal +++ b/apaperless.cabal @@ -37,6 +37,7 @@ executable apaperless SHA, lock-file, data-default, - tags + tags, + time hs-source-dirs: app default-language: GHC2021 diff --git a/app/Main.hs b/app/Main.hs index b21030d..cb6e563 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -27,6 +27,8 @@ import Data.String (IsString (fromString)) import Data.Text qualified as T import Data.Text.Encoding qualified as T import Data.Text.IO qualified as T +import Data.Time.Clock (UTCTime, getCurrentTime) +import Data.Time.Format.ISO8601 (iso8601Show) import Debug.Trace import GHC.Conc (getNumProcessors) import GHC.Generics (Generic) @@ -276,7 +278,7 @@ readDocument iFileName = <$> decodeFile @Index ("index" iFileName) applyFilters :: [Filter] -> [Document] -> [Document] -applyFilters filters = filter (pred filters) `at` (.index.tags) +applyFilters filters = filter (pred filters) `at` (.index.internalTags) where pred1 (FilterByTag tagKey) = hasTag (Tag tagKey Nothing) pred filters = \index -> all ($ index) (map pred1 filters) @@ -484,6 +486,7 @@ consume1 keep filePath = do if not hasText then ocr filePath else pure originalText' + addedAt <- getCurrentTime withGit do J.encodeFile iFilePath Index {tags = S.singleton (Tag "todo" Nothing), ..} if keep @@ -548,7 +551,8 @@ ocr1 tmp input = data Index = Index { originalText :: T.Text, - tags :: S.Set Tag + tags :: S.Set Tag, + addedAt :: UTCTime } deriving (Show, Generic, Eq) @@ -561,6 +565,17 @@ instance HasField "shortText" Index T.Text where (T.unlines . take 10 . T.lines) . (.originalText) +instance HasField "internalTags" Index (S.Set Tag) where + getField index = + index.tags + `S.union` internalTags index + +internalTags :: Index -> S.Set Tag +internalTags index = + S.fromList + [ Tag "addedAt" (Just (T.pack (iso8601Show index.addedAt))) + ] + data PdfInfo = PdfInfo { numPages :: Int, pageSize :: (Double, Double) -- cgit v1.2.3