mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-30 11:51:57 +00:00
initial commit
This commit is contained in:
81
src/Handler/Types/Apps.hs
Normal file
81
src/Handler/Types/Apps.hs
Normal file
@@ -0,0 +1,81 @@
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
module Handler.Types.Apps where
|
||||
|
||||
import Startlude
|
||||
|
||||
import Data.Aeson
|
||||
import Data.Time.ISO8601
|
||||
import Yesod.Core.Content
|
||||
|
||||
import Lib.Types.ServerApp
|
||||
|
||||
newtype AvailableAppsRes = AvailableAppsRes
|
||||
{ availableApps :: [(StoreApp, Maybe AppVersion)]
|
||||
} deriving (Eq, Show)
|
||||
instance ToJSON AvailableAppsRes where
|
||||
toJSON = toJSON . fmap toJSON' . availableApps
|
||||
where
|
||||
toJSON' (StoreApp{..}, version) = object
|
||||
[ "id" .= storeAppId
|
||||
, "title" .= storeAppTitle
|
||||
, "versionInstalled" .= version
|
||||
, "versionLatest" .= (storeAppVersionInfoVersion . extract) storeAppVersions
|
||||
, "iconURL" .= storeAppIconUrl
|
||||
, "descriptionShort" .= storeAppDescriptionShort
|
||||
]
|
||||
instance ToTypedContent AvailableAppsRes where
|
||||
toTypedContent = toTypedContent . toJSON
|
||||
instance ToContent AvailableAppsRes where
|
||||
toContent = toContent . toJSON
|
||||
|
||||
newtype AvailableAppFullRes = AvailableAppFullRes
|
||||
{ availableAppFull :: (StoreApp, Maybe AppVersion)
|
||||
} deriving (Eq, Show)
|
||||
instance ToJSON AvailableAppFullRes where
|
||||
toJSON = toJSON' . availableAppFull
|
||||
where
|
||||
toJSON' (StoreApp{..}, version) = object
|
||||
[ "id" .= storeAppId
|
||||
, "title" .= storeAppTitle
|
||||
, "versionInstalled" .= version
|
||||
, "versionLatest" .= (storeAppVersionInfoVersion . extract) storeAppVersions
|
||||
, "iconURL" .= storeAppIconUrl
|
||||
, "descriptionShort" .= storeAppDescriptionShort
|
||||
, "descriptionLong" .= storeAppDescriptionLong
|
||||
, "versions" .= storeAppVersions
|
||||
]
|
||||
instance ToContent AvailableAppFullRes where
|
||||
toContent = toContent . toJSON
|
||||
instance ToTypedContent AvailableAppFullRes where
|
||||
toTypedContent = toTypedContent . toJSON
|
||||
|
||||
newtype InstalledAppRes = InstalledAppRes
|
||||
{ installedApp :: (StoreApp, ServerApp, AppStatus, UTCTime)
|
||||
} deriving (Eq, Show)
|
||||
instance ToJSON InstalledAppRes where
|
||||
toJSON = toJSON' . installedApp
|
||||
where
|
||||
toJSON' (store, server, status, time) = object
|
||||
[ "id" .= storeAppId store
|
||||
, "title" .= storeAppTitle store
|
||||
, "versionLatest" .= (storeAppVersionInfoVersion . extract) (storeAppVersions store)
|
||||
, "versionInstalled" .= serverAppVersionInstalled server
|
||||
, "iconURL" .= storeAppIconUrl store
|
||||
, "torAddress" .= serverAppTorService server
|
||||
, "status" .= status
|
||||
, "statusAt" .= formatISO8601Javascript time
|
||||
]
|
||||
instance ToTypedContent InstalledAppRes where
|
||||
toTypedContent = toTypedContent . toJSON
|
||||
instance ToContent InstalledAppRes where
|
||||
toContent = toContent . toJSON
|
||||
|
||||
data InstallNewAppReq = InstallNewAppReq
|
||||
{ installNewAppId :: Text
|
||||
, installNewAppVersion :: Text
|
||||
} deriving (Eq, Show)
|
||||
instance FromJSON InstallNewAppReq where
|
||||
parseJSON = withObject "Install New App Request" $ \o -> do
|
||||
installNewAppId <- o .: "id"
|
||||
installNewAppVersion <- o .: "version"
|
||||
pure InstallNewAppReq{..}
|
||||
23
src/Handler/Types/Register.hs
Normal file
23
src/Handler/Types/Register.hs
Normal file
@@ -0,0 +1,23 @@
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
module Handler.Types.Register where
|
||||
|
||||
import Startlude
|
||||
|
||||
import Control.Monad.Fail
|
||||
import Data.Aeson
|
||||
import Data.ByteArray.Encoding
|
||||
import Data.ByteArray.Sized
|
||||
|
||||
data RegisterReq = RegisterReq
|
||||
{ registerProductKey :: Text
|
||||
, registerPubKey :: SizedByteArray 33 ByteString
|
||||
} deriving (Eq, Show)
|
||||
instance FromJSON RegisterReq where
|
||||
parseJSON = withObject "Register Request" $ \o -> do
|
||||
registerProductKey <- o .: "productKey"
|
||||
registerPubKey <- o .: "pubKey" >>= \t ->
|
||||
case sizedByteArray <=< hush . convertFromBase Base16 $ encodeUtf8 t of
|
||||
Nothing -> fail "Invalid Hex Encoded Public Key"
|
||||
Just x -> pure x
|
||||
pure RegisterReq{..}
|
||||
36
src/Handler/Types/Status.hs
Normal file
36
src/Handler/Types/Status.hs
Normal file
@@ -0,0 +1,36 @@
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
module Handler.Types.Status where
|
||||
|
||||
import Startlude
|
||||
|
||||
import Data.Aeson
|
||||
import Data.Text
|
||||
import Yesod.Core.Content
|
||||
|
||||
import Lib.Types.ServerApp
|
||||
|
||||
data ServerRes = ServerRes
|
||||
{ serverStatus :: AppStatus
|
||||
, serverVersion :: AppVersion
|
||||
, serverSpecs :: Value
|
||||
} deriving (Eq, Show)
|
||||
instance ToJSON ServerRes where
|
||||
toJSON ServerRes{..} = object
|
||||
[ "status" .= toUpper (show serverStatus)
|
||||
, "versionInstalled" .= serverVersion
|
||||
, "specs" .= serverSpecs
|
||||
, "versionLatest" .= serverVersion -- TODO: change this.
|
||||
]
|
||||
instance ToTypedContent ServerRes where
|
||||
toTypedContent = toTypedContent . toJSON
|
||||
instance ToContent ServerRes where
|
||||
toContent = toContent . toJSON
|
||||
|
||||
newtype AppVersionRes = AppVersionRes
|
||||
{ unAppVersionRes :: AppVersion } deriving (Eq, Show)
|
||||
instance ToJSON AppVersionRes where
|
||||
toJSON AppVersionRes{unAppVersionRes} = object ["version" .= unAppVersionRes]
|
||||
instance ToContent AppVersionRes where
|
||||
toContent = toContent . toJSON
|
||||
instance ToTypedContent AppVersionRes where
|
||||
toTypedContent = toTypedContent . toJSON
|
||||
Reference in New Issue
Block a user