mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 02:11:53 +00:00
get system status endpoint
This commit is contained in:
@@ -13,3 +13,4 @@
|
|||||||
!/apps/#S9PK AppR GET -- get most recent appId at appversion spec, defaults to >=0.0.0 -- ?spec={semver-spec}
|
!/apps/#S9PK AppR GET -- get most recent appId at appversion spec, defaults to >=0.0.0 -- ?spec={semver-spec}
|
||||||
|
|
||||||
!/sys/#SYS_EXTENSIONLESS SysR GET -- get most recent sys app -- ?spec={semver-spec}
|
!/sys/#SYS_EXTENSIONLESS SysR GET -- get most recent sys app -- ?spec={semver-spec}
|
||||||
|
/sys/status SystemStatusR GET -- get system update status and version
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
{-# LANGUAGE FlexibleInstances #-}
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
{-# LANGUAGE NamedFieldPuns #-}
|
{-# LANGUAGE NamedFieldPuns #-}
|
||||||
module Handler.Types.Status where
|
module Handler.Types.Status where
|
||||||
@@ -9,6 +10,7 @@ import Yesod.Core.Content
|
|||||||
|
|
||||||
import Lib.Types.Emver
|
import Lib.Types.Emver
|
||||||
import Orphans.Emver ( )
|
import Orphans.Emver ( )
|
||||||
|
import Data.Text
|
||||||
|
|
||||||
data AppVersionRes = AppVersionRes
|
data AppVersionRes = AppVersionRes
|
||||||
{ appVersionVersion :: Version
|
{ appVersionVersion :: Version
|
||||||
@@ -35,3 +37,22 @@ instance ToContent (Maybe AppVersionRes) where
|
|||||||
toContent = toContent . toJSON
|
toContent = toContent . toJSON
|
||||||
instance ToTypedContent (Maybe AppVersionRes) where
|
instance ToTypedContent (Maybe AppVersionRes) where
|
||||||
toTypedContent = toTypedContent . toJSON
|
toTypedContent = toTypedContent . toJSON
|
||||||
|
|
||||||
|
-- status - nothing, available, instuctions
|
||||||
|
-- version - semver string
|
||||||
|
|
||||||
|
data SystemStatus = NOTHING | AVAILABLE | INSTRUCTIONS
|
||||||
|
deriving (Eq, Show)
|
||||||
|
instance ToJSON SystemStatus where
|
||||||
|
toJSON = String . toLower . show
|
||||||
|
|
||||||
|
data OSVersionRes = OSVersionRes
|
||||||
|
{ osVersionStatus :: SystemStatus
|
||||||
|
, osVersionVersion :: Version
|
||||||
|
} deriving (Eq, Show)
|
||||||
|
instance ToJSON OSVersionRes where
|
||||||
|
toJSON OSVersionRes { .. } = object ["status" .= osVersionStatus, "version" .= osVersionVersion]
|
||||||
|
instance ToContent OSVersionRes where
|
||||||
|
toContent = toContent . toJSON
|
||||||
|
instance ToTypedContent OSVersionRes where
|
||||||
|
toTypedContent = toTypedContent . toJSON
|
||||||
@@ -44,3 +44,8 @@ getVersionWSpec :: KnownSymbol a => FilePath -> Extension a -> Handler (Maybe Ap
|
|||||||
getVersionWSpec rootDir ext = do
|
getVersionWSpec rootDir ext = do
|
||||||
av <- getVersionFromQuery rootDir ext
|
av <- getVersionFromQuery rootDir ext
|
||||||
pure $ liftA3 AppVersionRes av (pure Nothing) (pure Nothing)
|
pure $ liftA3 AppVersionRes av (pure Nothing) (pure Nothing)
|
||||||
|
|
||||||
|
getSystemStatusR :: Handler OSVersionRes
|
||||||
|
getSystemStatusR = do
|
||||||
|
-- hardcoded since this will be last OS version release on this registry before 1.0
|
||||||
|
pure $ OSVersionRes NOTHING $ Version (0,2,13,0)
|
||||||
@@ -37,6 +37,7 @@ getAvailableAppVersions rootDirectory ext@(Extension appId) = do
|
|||||||
getSubDirectories path = (fmap (fromRight []) . try @SomeException $ listDirectory path)
|
getSubDirectories path = (fmap (fromRight []) . try @SomeException $ listDirectory path)
|
||||||
>>= filterM (doesDirectoryExist . (path </>))
|
>>= filterM (doesDirectoryExist . (path </>))
|
||||||
|
|
||||||
|
-- this works for both service versions and embassyOS versions
|
||||||
getMostRecentAppVersion :: KnownSymbol a => FilePath -> Extension a -> IO (Maybe RegisteredAppVersion)
|
getMostRecentAppVersion :: KnownSymbol a => FilePath -> Extension a -> IO (Maybe RegisteredAppVersion)
|
||||||
getMostRecentAppVersion rootDirectory ext = do
|
getMostRecentAppVersion rootDirectory ext = do
|
||||||
allVersions <- liftIO $ getAvailableAppVersions rootDirectory ext
|
allVersions <- liftIO $ getAvailableAppVersions rootDirectory ext
|
||||||
|
|||||||
Reference in New Issue
Block a user