fix version parsing and add temp logs

This commit is contained in:
Lucy Cifferello
2021-07-02 18:20:05 -04:00
committed by Keagan McClelland
parent 82dcfbd5f5
commit d64e9b71c6
2 changed files with 8 additions and 8 deletions

View File

@@ -19,7 +19,6 @@ import Yesod.Persist.Core
import Database.Marketplace import Database.Marketplace
import Data.List import Data.List
import Lib.Types.Category import Lib.Types.Category
import Text.Read hiding (readMaybe)
import Lib.Types.AppIndex import Lib.Types.AppIndex
import qualified Data.HashMap.Strict as HM import qualified Data.HashMap.Strict as HM
import Data.HashMap.Strict (HashMap) import Data.HashMap.Strict (HashMap)
@@ -38,7 +37,6 @@ import qualified Data.Text as T
import Data.String.Interpolate.IsString import Data.String.Interpolate.IsString
import Util.Shared import Util.Shared
newtype CategoryRes = CategoryRes { newtype CategoryRes = CategoryRes {
categories :: [CategoryTitle] categories :: [CategoryTitle]
} deriving (Show, Generic) } deriving (Show, Generic)
@@ -177,19 +175,21 @@ getServiceR = do
(service, version) <- case lookup "id" getParameters of (service, version) <- case lookup "id" getParameters of
Nothing -> sendResponseStatus status404 ("id param should exist" :: Text) Nothing -> sendResponseStatus status404 ("id param should exist" :: Text)
Just appId' -> do Just appId' -> do
case lookup "version" getParameters of versionString <- T.filter (not . isSpace) . fromMaybe "*" <$> lookupGetParam "version"
case readMaybe versionString of
Nothing -> do Nothing -> do
sendResponseStatus status400 ("Invalid App Version Specification" :: Text)
-- default to latest - need to determine best available based on OS version? -- default to latest - need to determine best available based on OS version?
runDB $ fetchLatestApp appId' >>= errOnNothing status404 "service not found" -- runDB $ fetchLatestApp appId' >>= errOnNothing status404 "service not found"
Just c -> do Just v -> runDB $ fetchLatestAppAtVersion appId' v >>= errOnNothing status404 ("service at version " <> show v <> " not found")
let version' = Version $ read $ toS c $logInfo $ "*******************" <> show version
runDB $ fetchLatestAppAtVersion appId' version' >>= errOnNothing status404 ("service at version " <> show version' <> " not found")
(versions, mappedVersions) <- fetchAllAppVersions (entityKey service) (versions, mappedVersions) <- 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
let appId = sAppAppId $ entityVal service let appId = sAppAppId $ entityVal service
let appDir = (<> "/") . (</> show version) . (</> toS appId) $ appsDir let appDir = (<> "/") . (</> show version) . (</> toS appId) $ appsDir
let appExt = Extension (toS appId) :: Extension "s9pk" let appExt = Extension (toS appId) :: Extension "s9pk"
$logInfo $ "*******************" <> show appDir
manifest' <- handleS9ErrT $ getManifest appMgrDir appDir appExt manifest' <- handleS9ErrT $ getManifest appMgrDir appDir appExt
manifest <- case eitherDecode $ BS.fromStrict manifest' of manifest <- case eitherDecode $ BS.fromStrict manifest' of
Left e -> do Left e -> do

View File

@@ -52,7 +52,7 @@ import Data.Aeson
import Startlude (Hashable) import Startlude (Hashable)
-- | AppVersion is the core representation of the SemverQuad type. -- | 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 instance Show Version where
show (Version (x, y, z, q)) = show (Version (x, y, z, q)) =
let postfix = if q == 0 then "" else '.' : show q in show x <> "." <> show y <> "." <> show z <> postfix let postfix = if q == 0 then "" else '.' : show q in show x <> "." <> show y <> "." <> show z <> postfix