add marketplace icon to info response

This commit is contained in:
Lucy Cifferello
2022-11-10 11:40:13 -07:00
parent d83ea36d93
commit 18329bd021
3 changed files with 41 additions and 32 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -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@