From fd200a85af7f56670009e9adbf1bb7d7e38088f9 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 29 Sep 2020 17:27:21 -0700 Subject: [PATCH] web: /version provides hledger version string as JSON (#1152) --- hledger-web/Hledger/Web/Handler/MiscR.hs | 11 ++++++++++- hledger-web/config/routes | 1 + hledger-web/hledger-web.m4.md | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hledger-web/Hledger/Web/Handler/MiscR.hs b/hledger-web/Hledger/Web/Handler/MiscR.hs index 087eb9b54..4dd4e198f 100644 --- a/hledger-web/Hledger/Web/Handler/MiscR.hs +++ b/hledger-web/Hledger/Web/Handler/MiscR.hs @@ -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 diff --git a/hledger-web/config/routes b/hledger-web/config/routes index 4c47c6385..5640e409c 100644 --- a/hledger-web/config/routes +++ b/hledger-web/config/routes @@ -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 diff --git a/hledger-web/hledger-web.m4.md b/hledger-web/hledger-web.m4.md index 9c1998c6d..f770c645c 100644 --- a/hledger-web/hledger-web.m4.md +++ b/hledger-web/hledger-web.m4.md @@ -215,6 +215,7 @@ $ hledger-web -f examples/sample.journal --serve-api You can get JSON data from these routes: ``` +/version /accountnames /transactions /prices