fix urls for static files

This commit is contained in:
Lucy Cifferello
2021-08-24 09:04:05 -06:00
committed by Keagan McClelland
parent aa88306ee1
commit 723602e6f7
7 changed files with 69 additions and 67 deletions

View File

@@ -2,11 +2,13 @@
!/package/#S9PK AppR GET -- get most recent appId at appversion spec, defaults to >=0.0.0 -- ?spec={semver-spec} !/package/#S9PK AppR GET -- get most recent appId at appversion spec, defaults to >=0.0.0 -- ?spec={semver-spec}
/package/data CategoriesR GET -- get all marketplace categories /package/data CategoriesR GET -- get all marketplace categories
/package/index PackageListR GET -- filter marketplace services by various query params /package/index PackageListR GET -- filter marketplace services by various query params
/eos/latest EosR GET -- get eos information /eos/latest EosR GET -- get eos information
/latest-version VersionLatestR GET -- get latest version of apps in query param id /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} /package/manifest/#AppIdentifier AppManifestR GET -- get app manifest from appmgr -- ?version={semver-spec}
/marketplace/package/release-notes ReleaseNotesR 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> /package/icon/#AppIdentifier IconsR GET -- get icons - can specify version with ?spec=<emver>
/package/license/#AppIdentifier LicenseR GET -- get icons - can specify version with ?spec=<emver>
/package/instructions/#AppIdentifier InstructionsR GET -- get icons - can specify version with ?spec=<emver>
-- TODO confirm needed -- TODO confirm needed
/package/config/#AppIdentifier AppConfigR GET -- get app config from appmgr -- ?spec={semver-spec} /package/config/#AppIdentifier AppConfigR GET -- get app config from appmgr -- ?spec={semver-spec}

View File

@@ -75,7 +75,7 @@ getAppManifestR :: AppIdentifier -> Handler TypedContent
getAppManifestR appId = do getAppManifestR appId = do
(appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings (appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings
av <- getVersionFromQuery appsDir appExt >>= \case av <- getVersionFromQuery appsDir appExt >>= \case
Nothing -> sendResponseStatus status400 ("Specified App Version Not Found" :: Text) Nothing -> sendResponseStatus status404 ("Specified App Version Not Found" :: Text)
Just v -> pure v Just v -> pure v
let appDir = (<> "/") . (</> show av) . (</> toS appId) $ appsDir let appDir = (<> "/") . (</> show av) . (</> toS appId) $ appsDir
manifest <- handleS9ErrT $ getManifest appMgrDir appDir appExt manifest <- handleS9ErrT $ getManifest appMgrDir appDir appExt
@@ -89,7 +89,7 @@ getAppConfigR appId = do
let appsDir = (</> "apps") . resourcesDir $ appSettings let appsDir = (</> "apps") . resourcesDir $ appSettings
let appMgrDir = staticBinDir appSettings let appMgrDir = staticBinDir appSettings
av <- getVersionFromQuery appsDir appExt >>= \case av <- getVersionFromQuery appsDir appExt >>= \case
Nothing -> sendResponseStatus status400 ("Specified App Version Not Found" :: Text) Nothing -> sendResponseStatus status404 ("Specified App Version Not Found" :: Text)
Just v -> pure v Just v -> pure v
let appDir = (<> "/") . (</> show av) . (</> toS appId) $ appsDir let appDir = (<> "/") . (</> show av) . (</> toS appId) $ appsDir
config <- handleS9ErrT $ getConfig appMgrDir appDir appExt config <- handleS9ErrT $ getConfig appMgrDir appDir appExt

View File

@@ -1,6 +1,7 @@
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeApplications #-}
{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
module Handler.Icons where module Handler.Icons where
@@ -18,44 +19,53 @@ import System.FilePath ((</>))
import Util.Shared import Util.Shared
import Lib.External.AppMgr import Lib.External.AppMgr
import Lib.Error import Lib.Error
import Data.Conduit.Process
import Conduit
import qualified Data.ByteString.Lazy as BS import qualified Data.ByteString.Lazy as BS
import Network.HTTP.Types
import Lib.Types.AppIndex
getIconsR :: Extension "png" -> Handler TypedContent getIconsR :: AppIdentifier -> Handler TypedContent
getIconsR ext = do getIconsR appId = do
(appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings (appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings
$logInfo $ show ext
spec <- getVersionFromQuery appsDir ext >>= \case spec <- getVersionFromQuery appsDir ext >>= \case
Nothing -> notFound Nothing -> sendResponseStatus status404 ("Specified App Version Not Found" :: Text)
Just v -> pure v Just v -> pure v
servicePath <- liftIO $ getVersionedFileFromDir (appsDir </> show spec) ext spec servicePath <- liftIO $ getVersionedFileFromDir appsDir ext spec
case servicePath of case servicePath of
Nothing -> notFound Nothing -> notFound
Just p -> do Just p -> do
icon <- handleS9ErrT $ getIcon appMgrDir p ext -- (_, Just hout, _, _) <- liftIO (createProcess $ iconBs { std_out = CreatePipe })
respondSource typePlain $ CB.sourceLazy (BS.fromStrict icon) .| awaitForever sendChunkBS -- respondSource typePlain (runConduit $ yieldMany () [iconBs])
-- respondSource typePlain $ sourceHandle hout .| awaitForever sendChunkBS
respondSource typePlain (sendChunkBS =<< handleS9ErrT (getIcon appMgrDir p ext))
where ext = Extension (toS appId) :: Extension "s9pk"
-- getLicenseR :: Extension "" -> Handler TypedContent getLicenseR :: AppIdentifier -> Handler TypedContent
-- getLicenseR ext = do getLicenseR appId = do
-- AppSettings{..} <- appSettings <$> getYesod (appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings
-- mPng <- liftIO $ getUnversionedFileFromDir (resourcesDir </> "icons") ext $logInfo $ show ext
-- case mPng of spec <- getVersionFromQuery appsDir ext >>= \case
-- Nothing -> notFound Nothing -> sendResponseStatus status404 ("Specified App Version Not Found" :: Text)
-- Just pngPath -> do Just v -> pure v
-- putStrLn @Text $ show pngPath servicePath <- liftIO $ getVersionedFileFromDir appsDir ext spec
-- exists <- liftIO $ doesFileExist pngPath case servicePath of
-- if exists Nothing -> notFound
-- then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS Just p -> do
-- else notFound respondSource typePlain (sendChunkBS =<< handleS9ErrT (getLicense appMgrDir p ext))
where ext = Extension (toS appId) :: Extension "s9pk"
-- getMarkdownR :: Extension "md" -> Handler TypedContent getInstructionsR :: AppIdentifier -> Handler TypedContent
-- getMarkdownR ext = do getInstructionsR appId = do
-- -- @TODO switch to getting from service directory (appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings
-- AppSettings{..} <- appSettings <$> getYesod $logInfo $ show ext
-- mPng <- liftIO $ getUnversionedFileFromDir (resourcesDir </> "icons") ext spec <- getVersionFromQuery appsDir ext >>= \case
-- case mPng of Nothing -> sendResponseStatus status404 ("Specified App Version Not Found" :: Text)
-- Nothing -> notFound Just v -> pure v
-- Just pngPath -> do servicePath <- liftIO $ getVersionedFileFromDir appsDir ext spec
-- putStrLn @Text $ show pngPath case servicePath of
-- exists <- liftIO $ doesFileExist pngPath Nothing -> notFound
-- if exists Just p -> do
-- then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS respondSource typePlain (sendChunkBS =<< handleS9ErrT (getInstructions appMgrDir p ext))
-- else notFound where ext = Extension (toS appId) :: Extension "s9pk"

View File

@@ -46,11 +46,11 @@ instance ToContent CategoryRes where
instance ToTypedContent CategoryRes where instance ToTypedContent CategoryRes where
toTypedContent = toTypedContent . toJSON toTypedContent = toTypedContent . toJSON
data ServiceRes = ServiceRes data ServiceRes = ServiceRes
{ serviceResIcon :: Text { serviceResIcon :: URL
, serviceResManifest :: Maybe Data.Aeson.Value -- ServiceManifest , serviceResManifest :: Maybe Data.Aeson.Value -- ServiceManifest
, serviceResCategories :: [CategoryTitle] , serviceResCategories :: [CategoryTitle]
, serviceResInstructions :: Text , serviceResInstructions :: URL
, serviceResLicense :: Text , serviceResLicense :: URL
, serviceResVersions :: [Version] , serviceResVersions :: [Version]
, serviceResDependencyInfo :: HM.HashMap AppIdentifier DependencyInfo , serviceResDependencyInfo :: HM.HashMap AppIdentifier DependencyInfo
} deriving (Generic) } deriving (Generic)
@@ -296,7 +296,7 @@ getServiceR = do
getServiceDetails :: Maybe (Entity SVersion) -> Entity SApp -> HandlerFor RegistryCtx ServiceRes getServiceDetails :: Maybe (Entity SVersion) -> Entity SApp -> HandlerFor RegistryCtx ServiceRes
getServiceDetails maybeVersion service = do getServiceDetails maybeVersion service = do
(versions, mappedVersions) <- fetchAllAppVersions (entityKey service) (versions, _) <- fetchAllAppVersions (entityKey service)
categories <- runDB $ fetchAppCategories (entityKey service) categories <- runDB $ fetchAppCategories (entityKey service)
(appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings (appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings
domain <- getsYesod $ registryHostname . appSettings domain <- getsYesod $ registryHostname . appSettings
@@ -315,37 +315,28 @@ getServiceDetails maybeVersion service = do
$logError (show e) $logError (show e)
sendResponseStatus status500 ("Internal Server Error" :: Text) sendResponseStatus status500 ("Internal Server Error" :: Text)
Right a -> pure a Right a -> pure a
d <- traverse (mapDependencyMetadata appsDir appMgrDir domain) (HM.toList $ serviceManifestDependencies manifest) d <- traverse (mapDependencyMetadata appsDir domain) (HM.toList $ serviceManifestDependencies manifest)
-- @TODO uncomment when sdk icon working
-- icon <- decodeIcon appMgrDir appDir appExt
let icon = [i|https://#{domain}/icons/#{appId}.png|]
instructions <- decodeInstructions appMgrDir appDir appExt
license <- decodeLicense appMgrDir appDir appExt
pure $ ServiceRes pure $ ServiceRes
{ serviceResIcon = icon { serviceResIcon = [i|https://#{domain}/package/icon/#{appId}|]
, serviceResManifest = decode $ BS.fromStrict manifest' -- pass through raw JSON Value , serviceResManifest = decode $ BS.fromStrict manifest' -- pass through raw JSON Value
, serviceResCategories = serviceCategoryCategoryName . entityVal <$> categories , serviceResCategories = serviceCategoryCategoryName . entityVal <$> categories
, serviceResInstructions = instructions , serviceResInstructions = [i|https://#{domain}/package/license/#{appId}|]
, serviceResLicense = license , serviceResLicense = [i|https://#{domain}/package/instructions/#{appId}|]
, serviceResVersions = versionInfoVersion <$> versions , serviceResVersions = versionInfoVersion <$> versions
, serviceResDependencyInfo = HM.fromList d , serviceResDependencyInfo = HM.fromList d
} }
type URL = Text type URL = Text
mapDependencyMetadata :: (MonadIO m, MonadHandler m) => FilePath -> FilePath -> Text -> (AppIdentifier, ServiceDependencyInfo) -> m (AppIdentifier, DependencyInfo) mapDependencyMetadata :: (MonadIO m, MonadHandler m) => FilePath -> Text -> (AppIdentifier, ServiceDependencyInfo) -> m (AppIdentifier, DependencyInfo)
mapDependencyMetadata appsDir appmgrPath domain (appId, depInfo) = do mapDependencyMetadata appsDir domain (appId, depInfo) = do
let ext = (Extension (toS appId) :: Extension "s9pk") let ext = (Extension (toS appId) :: Extension "s9pk")
-- get best version from VersionRange of dependency -- get best version from VersionRange of dependency
version <- getBestVersion appsDir ext (serviceDependencyInfoVersion depInfo) >>= \case version <- getBestVersion appsDir ext (serviceDependencyInfoVersion depInfo) >>= \case
Nothing -> sendResponseStatus status404 ("best version not found for dependent package " <> appId :: Text) Nothing -> sendResponseStatus status404 ("best version not found for dependent package " <> appId :: Text)
Just v -> pure v Just v -> pure v
let depPath = appsDir </> toS appId </> show version
-- @TODO uncomment when sdk icon working
-- icon <- decodeIcon appmgrPath depPath ext
let icon = [i|https://#{domain}/icons/#{appId}.png|]
pure (appId, DependencyInfo pure (appId, DependencyInfo
{ dependencyInfoTitle = appId { dependencyInfoTitle = appId
, dependencyInfoIcon = icon , dependencyInfoIcon = [i|https://#{domain}/package/icon/#{appId}?spec==#{version}|]
}) })
decodeIcon :: (MonadHandler m, KnownSymbol a) => FilePath -> FilePath -> Extension a -> m URL decodeIcon :: (MonadHandler m, KnownSymbol a) => FilePath -> FilePath -> Extension a -> m URL
@@ -430,12 +421,9 @@ mapEntityToStoreApp serviceEntity = do
, storeAppTimestamp = Just (sAppCreatedAt service) -- case on if updatedAt? or always use updated time? was file timestamp , storeAppTimestamp = Just (sAppCreatedAt service) -- case on if updatedAt? or always use updated time? was file timestamp
} }
mapEntityToServiceAvailable :: (MonadIO m, MonadHandler m) => FilePath -> FilePath -> Text -> Entity SApp -> ReaderT SqlBackend m ServiceAvailable mapEntityToServiceAvailable :: (MonadIO m, MonadHandler m) => Text -> Entity SApp -> ReaderT SqlBackend m ServiceAvailable
mapEntityToServiceAvailable appMgrDir appsDir domain service = do mapEntityToServiceAvailable domain service = do
-- @TODO uncomment and replace icon when portable embassy-sdk live
-- icon <- decodeIcon appMgrDir appsDir (Extension "png")
let appId = sAppAppId $ entityVal service let appId = sAppAppId $ entityVal service
let icon = [i|https://#{domain}/icons/#{appId}.png|]
(_, v) <- fetchLatestApp appId >>= errOnNothing status404 "service not found" (_, v) <- fetchLatestApp appId >>= errOnNothing status404 "service not found"
let appVersion = sVersionNumber (entityVal v) let appVersion = sVersionNumber (entityVal v)
pure $ ServiceAvailable pure $ ServiceAvailable
@@ -443,7 +431,7 @@ mapEntityToServiceAvailable appMgrDir appsDir domain service = do
, serviceAvailableTitle = sAppTitle $ entityVal service , serviceAvailableTitle = sAppTitle $ entityVal service
, serviceAvailableDescShort = sAppDescShort $ entityVal service , serviceAvailableDescShort = sAppDescShort $ entityVal service
, serviceAvailableVersion = appVersion , serviceAvailableVersion = appVersion
, serviceAvailableIcon = icon , serviceAvailableIcon = [i|https://#{domain}/package/icon/#{appId}?spec==#{appVersion}|]
} }
-- >>> encode hm -- >>> encode hm

View File

@@ -58,7 +58,7 @@ getManifest appmgrPath appPath e@(Extension appId) = do
getIcon :: (MonadIO m, KnownSymbol a) => FilePath -> FilePath -> Extension a -> S9ErrT m ByteString getIcon :: (MonadIO m, KnownSymbol a) => FilePath -> FilePath -> Extension a -> S9ErrT m ByteString
getIcon appmgrPath appPath e@(Extension icon) = do getIcon appmgrPath appPath e@(Extension icon) = do
(ec, bs) <- readProcessInheritStderr (appmgrPath <> "embassy-sdk") ["inspect", "icon", appPath <> show e] "" (ec, bs) <- readProcessInheritStderr (appmgrPath <> "embassy-sdk") ["inspect", "icon", appPath] ""
case ec of case ec of
ExitSuccess -> pure bs ExitSuccess -> pure bs
ExitFailure n -> throwE $ AppMgrE [i|embassy-sdk inspect icon #{icon}|] n ExitFailure n -> throwE $ AppMgrE [i|embassy-sdk inspect icon #{icon}|] n
@@ -72,14 +72,14 @@ getPackageHash appmgrPath appPath e@(Extension appId) = do
getInstructions :: (MonadIO m, KnownSymbol a) => FilePath -> FilePath -> Extension a -> S9ErrT m ByteString getInstructions :: (MonadIO m, KnownSymbol a) => FilePath -> FilePath -> Extension a -> S9ErrT m ByteString
getInstructions appmgrPath appPath e@(Extension appId) = do getInstructions appmgrPath appPath e@(Extension appId) = do
(ec, bs) <- readProcessInheritStderr (appmgrPath <> "embassy-sdk") ["inspect", "instructions", appPath <> show e] "" (ec, bs) <- readProcessInheritStderr (appmgrPath <> "embassy-sdk") ["inspect", "instructions", appPath] ""
case ec of case ec of
ExitSuccess -> pure bs ExitSuccess -> pure bs
ExitFailure n -> throwE $ AppMgrE [i|embassy-sdk inspect instructions #{appId}|] n ExitFailure n -> throwE $ AppMgrE [i|embassy-sdk inspect instructions #{appId}|] n
getLicense :: (MonadIO m, KnownSymbol a) => FilePath -> FilePath -> Extension a -> S9ErrT m ByteString getLicense :: (MonadIO m, KnownSymbol a) => FilePath -> FilePath -> Extension a -> S9ErrT m ByteString
getLicense appmgrPath appPath e@(Extension appId) = do getLicense appmgrPath appPath e@(Extension appId) = do
(ec, bs) <- readProcessInheritStderr (appmgrPath <> "embassy-sdk") ["inspect", "license", appPath <> show e] "" (ec, bs) <- readProcessInheritStderr (appmgrPath <> "embassy-sdk") ["inspect", "license", appPath] ""
case ec of case ec of
ExitSuccess -> pure bs ExitSuccess -> pure bs
ExitFailure n -> throwE $ AppMgrE [i|embassy-sdk inspect license #{appId}|] n ExitFailure n -> throwE $ AppMgrE [i|embassy-sdk inspect license #{appId}|] n

View File

@@ -2,6 +2,7 @@
{-# LANGUAGE KindSignatures #-} {-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TemplateHaskell #-}
module Lib.Registry where module Lib.Registry where

View File

@@ -29,6 +29,7 @@ getBestVersion rootDir ext spec = do
appVersions <- liftIO $ getAvailableAppVersions rootDir ext appVersions <- liftIO $ getAvailableAppVersions rootDir ext
let satisfactory = filter ((<|| spec) . fst . unRegisteredAppVersion) appVersions let satisfactory = filter ((<|| spec) . fst . unRegisteredAppVersion) appVersions
let best = getMax <$> foldMap (Just . Max . fst . unRegisteredAppVersion) satisfactory let best = getMax <$> foldMap (Just . Max . fst . unRegisteredAppVersion) satisfactory
$logInfo $ show best
pure best pure best
addPackageHeader :: (MonadHandler m, KnownSymbol a) => FilePath -> FilePath -> Extension a -> m () addPackageHeader :: (MonadHandler m, KnownSymbol a) => FilePath -> FilePath -> Extension a -> m ()