streaming output works

This commit is contained in:
Aaron Greenspan
2019-12-24 00:13:57 -07:00
parent 8915998a5f
commit 159e576eac
23 changed files with 171 additions and 221 deletions

View File

@@ -12,11 +12,14 @@ import Data.Aeson
import qualified Data.ByteString.Lazy as BS
import Data.Conduit
import qualified Data.Conduit.Binary as CB
import System.FilePath
import System.Directory
import Yesod.Core
import Foundation
import Lib.Resource
import Handler.Types.Status
import Lib.Registry
import Lib.Semver
import Lib.Types.Semver
pureLog :: Show a => a -> Handler a
pureLog = liftA2 (*>) ($logInfo . show) pure
@@ -24,6 +27,28 @@ pureLog = liftA2 (*>) ($logInfo . show) pure
logRet :: ToJSON a => Handler a -> Handler a
logRet = (>>= liftA2 (*>) ($logInfo . decodeUtf8 . BS.toStrict . encode) pure)
type AppManifestYml = TypedContent
getAppsManifestR :: Handler AppManifestYml
getAppsManifestR = respondSource typePlain $ CB.sourceFile manifestPath .| awaitForever sendChunkBS
getAppsManifestR :: Handler TypedContent
getAppsManifestR = respondSource typePlain $ CB.sourceFile appManifestPath .| awaitForever sendChunkBS
getAgentR :: Handler TypedContent
getAgentR = getApp sysResourceDir $ S9PK "agent"
getAppMgrR :: Handler TypedContent
getAppMgrR = getApp sysResourceDir $ S9PK "appmgr"
getAppR :: S9PK -> Handler TypedContent
getAppR = getApp appResourceDir
getApp :: FilePath -> S9PK -> Handler TypedContent
getApp rootDir (S9PK appId) = do
spec <- querySpecD mostRecentVersion <$> lookupGetParam "spec"
appVersions <- registeredAppVersions appId <$> loadRegistry rootDir
case getSpecifiedAppVersion spec appVersions of
Nothing -> respondSource typePlain sendFlush
Just (RegisteredAppVersion (_, filePath)) -> do
exists <- liftIO $ doesFileExist filePath
if exists
then respondSource typePlain $ CB.sourceFile filePath .| awaitForever sendChunkBS
else respondSource typePlain sendFlush