[frame] prefetch codimd doc first, before downloading it

Otherwise, if doc wasn't visited yet, codimd returns some large HTML
page.
parent 6e07f6c5
Pipeline #5889 passed with stages
in 108 minutes
......@@ -14,11 +14,10 @@ Portability : POSIX
module Gargantext.Database.Admin.Types.Hyperdata.Frame
where
import Control.Lens
import Data.ByteString.Lazy (toStrict)
import Data.Text qualified as T
import Gargantext.Database.Admin.Types.Hyperdata.Prelude
import Gargantext.Prelude hiding (toStrict)
import Gargantext.Prelude ( ($), Show, Applicative(pure), IO, (.), (&), decodeUtf8 )
import Network.Wreq qualified as Wreq
------------------------------------------------------------------------
......@@ -62,7 +61,12 @@ instance ToSchema HyperdataFrame where
getHyperdataFrameContents :: HyperdataFrame -> IO Text
getHyperdataFrameContents (HyperdataFrame { _hf_base, _hf_frame_id }) = do
let path = T.concat [_hf_base, "/", _hf_frame_id, "/download"]
let path = T.intercalate "/" [_hf_base, _hf_frame_id, "download"]
-- We need to issue a request to this frame, because it might not
-- have been fetched yet and in that case codimd returns some ugly
-- HTML
-- See issue https://gitlab.iscpif.fr/gargantext/haskell-gargantext/issues/333
_ <- Wreq.headWith Wreq.defaults $ T.unpack path
r <- Wreq.get $ T.unpack path
pure $ decodeUtf8 $ toStrict $ r ^. Wreq.responseBody
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment