Commit 5f1195fd authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge remote-tracking branch 'origin/312-dev-zip-file-last-modification-time-fix' into testing

parents 8de56ef9 71bc8cf8
...@@ -18,7 +18,7 @@ fi ...@@ -18,7 +18,7 @@ fi
# with the `sha256sum` result calculated on the `cabal.project` and # with the `sha256sum` result calculated on the `cabal.project` and
# `cabal.project.freeze`. This ensures the files stay deterministic so that CI # `cabal.project.freeze`. This ensures the files stay deterministic so that CI
# cache can kick in. # cache can kick in.
expected_cabal_project_hash="96be39a29bab66851278db07974dc3c61e7f807aefc3a3e9d50a9eb269706ef0" expected_cabal_project_hash="7142cc1299cafe14f07273c3437409a862f7d931cff778a634312a450543c07b"
expected_cabal_project_freeze_hash="a88c2d091ee6223b64fb5dd38e71ab8379710a2aa716d2467f318789e4d75589" expected_cabal_project_freeze_hash="a88c2d091ee6223b64fb5dd38e71ab8379710a2aa716d2467f318789e4d75589"
cabal --store-dir=$STORE_DIR v2-build --dry-run cabal --store-dir=$STORE_DIR v2-build --dry-run
......
...@@ -172,7 +172,7 @@ source-repository-package ...@@ -172,7 +172,7 @@ source-repository-package
type: git type: git
location: https://github.com/robstewart57/rdf4h.git location: https://github.com/robstewart57/rdf4h.git
tag: 4fd2edf30c141600ffad6d730cc4c1c08a6dbce4 tag: 4fd2edf30c141600ffad6d730cc4c1c08a6dbce4
allow-older: * allow-older: *
allow-newer: * allow-newer: *
......
...@@ -16,6 +16,7 @@ import Data.ByteString.Lazy.Char8 qualified as BSC ...@@ -16,6 +16,7 @@ import Data.ByteString.Lazy.Char8 qualified as BSC
import Data.Csv (encodeDefaultOrderedByName) import Data.Csv (encodeDefaultOrderedByName)
import Data.Text qualified as T import Data.Text qualified as T
import Data.Text.Encoding qualified as TE import Data.Text.Encoding qualified as TE
import Data.Time.Clock.System (getSystemTime, systemSeconds)
import Data.Version (showVersion) import Data.Version (showVersion)
import Gargantext.API.Node.Document.Export.Types import Gargantext.API.Node.Document.Export.Types
import Gargantext.API.Prelude (GargNoServer, GargServer) import Gargantext.API.Prelude (GargNoServer, GargServer)
...@@ -28,6 +29,7 @@ import Gargantext.Database.Schema.Node (NodePoly(..), node_user_id) ...@@ -28,6 +29,7 @@ import Gargantext.Database.Schema.Node (NodePoly(..), node_user_id)
import Gargantext.Prelude import Gargantext.Prelude
import Paths_gargantext qualified as PG -- cabal magic build module import Paths_gargantext qualified as PG -- cabal magic build module
import Servant ( addHeader, (:<|>)((:<|>)), Header, Headers(getResponse) ) import Servant ( addHeader, (:<|>)((:<|>)), Header, Headers(getResponse) )
import Data.Time.LocalTime (getCurrentTimeZone, TimeZone (timeZoneMinutes))
api :: NodeId api :: NodeId
-- ^ The ID of the target user -- ^ The ID of the target user
...@@ -79,8 +81,14 @@ getDocumentsJSONZip :: NodeId ...@@ -79,8 +81,14 @@ getDocumentsJSONZip :: NodeId
-> GargNoServer (Headers '[Header "Content-Disposition" T.Text] DocumentExportZIP) -- [Document] -> GargNoServer (Headers '[Header "Content-Disposition" T.Text] DocumentExportZIP) -- [Document]
getDocumentsJSONZip userNodeId pId = do getDocumentsJSONZip userNodeId pId = do
dJSON <- getDocumentsJSON userNodeId pId dJSON <- getDocumentsJSON userNodeId pId
systime <- liftBase getSystemTime
tz <- liftBase getCurrentTimeZone
let dexp = getResponse dJSON let dexp = getResponse dJSON
let dexpz = DocumentExportZIP { _dez_dexp = dexp, _dez_doc_id = pId } let dexpz = DocumentExportZIP { _dez_dexp = dexp
, _dez_doc_id = pId
-- see https://github.com/jgm/zip-archive/commit/efe4423a9a2b1dc2a4d413917a933828d3f8dc0f
, _dez_last_modified = fromIntegral (systemSeconds systime) +
fromIntegral (timeZoneMinutes tz * 60) }
pure $ addHeader (T.concat [ "attachment; filename=" pure $ addHeader (T.concat [ "attachment; filename="
, dezFileName dexpz , dezFileName dexpz
, ".zip" ]) dexpz , ".zip" ]) dexpz
......
...@@ -25,7 +25,7 @@ import Gargantext.Database.Admin.Types.Hyperdata.Document ( HyperdataDocument(.. ...@@ -25,7 +25,7 @@ import Gargantext.Database.Admin.Types.Hyperdata.Document ( HyperdataDocument(..
import Gargantext.Database.Admin.Types.Node (DocId) import Gargantext.Database.Admin.Types.Node (DocId)
import Gargantext.Database.Schema.Node (NodePoly(..)) import Gargantext.Database.Schema.Node (NodePoly(..))
import Gargantext.Utils.Servant (ZIP) import Gargantext.Utils.Servant (ZIP)
import Gargantext.Utils.Zip (zipContentsPure) import Gargantext.Utils.Zip (zipContentsPureWithLastModified)
import Protolude import Protolude
import Servant ((:>), (:<|>), Get, Header, Headers(..), JSON, MimeRender(..), PlainText, Summary) import Servant ((:>), (:<|>), Get, Header, Headers(..), JSON, MimeRender(..), PlainText, Summary)
...@@ -38,8 +38,9 @@ data DocumentExport = ...@@ -38,8 +38,9 @@ data DocumentExport =
-- | This is to represent a zipped document export. We want to have doc_id in zipped file name. -- | This is to represent a zipped document export. We want to have doc_id in zipped file name.
data DocumentExportZIP = data DocumentExportZIP =
DocumentExportZIP { _dez_dexp :: DocumentExport DocumentExportZIP { _dez_dexp :: DocumentExport
, _dez_doc_id :: DocId } deriving (Generic) , _dez_doc_id :: DocId
, _dez_last_modified :: Integer } deriving (Generic)
data Document = data Document =
...@@ -125,4 +126,4 @@ dezFileName (DocumentExportZIP { .. }) = "GarganText_DocsList-" <> show _dez_doc ...@@ -125,4 +126,4 @@ dezFileName (DocumentExportZIP { .. }) = "GarganText_DocsList-" <> show _dez_doc
instance MimeRender ZIP DocumentExportZIP where instance MimeRender ZIP DocumentExportZIP where
mimeRender _ dexpz@(DocumentExportZIP { .. }) = mimeRender _ dexpz@(DocumentExportZIP { .. }) =
zipContentsPure (T.unpack $ dezFileName dexpz) (encode _dez_dexp) zipContentsPureWithLastModified (T.unpack $ dezFileName dexpz) (encode _dez_dexp) _dez_last_modified
...@@ -50,3 +50,9 @@ zipContentsPure :: FilePath -> BSC.ByteString -> BSC.ByteString ...@@ -50,3 +50,9 @@ zipContentsPure :: FilePath -> BSC.ByteString -> BSC.ByteString
zipContentsPure fpath bscContents = ZArch.fromArchive (ZArch.addEntryToArchive e ZArch.emptyArchive) zipContentsPure fpath bscContents = ZArch.fromArchive (ZArch.addEntryToArchive e ZArch.emptyArchive)
where where
e = ZArch.toEntry fpath 0 bscContents e = ZArch.toEntry fpath 0 bscContents
zipContentsPureWithLastModified :: FilePath -> BSC.ByteString -> Integer -> BSC.ByteString
zipContentsPureWithLastModified fpath bscContents lastModified =
ZArch.fromArchive (ZArch.addEntryToArchive e ZArch.emptyArchive)
where
e = ZArch.toEntry fpath lastModified bscContents
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