fix routes

This commit is contained in:
Lucy Cifferello
2021-08-23 15:34:59 -06:00
parent f81d76eb6a
commit ff803583c1
3 changed files with 55 additions and 45 deletions

View File

@@ -1,16 +1,19 @@
!/package/#S9PK AppR GET -- get most recent appId at appversion spec, defaults to >=0.0.0 -- ?spec={semver-spec}
/marketplace/package/data CategoriesR GET -- get all marketplace categories
/marketplace/package/index PackageListR GET -- filter marketplace services by various query params
/eos EosR GET -- get eos information
/marketplace/latest-version VersionLatestR GET -- get latest version of apps in query param id
/package/data CategoriesR GET -- get all marketplace categories
/package/index PackageListR GET -- filter marketplace services by various query params
/eos/latest EosR GET -- get eos information
/latest-version VersionLatestR GET -- get latest version of apps in query param id
/package/manifest/#AppIdentifier AppManifestR GET -- get app manifest from appmgr -- ?version={semver-spec}
/marketplace/package/release-notes getReleaseNotesR GET -- get release notes for package - expects query param of id=<pacakge-id>
/marketplace/package/release-notes ReleaseNotesR GET -- get release notes for package - expects query param of id=<pacakge-id>
/icons/#PNG IconsR GET -- get icons - expects ?version=<emver>
-- TODO confirm needed
/package/config/#AppIdentifier AppConfigR GET -- get app config from appmgr -- ?spec={semver-spec}
/package/version/#Text VersionAppR GET -- get most recent appId version
-- TODO deprecate
!/sys/#SYS_EXTENSIONLESS SysR GET -- get most recent sys app -- ?spec={semver-spec}
/version VersionR GET
/icons/#PNG IconsR GET -- get icons
/sys/version/#Text VersionSysR GET -- get most recent sys app version
/package/config/#AppIdentifier AppConfigR GET -- get app config from appmgr -- ?spec={semver-spec}
/package/version/#Text VersionAppR GET -- get most recent appId version
/sys/version/#Text VersionSysR GET -- get most recent sys app version

View File

@@ -7,7 +7,7 @@ module Handler.Icons where
import Startlude hiding (Handler)
import Data.Conduit
import qualified Data.Conduit.Binary as CB
import qualified Data.Conduit.Combinators as CB
import System.Directory
import Yesod.Core
@@ -15,44 +15,47 @@ import Foundation
import Lib.Registry
import Settings
import System.FilePath ((</>))
import Util.Shared
import Lib.External.AppMgr
import Lib.Error
import qualified Data.ByteString.Lazy as BS
getIconsR :: Extension "png" -> Handler TypedContent
getIconsR ext = do
-- @TODO switch to getting from service directory
AppSettings{..} <- appSettings <$> getYesod
mPng <- liftIO $ getVersionedFileFromDir (resourcesDir </> "icons") ext
case mPng of
(appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings
spec <- getVersionFromQuery appsDir ext >>= \case
Nothing -> notFound
Just v -> pure v
servicePath <- liftIO $ getVersionedFileFromDir (appsDir </> show spec) ext spec
case servicePath of
Nothing -> notFound
Just pngPath -> do
putStrLn @Text $ show pngPath
exists <- liftIO $ doesFileExist pngPath
if exists
then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS
else notFound
Just p -> do
icon <- handleS9ErrT $ getIcon appMgrDir p ext
respondSource typePlain $ CB.sourceLazy (BS.fromStrict icon) .| awaitForever sendChunkBS
getLicenseR :: Extension "" -> Handler TypedContent
getLicenseR ext = do
AppSettings{..} <- appSettings <$> getYesod
mPng <- liftIO $ getUnversionedFileFromDir (resourcesDir </> "icons") ext
case mPng of
Nothing -> notFound
Just pngPath -> do
putStrLn @Text $ show pngPath
exists <- liftIO $ doesFileExist pngPath
if exists
then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS
else notFound
-- getLicenseR :: Extension "" -> Handler TypedContent
-- getLicenseR ext = do
-- AppSettings{..} <- appSettings <$> getYesod
-- mPng <- liftIO $ getUnversionedFileFromDir (resourcesDir </> "icons") ext
-- case mPng of
-- Nothing -> notFound
-- Just pngPath -> do
-- putStrLn @Text $ show pngPath
-- exists <- liftIO $ doesFileExist pngPath
-- if exists
-- then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS
-- else notFound
getMarkdownR :: Extension "md" -> Handler TypedContent
getMarkdownR ext = do
-- @TODO switch to getting from service directory
AppSettings{..} <- appSettings <$> getYesod
mPng <- liftIO $ getUnversionedFileFromDir (resourcesDir </> "icons") ext
case mPng of
Nothing -> notFound
Just pngPath -> do
putStrLn @Text $ show pngPath
exists <- liftIO $ doesFileExist pngPath
if exists
then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS
else notFound
-- getMarkdownR :: Extension "md" -> Handler TypedContent
-- getMarkdownR ext = do
-- -- @TODO switch to getting from service directory
-- AppSettings{..} <- appSettings <$> getYesod
-- mPng <- liftIO $ getUnversionedFileFromDir (resourcesDir </> "icons") ext
-- case mPng of
-- Nothing -> notFound
-- Just pngPath -> do
-- putStrLn @Text $ show pngPath
-- exists <- liftIO $ doesFileExist pngPath
-- if exists
-- then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS
-- else notFound

View File

@@ -59,6 +59,10 @@ newtype ReleaseNotes = ReleaseNotes { unReleaseNotes :: HM.HashMap Version Text
deriving (Eq, Show)
instance ToJSON ReleaseNotes where
toJSON ReleaseNotes { .. } = object [ t .= v | (k,v) <- HM.toList unReleaseNotes, let (String t) = toJSON k ]
instance ToContent ReleaseNotes where
toContent = toContent . toJSON
instance ToTypedContent ReleaseNotes where
toTypedContent = toTypedContent . toJSON
instance ToJSON ServiceRes where
toJSON ServiceRes {..} = object
[ "icon" .= serviceResIcon