From 84034bb510dc433fc1fb43b25cef63f2886636d7 Mon Sep 17 00:00:00 2001 From: Lucy Cifferello Date: Tue, 7 Jul 2020 18:10:45 -0600 Subject: [PATCH] more dynamic flow --- src/Handler/Apps.hs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Handler/Apps.hs b/src/Handler/Apps.hs index 2f3160d..74ad59e 100644 --- a/src/Handler/Apps.hs +++ b/src/Handler/Apps.hs @@ -78,21 +78,20 @@ getApp rootDir ext@(Extension appId) = do determineEvent exists (extension ext) filePath appVersion where determineEvent :: FileExistence -> String -> FilePath -> AppVersion -> HandlerFor AgentCtx TypedContent - -- for system files - determineEvent Existent "" fp _ = do - sz <- liftIO $ fileSize <$> getFileStatus fp - addHeader "Content-Length" (show sz) - respondSource typePlain $ CB.sourceFile fp .| awaitForever sendChunkBS -- for app files determineEvent Existent "s9pk" fp av = do _ <- recordMetrics appId rootDir av - sz <- liftIO $ fileSize <$> getFileStatus fp - addHeader "Content-Length" (show sz) - respondSource typePlain $ CB.sourceFile fp .| awaitForever sendChunkBS - -- for png files - determineEvent Existent _ _ _ = notFound + chunkIt fp + -- for png, system, etc + determineEvent Existent _ fp _ = chunkIt fp determineEvent NonExistent _ _ _ = notFound +chunkIt :: FilePath -> HandlerFor AgentCtx TypedContent +chunkIt fp = do + sz <- liftIO $ fileSize <$> getFileStatus fp + addHeader "Content-Length" (show sz) + respondSource typePlain $ CB.sourceFile fp .| awaitForever sendChunkBS + recordMetrics :: String -> FilePath -> AppVersion -> HandlerFor AgentCtx () recordMetrics appId rootDir appVersion = do let appId' = T.pack appId