diff OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 1700:f5ddbd9239dd

New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 09 Oct 2015 17:20:26 +0200
parents b8dc2f855a83
children 4aaaecae5803
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Fri Oct 09 13:31:22 2015 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Fri Oct 09 17:20:26 2015 +0200
@@ -479,6 +479,7 @@
     {
       Json::Value operations = Json::arrayValue;
 
+      operations.append("compress");
       operations.append("compressed-data");
 
       if (info.GetCompressedMD5() != "")
@@ -488,6 +489,7 @@
 
       operations.append("compressed-size");
       operations.append("data");
+      operations.append("is-compressed");
 
       if (info.GetUncompressedMD5() != "")
       {
@@ -495,6 +497,7 @@
       }
 
       operations.append("size");
+      operations.append("uncompress");
 
       if (info.GetCompressedMD5() != "" &&
           info.GetUncompressedMD5() != "")
@@ -663,6 +666,31 @@
   }
 
 
+  template <enum CompressionType compression>
+  static void ChangeAttachmentCompression(RestApiPostCall& call)
+  {
+    CheckValidResourceType(call);
+
+    std::string publicId = call.GetUriComponent("id", "");
+    std::string name = call.GetUriComponent("name", "");
+    FileContentType contentType = StringToContentType(name);
+
+    OrthancRestApi::GetContext(call).ChangeAttachmentCompression(publicId, contentType, compression);
+    call.GetOutput().AnswerBuffer("{}", "application/json");
+  }
+
+
+  static void IsAttachmentCompressed(RestApiGetCall& call)
+  {
+    FileInfo info;
+    if (GetAttachmentInfo(info, call))
+    {
+      std::string answer = (info.GetCompressionType() == CompressionType_None) ? "0" : "1";
+      call.GetOutput().AnswerBuffer(answer, "text/plain");
+    }
+  }
+
+
   // Raw access to the DICOM tags of an instance ------------------------------
 
   static void GetRawContent(RestApiGetCall& call)
@@ -1125,14 +1153,17 @@
     Register("/{resourceType}/{id}/attachments", ListAttachments);
     Register("/{resourceType}/{id}/attachments/{name}", DeleteAttachment);
     Register("/{resourceType}/{id}/attachments/{name}", GetAttachmentOperations);
+    Register("/{resourceType}/{id}/attachments/{name}", UploadAttachment);
+    Register("/{resourceType}/{id}/attachments/{name}/compress", ChangeAttachmentCompression<CompressionType_ZlibWithSize>);
     Register("/{resourceType}/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>);
     Register("/{resourceType}/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5);
     Register("/{resourceType}/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize);
     Register("/{resourceType}/{id}/attachments/{name}/data", GetAttachmentData<1>);
+    Register("/{resourceType}/{id}/attachments/{name}/is-compressed", IsAttachmentCompressed);
     Register("/{resourceType}/{id}/attachments/{name}/md5", GetAttachmentMD5);
     Register("/{resourceType}/{id}/attachments/{name}/size", GetAttachmentSize);
+    Register("/{resourceType}/{id}/attachments/{name}/uncompress", ChangeAttachmentCompression<CompressionType_None>);
     Register("/{resourceType}/{id}/attachments/{name}/verify-md5", VerifyAttachment);
-    Register("/{resourceType}/{id}/attachments/{name}", UploadAttachment);
 
     Register("/tools/lookup", Lookup);
     Register("/tools/find", Find);