|
|
|
@ -96,11 +96,30 @@ instance ToNode (Catalog 1) where
|
|
|
|
|
|
|
|
|
|
class Monad m => VersionedCatalog m (v :: Nat) where
|
|
|
|
|
getChannels :: SafeUser -> m (Catalog v)
|
|
|
|
|
getBooks :: Channel.ChannelID -> SafeUser -> m (Catalog v)
|
|
|
|
|
|
|
|
|
|
instance VersionedCatalog AppM 1 where
|
|
|
|
|
getChannels SafeUser{username} = do
|
|
|
|
|
getChannels = getChannelsV1
|
|
|
|
|
getBooks = getBooksV1
|
|
|
|
|
|
|
|
|
|
relUrl :: Text -> Rel
|
|
|
|
|
relUrl x = Rel ("/api/current/" <> x)
|
|
|
|
|
|
|
|
|
|
getBooksV1 :: Channel.ChannelID -> SafeUser -> AppM (Catalog 1)
|
|
|
|
|
getBooksV1 identifier SafeUser{} = do
|
|
|
|
|
updated <- liftIO getCurrentTime
|
|
|
|
|
let self = Rel ("/api/current/" <> selfUrl)
|
|
|
|
|
let self = relUrl selfUrl
|
|
|
|
|
start = relUrl startUrl
|
|
|
|
|
selfUrl = pack . uriPath . linkURI $ safeLink (Proxy @(BaseAPI 1)) (Proxy @(ChannelCatalog 1)) identifier
|
|
|
|
|
startUrl = pack . uriPath . linkURI $ safeLink (Proxy @(BaseAPI 1)) (Proxy @(RootCatalog 1))
|
|
|
|
|
entries = mempty
|
|
|
|
|
pagination = Pagination Nothing Nothing
|
|
|
|
|
pure CatalogV1{..}
|
|
|
|
|
|
|
|
|
|
getChannelsV1 :: SafeUser -> AppM (Catalog 1)
|
|
|
|
|
getChannelsV1 SafeUser{username} = do
|
|
|
|
|
updated <- liftIO getCurrentTime
|
|
|
|
|
let self = relUrl selfUrl
|
|
|
|
|
-- I'm not sure if this safe link approach is really useable with this
|
|
|
|
|
-- api hierarchy since I can't access the topmost api from here. Also
|
|
|
|
|
-- authentication would bring a little bit of extra effort as well
|
|
|
|
@ -113,13 +132,15 @@ instance VersionedCatalog AppM 1 where
|
|
|
|
|
fromChannel :: UTCTime -> Channel.Channel -> Entry 1
|
|
|
|
|
fromChannel updated Channel.Channel{..} =
|
|
|
|
|
let url = pack . uriPath . linkURI $ safeLink (Proxy @(BaseAPI 1)) (Proxy @(ChannelCatalog 1)) identifier
|
|
|
|
|
self = Rel ("/api/current/" <> url)
|
|
|
|
|
self = relUrl url
|
|
|
|
|
in EntryV1 channel channel updated channel (Left $ SubSection self)
|
|
|
|
|
|
|
|
|
|
type VersionedAPI (v :: Nat) = Auth '[SA.BasicAuth, SA.JWT] SafeUser :> BaseAPI v
|
|
|
|
|
|
|
|
|
|
type RootCatalog (v :: Nat) = "catalog" :> Get '[XML] (Catalog v)
|
|
|
|
|
type ChannelCatalog (v :: Nat) = "catalog" :> "channel" :> Capture "channel_id" Channel.ChannelID :> Get '[XML] (Catalog v)
|
|
|
|
|
type CatalogContent = '[XML, OPDS]
|
|
|
|
|
|
|
|
|
|
type RootCatalog (v :: Nat) = "catalog" :> Get CatalogContent (Catalog v)
|
|
|
|
|
type ChannelCatalog (v :: Nat) = "catalog" :> "channel" :> Capture "channel_id" Channel.ChannelID :> Get CatalogContent (Catalog v)
|
|
|
|
|
type BaseAPI (v :: Nat) = RootCatalog v
|
|
|
|
|
:<|> ChannelCatalog v
|
|
|
|
|
|
|
|
|
@ -127,6 +148,8 @@ handler :: forall v. VersionedCatalog AppM v => ServerT (VersionedAPI v) AppM
|
|
|
|
|
handler auth = catalogRoot :<|> catalogChannels
|
|
|
|
|
where
|
|
|
|
|
catalogChannels :: Channel.ChannelID -> AppM (Catalog v)
|
|
|
|
|
catalogChannels _ = throwM err403{errBody="Not implemented"}
|
|
|
|
|
-- Channel specific catalog returns tags inside the catalog
|
|
|
|
|
catalogChannels identifier = flip requireLoggedIn auth (getBooks identifier)
|
|
|
|
|
catalogRoot :: AppM (Catalog v)
|
|
|
|
|
-- catalog root returns channels
|
|
|
|
|
catalogRoot = flip requireLoggedIn auth getChannels
|
|
|
|
|