mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
0.2.5 initial commit
Makefile incomplete
This commit is contained in:
25
agent/src/Orphans/Digest.hs
Normal file
25
agent/src/Orphans/Digest.hs
Normal file
@@ -0,0 +1,25 @@
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
module Orphans.Digest where
|
||||
|
||||
import Startlude
|
||||
|
||||
import Crypto.Hash
|
||||
import Data.ByteArray
|
||||
import Data.ByteArray.Encoding
|
||||
import Data.String.Interpolate.IsString
|
||||
import Database.Persist.Sql
|
||||
import Web.HttpApiData
|
||||
|
||||
instance HashAlgorithm a => PersistField (Digest a) where
|
||||
toPersistValue = PersistByteString . convert
|
||||
fromPersistValue (PersistByteString bs) =
|
||||
note [i|Invalid Digest: #{decodeUtf8 $ convertToBase Base16 bs}|] . digestFromByteString $ bs
|
||||
fromPersistValue other = Left $ "Invalid Digest: " <> show other
|
||||
|
||||
instance HashAlgorithm a => PersistFieldSql (Digest a) where
|
||||
sqlType _ = SqlBlob
|
||||
|
||||
instance HashAlgorithm a => ToHttpApiData (Digest a) where
|
||||
toUrlPiece = decodeUtf8 . convertToBase Base16
|
||||
18
agent/src/Orphans/UUID.hs
Normal file
18
agent/src/Orphans/UUID.hs
Normal file
@@ -0,0 +1,18 @@
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
module Orphans.UUID where
|
||||
|
||||
import Startlude
|
||||
|
||||
import Data.UUID
|
||||
import Database.Persist.Sql
|
||||
import Yesod.Core
|
||||
|
||||
instance PathPiece UUID where
|
||||
toPathPiece = show
|
||||
fromPathPiece = readMaybe
|
||||
instance PersistField UUID where
|
||||
toPersistValue = PersistText . show
|
||||
fromPersistValue (PersistText t) = note "Invalid UUID" $ readMaybe t
|
||||
fromPersistValue other = Left $ "Invalid UUID: " <> show other
|
||||
instance PersistFieldSql UUID where
|
||||
sqlType _ = SqlString
|
||||
Reference in New Issue
Block a user