From a15179ab68f7aab00316ef014cf1388550b0ceb0 Mon Sep 17 00:00:00 2001 From: Lucy Cifferello <12953208+elvece@users.noreply.github.com> Date: Mon, 23 Aug 2021 15:34:59 -0600 Subject: [PATCH] fix routes --- config/routes | 21 ++++++----- src/Handler/Icons.hs | 75 ++++++++++++++++++++------------------ src/Handler/Marketplace.hs | 4 ++ 3 files changed, 55 insertions(+), 45 deletions(-) diff --git a/config/routes b/config/routes index 3a6e4d8..e2f720f 100644 --- a/config/routes +++ b/config/routes @@ -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= +/marketplace/package/release-notes ReleaseNotesR GET -- get release notes for package - expects query param of id= +/icons/#PNG IconsR GET -- get icons - expects ?version= + +-- 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 \ No newline at end of file +/sys/version/#Text VersionSysR GET -- get most recent sys app version \ No newline at end of file diff --git a/src/Handler/Icons.hs b/src/Handler/Icons.hs index d05eb96..179b619 100644 --- a/src/Handler/Icons.hs +++ b/src/Handler/Icons.hs @@ -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 \ No newline at end of file +-- 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 \ No newline at end of file diff --git a/src/Handler/Marketplace.hs b/src/Handler/Marketplace.hs index de01166..2c5f04b 100644 --- a/src/Handler/Marketplace.hs +++ b/src/Handler/Marketplace.hs @@ -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