diff --git a/config/routes b/config/routes index 50d46b9..e5b5994 100644 --- a/config/routes +++ b/config/routes @@ -12,4 +12,5 @@ /icons/#PNG IconsR GET -- get icons !/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} \ No newline at end of file +!/sys/#SYS_EXTENSIONLESS SysR GET -- get most recent sys app -- ?spec={semver-spec} +/sys/status SystemStatusR GET -- get system update status and version \ No newline at end of file diff --git a/src/Handler/Types/Status.hs b/src/Handler/Types/Status.hs index cada3de..24a8c63 100644 --- a/src/Handler/Types/Status.hs +++ b/src/Handler/Types/Status.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE NamedFieldPuns #-} module Handler.Types.Status where @@ -9,6 +10,7 @@ import Yesod.Core.Content import Lib.Types.Emver import Orphans.Emver ( ) +import Data.Text data AppVersionRes = AppVersionRes { appVersionVersion :: Version @@ -35,3 +37,22 @@ instance ToContent (Maybe AppVersionRes) where toContent = toContent . toJSON instance ToTypedContent (Maybe AppVersionRes) where 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 \ No newline at end of file diff --git a/src/Handler/Version.hs b/src/Handler/Version.hs index 4886c19..9c314ee 100644 --- a/src/Handler/Version.hs +++ b/src/Handler/Version.hs @@ -44,3 +44,8 @@ getVersionWSpec :: KnownSymbol a => FilePath -> Extension a -> Handler (Maybe Ap getVersionWSpec rootDir ext = do av <- getVersionFromQuery rootDir ext 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) \ No newline at end of file diff --git a/src/Lib/Registry.hs b/src/Lib/Registry.hs index 15694c5..d586245 100644 --- a/src/Lib/Registry.hs +++ b/src/Lib/Registry.hs @@ -37,6 +37,7 @@ getAvailableAppVersions rootDirectory ext@(Extension appId) = do getSubDirectories path = (fmap (fromRight []) . try @SomeException $ listDirectory path) >>= filterM (doesDirectoryExist . (path )) +-- this works for both service versions and embassyOS versions getMostRecentAppVersion :: KnownSymbol a => FilePath -> Extension a -> IO (Maybe RegisteredAppVersion) getMostRecentAppVersion rootDirectory ext = do allVersions <- liftIO $ getAvailableAppVersions rootDirectory ext