getDownloadR ri Directory   p = lift $ queryAcid (Access ri p) >>= \case
      Nothing   -> notFound
      Just node -> do
                     let ps = mapMaybe toPath . ST.flatten . current' $ node
                     fps <- mapM getFPs ps

                     addTypedHeader HFileKind Directory
                     addHeader "Content-Disposition" $ mconcat
                       [ "attachment; filename=\""
                       , _unFileName $ fileNameOf p, ".zip\""
                       ]

                     respondSource typeOctet
                       (readArchive fps $= awaitForever sendChunk)
  where
    -- toPath           :: _ -> Maybe (Path, Signature)
    toPath (n,(_,x)) = (Path $ F.toList n,) <$> x^?fileKind.signature

    getFPs (p',s) = (f p',) <$> getFilePath ri p' s

    f (Path ps) = FP.joinPath $ map (\n -> T.unpack $ n^.unFileName) ps
getDownloadR ri Directory   p = lift $ queryAcid (Access ri p) >>= \case
      Nothing   -> notFound
      Just node -> do
                     let ps = mapMaybe toPath . ST.flatten . current' $ node
                     fps <- mapM getFPs ps

                     addTypedHeader HFileKind Directory
                     addHeader "Content-Disposition" $ mconcat
                       [ "attachment; filename=\""
                       , _unFileName $ fileNameOf p, ".zip\""
                       ]

                     respondSource typeOctet
                       (readArchive fps $= awaitForever sendChunk)
  where
    -- toPath           :: _ -> Maybe (Path, Signature)
    toPath (n,(_,x)) = (Path $ F.toList n,) <$> x^?fileKind.signature

    getFPs (p',s) = (f p',) <$> getFilePath ri p' s

    f (Path ps) = FP.joinPath $ map (\n -> T.unpack $ n^.unFileName) ps
getDownloadR ri Directory   p = lift $ queryAcid (Access ri p) >>= \case
      Nothing   -> notFound
      Just node -> do
                     let ps = mapMaybe toPath . ST.flatten . current' $ node
                     fps <- mapM getFPs ps

                     addTypedHeader HFileKind Directory
                     addHeader "Content-Disposition" $ mconcat
                       [ "attachment; filename=\""
                       , _unFileName $ fileNameOf p, ".zip\""
                       ]

                     respondSource typeOctet
                       (readArchive fps $= awaitForever sendChunk)
  where
    -- toPath           :: _ -> Maybe (Path, Signature)
    toPath (n,(_,x)) = (Path $ F.toList n,) <$> x^?fileKind.signature

    getFPs (p',s) = (f p',) <$> getFilePath ri p' s

    f (Path ps) = FP.joinPath $ map (\n -> T.unpack $ n^.unFileName) ps