From 18329bd021ee23cc301bb29ec74f70460c39c090 Mon Sep 17 00:00:00 2001 From: Lucy Cifferello <12953208+elvece@users.noreply.github.com> Date: Thu, 10 Nov 2022 11:40:13 -0700 Subject: [PATCH] add marketplace icon to info response --- config/settings.yml | 5 +-- src/Handler/Package/V0/Info.hs | 11 +++++-- src/Settings.hs | 57 +++++++++++++++++----------------- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/config/settings.yml b/config/settings.yml index 77ab0d6..53baf7b 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -31,11 +31,12 @@ detailed-logging: true resources-path: "_env:RESOURCES_PATH:/var/www/html/resources" ssl-path: "_env:SSL_PATH:/var/ssl" ssl-auto: "_env:SSL_AUTO:true" -registry-hostname: "_env:REGISTRY_HOSTNAME:alpha-registry.start9labs.com" +registry-hostname: "_env:REGISTRY_HOSTNAME:alpha-registry-x.start9.com" tor-port: "_env:TOR_PORT:447" static-bin-dir: "_env:STATIC_BIN:/usr/local/bin/" -error-log-root: "_env:ERROR_LOG_ROOT:/var/log/embassy-os/" +error-log-root: "_env:ERROR_LOG_ROOT:/var/log/registry/" marketplace-name: "_env:MARKETPLACE_NAME:CHANGE ME" +icon-path: "_env:ICON_PATH:/var/www/html/resources" database: database: "_env:PG_DATABASE:start9_registry" diff --git a/src/Handler/Package/V0/Info.hs b/src/Handler/Package/V0/Info.hs index 3717acf..5595909 100644 --- a/src/Handler/Package/V0/Info.hs +++ b/src/Handler/Package/V0/Info.hs @@ -6,14 +6,17 @@ import Foundation (Handler, RegistryCtx (..)) import Handler.Util (tickleMAU) import Model (Category (..), EntityField (..)) import Settings (AppSettings (..)) -import Startlude (Generic, Show, Text, pure, ($), (.), (<$>)) +import Startlude (Generic, Show, Text, pure, ($), (.), (<$>), MonadIO (liftIO), decodeUtf8) import Yesod (ToContent (..), ToTypedContent (..), YesodPersist (runDB), getsYesod) import Yesod.Core.Types (JSONResponse (..)) +import System.FilePath (()) +import Data.ByteString (readFile) data InfoRes = InfoRes { name :: !Text , categories :: ![Text] + , icon :: !Text -- base64 } deriving (Show, Generic) instance ToJSON InfoRes @@ -26,10 +29,14 @@ instance ToTypedContent InfoRes where getInfoR :: Handler (JSONResponse InfoRes) getInfoR = do name <- getsYesod $ marketplaceName . appSettings + iconFile <- getsYesod $ ( "icon") . iconPath . appSettings + icon' <- liftIO $ readFile iconFile + let icon = decodeUtf8 icon' + allCategories <- runDB $ select $ do cats <- from $ table @Category orderBy [asc (cats ^. CategoryPriority)] pure cats tickleMAU - pure $ JSONResponse $ InfoRes name $ categoryName . entityVal <$> allCategories + pure $ JSONResponse $ InfoRes name (categoryName . entityVal <$> allCategories) icon diff --git a/src/Settings.hs b/src/Settings.hs index bca3e71..a553d97 100644 --- a/src/Settings.hs +++ b/src/Settings.hs @@ -62,29 +62,30 @@ import Orphans.Emver ( ) type AppPort = Word16 data AppSettings = AppSettings { appDatabaseConf :: !PostgresConf - , appHost :: !HostPreference - -- ^ Host/interface the server should bind to. - , appPort :: !AppPort - -- ^ Port to listen on - , appIpFromHeader :: !Bool - -- ^ Get the IP address from the header when logging. Useful when sitting - -- behind a reverse proxy. , appDetailedRequestLogging :: !Bool -- ^ Use detailed request logging system + , appHost :: !HostPreference + -- ^ Host/interface the server should bind to. + , appIpFromHeader :: !Bool + -- ^ Get the IP address from the header when logging. Useful when sitting + , appPort :: !AppPort + -- ^ Port to listen on + -- behind a reverse proxy. , appShouldLogAll :: !Bool -- ^ Should all log messages be displayed? - , resourcesDir :: !FilePath - , sslPath :: !FilePath - , sslAuto :: !Bool - , registryHostname :: !Text - , registryVersion :: !Version - , sslKeyLocation :: !FilePath - , sslCsrLocation :: !FilePath - , sslCertLocation :: !FilePath - , torPort :: !AppPort - , staticBinDir :: !FilePath + , iconPath :: !FilePath , errorLogRoot :: !FilePath , marketplaceName :: !Text + , registryHostname :: !Text + , registryVersion :: !Version + , resourcesDir :: !FilePath + , sslAuto :: !Bool + , sslCertLocation :: !FilePath + , sslCsrLocation :: !FilePath + , sslKeyLocation :: !FilePath + , sslPath :: !FilePath + , staticBinDir :: !FilePath + , torPort :: !AppPort } instance Has PkgRepo AppSettings where extract = liftA2 PkgRepo (( "apps") . resourcesDir) staticBinDir @@ -101,26 +102,26 @@ instance Has EosRepo AppSettings where instance FromJSON AppSettings where parseJSON = withObject "AppSettings" $ \o -> do appDatabaseConf <- o .: "database" - appHost <- fromString <$> o .: "host" - appPort <- o .: "port" - appIpFromHeader <- o .: "ip-from-header" appDetailedRequestLogging <- o .:? "detailed-logging" .!= True + appHost <- fromString <$> o .: "host" + appIpFromHeader <- o .: "ip-from-header" + appPort <- o .: "port" appShouldLogAll <- o .:? "should-log-all" .!= False - resourcesDir <- o .: "resources-path" - sslPath <- o .: "ssl-path" - sslAuto <- o .: "ssl-auto" - registryHostname <- o .: "registry-hostname" - torPort <- o .: "tor-port" - staticBinDir <- o .: "static-bin-dir" errorLogRoot <- o .: "error-log-root" + iconPath <- o .: "icon-path" + marketplaceName <- o .: "marketplace-name" + registryHostname <- o .: "registry-hostname" + resourcesDir <- o .: "resources-path" + sslAuto <- o .: "ssl-auto" + sslPath <- o .: "ssl-path" + staticBinDir <- o .: "static-bin-dir" + torPort <- o .: "tor-port" let sslKeyLocation = sslPath "key.pem" let sslCsrLocation = sslPath "certificate.csr" let sslCertLocation = sslPath "certificate.pem" let registryVersion = fromJust . parseMaybe parseJSON . String . toS . showVersion $ version - marketplaceName <- o .: "marketplace-name" - return AppSettings { .. } -- | Raw bytes at compile time of @config/settings.yml@