From 09e188e9d80daaf0e1abcb5147053023e38c5020 Mon Sep 17 00:00:00 2001 From: Lucy Cifferello <12953208+elvece@users.noreply.github.com> Date: Tue, 6 Jul 2021 11:25:14 -0400 Subject: [PATCH] rename apps endpoints to package and add header to addl endpoint --- config/routes | 4 ++-- src/Handler/Apps.hs | 4 ++++ src/Handler/Marketplace.hs | 2 +- src/Handler/Version.hs | 10 ++++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/config/routes b/config/routes index 0db7157..246fe50 100644 --- a/config/routes +++ b/config/routes @@ -3,11 +3,11 @@ /version VersionR GET -/apps/version/#Text VersionAppR GET -- get most recent appId version +/package/version/#Text VersionAppR GET -- get most recent appId version /sys/version/#Text VersionSysR GET -- get most recent sys app version /icons/#PNG IconsR GET -- get icons -!/apps/#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} /sys/status SystemStatusR GET -- get system update status and version !/sys/#SYS_EXTENSIONLESS SysR GET -- get most recent sys app -- ?spec={semver-spec} diff --git a/src/Handler/Apps.hs b/src/Handler/Apps.hs index eab5950..32a9949 100644 --- a/src/Handler/Apps.hs +++ b/src/Handler/Apps.hs @@ -112,12 +112,16 @@ getApp rootDir ext@(Extension appId) = do putStrLn $ "valid appversion for " <> (show ext :: String) <> ": " <> show appVersions let satisfactory = filter ((<|| spec) . fst . unRegisteredAppVersion) appVersions let best = fst . getMaxVersion <$> foldMap (Just . MaxVersion . (, fst . unRegisteredAppVersion)) satisfactory + (appsDir, appMgrDir) <- getsYesod $ (( "apps") . resourcesDir &&& staticBinDir) . appSettings case best of Nothing -> notFound Just (RegisteredAppVersion (appVersion, filePath)) -> do exists' <- liftIO $ doesFileExist filePath >>= \case True -> pure Existent False -> pure NonExistent + let appDir = (<> "/") . ( show appVersion) . ( toS appId) $ appsDir + let appExt = Extension (toS appId) :: Extension "s9pk" + addPackageHeader appMgrDir appDir appExt determineEvent exists' (extension ext) filePath appVersion where determineEvent :: FileExistence -> String -> FilePath -> Version -> HandlerFor RegistryCtx TypedContent diff --git a/src/Handler/Marketplace.hs b/src/Handler/Marketplace.hs index db19242..ba8efce 100644 --- a/src/Handler/Marketplace.hs +++ b/src/Handler/Marketplace.hs @@ -213,7 +213,7 @@ getServiceR = do -- @TODO uncomment when sdk icon working -- icon <- decodeIcon appMgrDir depPath appExt let icon = [i|https://#{domain}/icons/#{appId}.png|] - -- addPackageHeader appMgrDir appDir appExt + addPackageHeader appMgrDir appDir appExt pure $ ServiceRes { serviceResIcon = icon , serviceResManifest = manifest -- TypedContent "application/json" (toContent manifest) diff --git a/src/Handler/Version.hs b/src/Handler/Version.hs index 774bbc9..1077aae 100644 --- a/src/Handler/Version.hs +++ b/src/Handler/Version.hs @@ -27,8 +27,14 @@ getVersionR = do getVersionAppR :: Text -> Handler (Maybe AppVersionRes) getVersionAppR appId = do - appsDir <- ( "apps") . resourcesDir . appSettings <$> getYesod - getVersionWSpec appsDir appExt + (appsDir, appMgrDir) <- getsYesod $ (( "apps") . resourcesDir &&& staticBinDir) . appSettings + res <- getVersionWSpec appsDir appExt + case res of + Nothing -> pure res + Just r -> do + let appDir = (<> "/") . ( (show $ appVersionVersion r)) . ( toS appId) $ appsDir + addPackageHeader appMgrDir appDir appExt + pure res where appExt = Extension (toS appId) :: Extension "s9pk" -- @TODO update to using db record