web: /version provides hledger version string as JSON (#1152)

This commit is contained in:
Simon Michael 2020-09-29 17:27:21 -07:00
parent f2b9ac2af1
commit fd200a85af
3 changed files with 12 additions and 1 deletions

View File

@ -7,7 +7,8 @@
{-# LANGUAGE TemplateHaskell #-}
module Hledger.Web.Handler.MiscR
( getAccountnamesR
( getVersionR
, getAccountnamesR
, getTransactionsR
, getPricesR
, getCommoditiesR
@ -25,6 +26,7 @@ import qualified Data.Text as T
import Yesod.Default.Handlers (getFaviconR, getRobotsR)
import Hledger
import Hledger.Cli.Version (version)
import Hledger.Web.Import
import Hledger.Web.Widget.Common (journalFile404)
@ -53,6 +55,13 @@ getDownloadR f = do
-- hledger-web equivalents of the old hledger-api's handlers
getVersionR :: Handler TypedContent
getVersionR = do
VD{caps} <- getViewData
when (CapView `notElem` caps) (permissionDenied "Missing the 'view' capability")
selectRep $ do
provideJson $ version
getAccountnamesR :: Handler TypedContent
getAccountnamesR = do
VD{caps, j} <- getViewData

View File

@ -12,6 +12,7 @@
/upload/#FilePath UploadR GET POST
/download/#FilePath DownloadR GET
/version VersionR GET
/accountnames AccountnamesR GET
/transactions TransactionsR GET
/prices PricesR GET

View File

@ -215,6 +215,7 @@ $ hledger-web -f examples/sample.journal --serve-api
You can get JSON data from these routes:
```
/version
/accountnames
/transactions
/prices