mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 10:21:51 +00:00
fix routes
This commit is contained in:
@@ -7,7 +7,7 @@ module Handler.Icons where
|
||||
import Startlude hiding (Handler)
|
||||
|
||||
import Data.Conduit
|
||||
import qualified Data.Conduit.Binary as CB
|
||||
import qualified Data.Conduit.Combinators as CB
|
||||
import System.Directory
|
||||
import Yesod.Core
|
||||
|
||||
@@ -15,44 +15,47 @@ import Foundation
|
||||
import Lib.Registry
|
||||
import Settings
|
||||
import System.FilePath ((</>))
|
||||
import Util.Shared
|
||||
import Lib.External.AppMgr
|
||||
import Lib.Error
|
||||
import qualified Data.ByteString.Lazy as BS
|
||||
|
||||
getIconsR :: Extension "png" -> Handler TypedContent
|
||||
getIconsR ext = do
|
||||
-- @TODO switch to getting from service directory
|
||||
AppSettings{..} <- appSettings <$> getYesod
|
||||
mPng <- liftIO $ getVersionedFileFromDir (resourcesDir </> "icons") ext
|
||||
case mPng of
|
||||
(appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings
|
||||
spec <- getVersionFromQuery appsDir ext >>= \case
|
||||
Nothing -> notFound
|
||||
Just v -> pure v
|
||||
servicePath <- liftIO $ getVersionedFileFromDir (appsDir </> show spec) ext spec
|
||||
case servicePath of
|
||||
Nothing -> notFound
|
||||
Just pngPath -> do
|
||||
putStrLn @Text $ show pngPath
|
||||
exists <- liftIO $ doesFileExist pngPath
|
||||
if exists
|
||||
then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS
|
||||
else notFound
|
||||
Just p -> do
|
||||
icon <- handleS9ErrT $ getIcon appMgrDir p ext
|
||||
respondSource typePlain $ CB.sourceLazy (BS.fromStrict icon) .| awaitForever sendChunkBS
|
||||
|
||||
getLicenseR :: Extension "" -> Handler TypedContent
|
||||
getLicenseR ext = do
|
||||
AppSettings{..} <- appSettings <$> getYesod
|
||||
mPng <- liftIO $ getUnversionedFileFromDir (resourcesDir </> "icons") ext
|
||||
case mPng of
|
||||
Nothing -> notFound
|
||||
Just pngPath -> do
|
||||
putStrLn @Text $ show pngPath
|
||||
exists <- liftIO $ doesFileExist pngPath
|
||||
if exists
|
||||
then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS
|
||||
else notFound
|
||||
-- getLicenseR :: Extension "" -> Handler TypedContent
|
||||
-- getLicenseR ext = do
|
||||
-- AppSettings{..} <- appSettings <$> getYesod
|
||||
-- mPng <- liftIO $ getUnversionedFileFromDir (resourcesDir </> "icons") ext
|
||||
-- case mPng of
|
||||
-- Nothing -> notFound
|
||||
-- Just pngPath -> do
|
||||
-- putStrLn @Text $ show pngPath
|
||||
-- exists <- liftIO $ doesFileExist pngPath
|
||||
-- if exists
|
||||
-- then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS
|
||||
-- else notFound
|
||||
|
||||
getMarkdownR :: Extension "md" -> Handler TypedContent
|
||||
getMarkdownR ext = do
|
||||
-- @TODO switch to getting from service directory
|
||||
AppSettings{..} <- appSettings <$> getYesod
|
||||
mPng <- liftIO $ getUnversionedFileFromDir (resourcesDir </> "icons") ext
|
||||
case mPng of
|
||||
Nothing -> notFound
|
||||
Just pngPath -> do
|
||||
putStrLn @Text $ show pngPath
|
||||
exists <- liftIO $ doesFileExist pngPath
|
||||
if exists
|
||||
then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS
|
||||
else notFound
|
||||
-- getMarkdownR :: Extension "md" -> Handler TypedContent
|
||||
-- getMarkdownR ext = do
|
||||
-- -- @TODO switch to getting from service directory
|
||||
-- AppSettings{..} <- appSettings <$> getYesod
|
||||
-- mPng <- liftIO $ getUnversionedFileFromDir (resourcesDir </> "icons") ext
|
||||
-- case mPng of
|
||||
-- Nothing -> notFound
|
||||
-- Just pngPath -> do
|
||||
-- putStrLn @Text $ show pngPath
|
||||
-- exists <- liftIO $ doesFileExist pngPath
|
||||
-- if exists
|
||||
-- then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS
|
||||
-- else notFound
|
||||
@@ -59,6 +59,10 @@ newtype ReleaseNotes = ReleaseNotes { unReleaseNotes :: HM.HashMap Version Text
|
||||
deriving (Eq, Show)
|
||||
instance ToJSON ReleaseNotes where
|
||||
toJSON ReleaseNotes { .. } = object [ t .= v | (k,v) <- HM.toList unReleaseNotes, let (String t) = toJSON k ]
|
||||
instance ToContent ReleaseNotes where
|
||||
toContent = toContent . toJSON
|
||||
instance ToTypedContent ReleaseNotes where
|
||||
toTypedContent = toTypedContent . toJSON
|
||||
instance ToJSON ServiceRes where
|
||||
toJSON ServiceRes {..} = object
|
||||
[ "icon" .= serviceResIcon
|
||||
|
||||
Reference in New Issue
Block a user