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 a616925905
commit bde94383d0
2 changed files with 8 additions and 8 deletions

View File

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

View File

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