From d64e9b71c696e369ef248a81bdead61ef685f5d8 Mon Sep 17 00:00:00 2001 From: Lucy Cifferello <12953208+elvece@users.noreply.github.com> Date: Fri, 2 Jul 2021 18:20:05 -0400 Subject: [PATCH] fix version parsing and add temp logs --- src/Handler/Marketplace.hs | 14 +++++++------- src/Lib/Types/Emver.hs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Handler/Marketplace.hs b/src/Handler/Marketplace.hs index 286fe48..9424910 100644 --- a/src/Handler/Marketplace.hs +++ b/src/Handler/Marketplace.hs @@ -19,7 +19,6 @@ import Yesod.Persist.Core import Database.Marketplace import Data.List import Lib.Types.Category -import Text.Read hiding (readMaybe) import Lib.Types.AppIndex import qualified Data.HashMap.Strict as HM import Data.HashMap.Strict (HashMap) @@ -38,7 +37,6 @@ import qualified Data.Text as T import Data.String.Interpolate.IsString import Util.Shared - newtype CategoryRes = CategoryRes { categories :: [CategoryTitle] } deriving (Show, Generic) @@ -177,19 +175,21 @@ getServiceR = do (service, version) <- case lookup "id" getParameters of Nothing -> sendResponseStatus status404 ("id param should exist" :: Text) Just appId' -> do - case lookup "version" getParameters of + versionString <- T.filter (not . isSpace) . fromMaybe "*" <$> lookupGetParam "version" + case readMaybe versionString of Nothing -> do + sendResponseStatus status400 ("Invalid App Version Specification" :: Text) -- default to latest - need to determine best available based on OS version? - runDB $ fetchLatestApp appId' >>= errOnNothing status404 "service not found" - Just c -> do - let version' = Version $ read $ toS c - runDB $ fetchLatestAppAtVersion appId' version' >>= errOnNothing status404 ("service at version " <> show version' <> " not found") + -- runDB $ fetchLatestApp appId' >>= errOnNothing status404 "service not found" + Just v -> runDB $ fetchLatestAppAtVersion appId' v >>= errOnNothing status404 ("service at version " <> show v <> " not found") + $logInfo $ "*******************" <> show version (versions, mappedVersions) <- fetchAllAppVersions (entityKey service) categories <- runDB $ fetchAppCategories (entityKey service) (appsDir, appMgrDir) <- getsYesod $ (( "apps") . resourcesDir &&& staticBinDir) . appSettings let appId = sAppAppId $ entityVal service let appDir = (<> "/") . ( show version) . ( toS appId) $ appsDir let appExt = Extension (toS appId) :: Extension "s9pk" + $logInfo $ "*******************" <> show appDir manifest' <- handleS9ErrT $ getManifest appMgrDir appDir appExt manifest <- case eitherDecode $ BS.fromStrict manifest' of Left e -> do diff --git a/src/Lib/Types/Emver.hs b/src/Lib/Types/Emver.hs index 55843db..dea037c 100644 --- a/src/Lib/Types/Emver.hs +++ b/src/Lib/Types/Emver.hs @@ -52,7 +52,7 @@ import Data.Aeson import Startlude (Hashable) -- | AppVersion is the core representation of the SemverQuad type. -newtype Version = Version { unVersion :: (Word, Word, Word, Word) } deriving (Eq, Ord, ToJSONKey, Hashable) +newtype Version = Version { unVersion :: (Word, Word, Word, Word) } deriving (Eq, Ord, ToJSONKey, Hashable, Read) instance Show Version where show (Version (x, y, z, q)) = let postfix = if q == 0 then "" else '.' : show q in show x <> "." <> show y <> "." <> show z <> postfix