2023-12-23 22:15:10 +01:00
|
|
|
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
|
|
|
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
|
|
obtain one at https://mozilla.org/MPL/2.0/. -}
|
|
|
|
|
2024-11-15 17:03:23 +01:00
|
|
|
-- | Contains data describing packages, methods to update them and to request
|
|
|
|
-- information about them.
|
2023-08-28 21:05:47 +02:00
|
|
|
module SlackBuilder.Package
|
2024-11-25 17:08:28 +01:00
|
|
|
( DataBaseEntry(..)
|
|
|
|
, Download(..)
|
2023-09-03 10:26:43 +02:00
|
|
|
, DownloadTemplate(..)
|
2024-02-17 14:15:01 +01:00
|
|
|
, PackageDescription(..)
|
|
|
|
, PackageUpdateData(..)
|
2023-08-28 21:05:47 +02:00
|
|
|
, Updater(..)
|
2023-09-03 10:26:43 +02:00
|
|
|
, renderDownloadWithVersion
|
2024-11-15 17:03:23 +01:00
|
|
|
, renderTextWithVersion
|
2023-08-28 21:05:47 +02:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Data.Text (Text)
|
|
|
|
import qualified Data.Text as Text
|
|
|
|
import Text.URI (URI(..))
|
|
|
|
import qualified Text.URI as URI
|
|
|
|
import Crypto.Hash (Digest, MD5)
|
|
|
|
import SlackBuilder.Trans
|
2023-09-03 10:26:43 +02:00
|
|
|
import Control.Monad.Catch (MonadThrow)
|
2023-11-01 17:05:16 +01:00
|
|
|
import Data.Map (Map)
|
2023-08-28 21:05:47 +02:00
|
|
|
|
2023-10-05 19:24:42 +02:00
|
|
|
-- | Contains information how a package can be updated.
|
2024-02-17 14:15:01 +01:00
|
|
|
data PackageDescription = PackageDescription
|
2023-10-05 19:24:42 +02:00
|
|
|
{ latest :: Updater
|
2023-11-01 17:05:16 +01:00
|
|
|
, downloaders :: Map Text Updater
|
2023-10-05 19:24:42 +02:00
|
|
|
, name :: Text
|
|
|
|
}
|
|
|
|
|
2024-02-17 14:15:01 +01:00
|
|
|
data PackageUpdateData = PackageUpdateData
|
|
|
|
{ description :: PackageDescription
|
|
|
|
, category :: Text
|
|
|
|
, version :: Text
|
|
|
|
}
|
|
|
|
|
2023-08-28 21:05:47 +02:00
|
|
|
-- | Download URI with the MD5 checksum of the target.
|
|
|
|
data Download = Download
|
|
|
|
{ download :: URI
|
|
|
|
, md5sum :: Digest MD5
|
|
|
|
} deriving (Eq, Show)
|
|
|
|
|
|
|
|
-- | List of URI components, including version placeholders.
|
2024-09-01 17:34:24 +02:00
|
|
|
newtype DownloadTemplate = DownloadTemplate
|
|
|
|
{ unDownloadTemplate :: Text
|
|
|
|
} deriving Eq
|
2023-08-28 21:05:47 +02:00
|
|
|
|
|
|
|
instance Show DownloadTemplate
|
|
|
|
where
|
2024-09-01 17:34:24 +02:00
|
|
|
show = Text.unpack . unDownloadTemplate
|
2023-08-28 21:05:47 +02:00
|
|
|
|
2023-09-21 23:51:02 +02:00
|
|
|
-- | Replaces placeholders in the URL template with the given version.
|
2023-09-03 10:26:43 +02:00
|
|
|
renderDownloadWithVersion :: MonadThrow m => DownloadTemplate -> Text -> m URI
|
2024-09-01 17:34:24 +02:00
|
|
|
renderDownloadWithVersion (DownloadTemplate template) version =
|
2024-11-15 17:03:23 +01:00
|
|
|
URI.mkURI $ renderTextWithVersion template version
|
|
|
|
|
|
|
|
-- | Replaces placeholders in the text with the given version.
|
|
|
|
renderTextWithVersion :: Text -> Text -> Text
|
|
|
|
renderTextWithVersion template version = Text.replace "{version}" version template
|
2023-09-03 10:26:43 +02:00
|
|
|
|
2023-08-28 21:05:47 +02:00
|
|
|
-- | Function used to get the latest version of a source.
|
2023-10-28 03:31:10 +02:00
|
|
|
data Updater = Updater
|
|
|
|
{ detectLatest :: SlackBuilderT (Maybe Text)
|
2024-01-19 09:57:58 +01:00
|
|
|
, is64 :: Bool
|
2023-11-01 17:05:16 +01:00
|
|
|
, getVersion :: Text -> Text -> SlackBuilderT Download
|
2023-10-28 03:31:10 +02:00
|
|
|
}
|
2024-11-25 17:08:28 +01:00
|
|
|
|
|
|
|
data DataBaseEntry = DataBaseEntry
|
|
|
|
{ name :: Text
|
|
|
|
, version :: Text
|
|
|
|
, arch :: Text
|
|
|
|
, build :: Text
|
|
|
|
} deriving Eq
|
|
|
|
|
|
|
|
instance Show DataBaseEntry
|
|
|
|
where
|
|
|
|
show DataBaseEntry{..} = Text.unpack
|
|
|
|
$ Text.intercalate "-" [name, version, arch, build]
|