changeset 4805:0a38000b086d

Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
author Alain Mazy <am@osimis.io>
date Tue, 09 Nov 2021 09:51:14 +0100
parents ae643f664628
children 753f87dac208
files NEWS OrthancFramework/Sources/JobsEngine/IJob.h OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp OrthancFramework/Sources/JobsEngine/JobsRegistry.h OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.cpp OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.cpp OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.h OrthancFramework/Sources/RestApi/RestApiOutput.cpp OrthancFramework/Sources/RestApi/RestApiOutput.h OrthancFramework/UnitTestsSources/JobsTests.cpp OrthancServer/Plugins/Engine/PluginsJob.h OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp OrthancServer/Sources/ServerJobs/ArchiveJob.cpp OrthancServer/Sources/ServerJobs/ArchiveJob.h OrthancServer/UnitTestsSources/ServerJobsTests.cpp
diffstat 16 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Oct 28 13:05:56 2021 +0200
+++ b/NEWS	Tue Nov 09 09:51:14 2021 +0100
@@ -10,9 +10,10 @@
 --------
 
 * API version upgraded to 16
-* If an image can not be decoced, ../preview and ../rendered routes are now returning 
+* If an image can not be decoded, ../preview and ../rendered routes are now returning 
   unsupported.png only if the ?returnUnsupportedImage option is specified; otherwise, 
   it raises a 415 error code.
+* Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
   
 
 
--- a/OrthancFramework/Sources/JobsEngine/IJob.h	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancFramework/Sources/JobsEngine/IJob.h	Tue Nov 09 09:51:14 2021 +0100
@@ -59,6 +59,7 @@
     // "success" state
     virtual bool GetOutput(std::string& output,
                            MimeType& mime,
+                           std::string& filename,
                            const std::string& key) = 0;
   };
 }
--- a/OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp	Tue Nov 09 09:51:14 2021 +0100
@@ -650,6 +650,7 @@
 
   bool JobsRegistry::GetJobOutput(std::string& output,
                                   MimeType& mime,
+                                  std::string& filename,
                                   const std::string& job,
                                   const std::string& key)
   {
@@ -668,7 +669,7 @@
 
       if (handler.GetState() == JobState_Success)
       {
-        return handler.GetJob().GetOutput(output, mime, key);
+        return handler.GetJob().GetOutput(output, mime, filename, key);
       }
       else
       {
--- a/OrthancFramework/Sources/JobsEngine/JobsRegistry.h	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancFramework/Sources/JobsEngine/JobsRegistry.h	Tue Nov 09 09:51:14 2021 +0100
@@ -148,6 +148,7 @@
 
     bool GetJobOutput(std::string& output,
                       MimeType& mime,
+                      std::string& filename,
                       const std::string& job,
                       const std::string& key);
 
--- a/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.cpp	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.cpp	Tue Nov 09 09:51:14 2021 +0100
@@ -448,6 +448,7 @@
 
   bool SequenceOfOperationsJob::GetOutput(std::string& output,
                                           MimeType& mime,
+                                          std::string& filename,
                                           const std::string& key)
   {
     return false;
--- a/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h	Tue Nov 09 09:51:14 2021 +0100
@@ -125,6 +125,7 @@
 
     virtual bool GetOutput(std::string& output,
                            MimeType& mime,
+                           std::string& filename,
                            const std::string& key) ORTHANC_OVERRIDE;
 
     void AwakeTrailingSleep();
--- a/OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.cpp	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.cpp	Tue Nov 09 09:51:14 2021 +0100
@@ -270,6 +270,7 @@
 
   bool SetOfCommandsJob::GetOutput(std::string &output,
                                    MimeType &mime,
+                                   std::string& filename,
                                    const std::string &key)
   {
     return false;
--- a/OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.h	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.h	Tue Nov 09 09:51:14 2021 +0100
@@ -104,6 +104,7 @@
 
     virtual bool GetOutput(std::string& output,
                            MimeType& mime,
+                           std::string& filename,
                            const std::string& key) ORTHANC_OVERRIDE;
   };
 }
--- a/OrthancFramework/Sources/RestApi/RestApiOutput.cpp	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancFramework/Sources/RestApi/RestApiOutput.cpp	Tue Nov 09 09:51:14 2021 +0100
@@ -214,4 +214,9 @@
     // empty string
     SetCookie(name, "", 1);
   }
+
+  void RestApiOutput::SetContentFilename(const char* filename)
+  {
+    output_.SetContentFilename(filename);
+  }
 }
--- a/OrthancFramework/Sources/RestApi/RestApiOutput.h	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancFramework/Sources/RestApi/RestApiOutput.h	Tue Nov 09 09:51:14 2021 +0100
@@ -77,6 +77,8 @@
                       size_t length,
                       MimeType contentType);
 
+    void SetContentFilename(const char* filename);
+
     void SignalError(HttpStatus status);
 
     void SignalError(HttpStatus status,
--- a/OrthancFramework/UnitTestsSources/JobsTests.cpp	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancFramework/UnitTestsSources/JobsTests.cpp	Tue Nov 09 09:51:14 2021 +0100
@@ -125,6 +125,7 @@
 
     virtual bool GetOutput(std::string& output,
                            MimeType& mime,
+                           std::string& filename,
                            const std::string& key) ORTHANC_OVERRIDE
     {
       return false;
--- a/OrthancServer/Plugins/Engine/PluginsJob.h	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancServer/Plugins/Engine/PluginsJob.h	Tue Nov 09 09:51:14 2021 +0100
@@ -75,6 +75,7 @@
 
     virtual bool GetOutput(std::string& output,
                            MimeType& mime,
+                           std::string& filename,
                            const std::string& key) ORTHANC_OVERRIDE
     {
       // TODO
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Tue Nov 09 09:51:14 2021 +0100
@@ -696,10 +696,16 @@
 
     std::string value;
     MimeType mime;
+    std::string filename;
     
     if (OrthancRestApi::GetContext(call).GetJobsEngine().
-        GetRegistry().GetJobOutput(value, mime, job, key))
+        GetRegistry().GetJobOutput(value, mime, filename, job, key))
     {
+      if (!filename.empty())
+      {
+        call.GetOutput().SetContentFilename(filename.c_str());
+      }
+
       call.GetOutput().AnswerBuffer(value, mime);
     }
     else
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Tue Nov 09 09:51:14 2021 +0100
@@ -1196,6 +1196,7 @@
 
   bool ArchiveJob::GetOutput(std::string& output,
                              MimeType& mime,
+                             std::string& filename,
                              const std::string& key)
   {   
     if (key == "archive" &&
@@ -1208,6 +1209,7 @@
         const DynamicTemporaryFile& f = dynamic_cast<DynamicTemporaryFile&>(accessor.GetItem());
         f.GetFile().Read(output);
         mime = MimeType_Zip;
+        filename = "archive.zip";
         return true;
       }
       else
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.h	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.h	Tue Nov 09 09:51:14 2021 +0100
@@ -118,6 +118,7 @@
 
     virtual bool GetOutput(std::string& output,
                            MimeType& mime,
+                           std::string& filename,
                            const std::string& key) ORTHANC_OVERRIDE;
   };
 }
--- a/OrthancServer/UnitTestsSources/ServerJobsTests.cpp	Thu Oct 28 13:05:56 2021 +0200
+++ b/OrthancServer/UnitTestsSources/ServerJobsTests.cpp	Tue Nov 09 09:51:14 2021 +0100
@@ -140,6 +140,7 @@
 
     virtual bool GetOutput(std::string& output,
                            MimeType& mime,
+                           std::string& filename,
                            const std::string& key) ORTHANC_OVERRIDE
     {
       return false;