diff OrthancServer/OrthancRestApi.cpp @ 702:7592a48e97e4

delete custom attachment
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Feb 2014 17:28:17 +0100
parents f9052558eada
children 696dbb4fd390
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi.cpp	Mon Feb 10 14:30:56 2014 +0100
+++ b/OrthancServer/OrthancRestApi.cpp	Tue Feb 11 17:28:17 2014 +0100
@@ -2028,13 +2028,36 @@
 
     const void* data = call.GetPutBody().size() ? &call.GetPutBody()[0] : NULL;
 
-    if (context.AddAttachment(publicId, StringToContentType(name), data, call.GetPutBody().size()))
+    FileContentType contentType = StringToContentType(name);
+    if (contentType >= FileContentType_StartUser &&  // It is forbidden to modify internal attachments
+        contentType <= FileContentType_EndUser &&
+        context.AddAttachment(publicId, StringToContentType(name), data, call.GetPutBody().size()))
     {
       call.GetOutput().AnswerBuffer("{}", "application/json");
     }
   }
 
 
+  static void DeleteAttachment(RestApi::DeleteCall& call)
+  {
+    RETRIEVE_CONTEXT(call);
+    CheckValidResourceType(call);
+
+    std::string publicId = call.GetUriComponent("id", "");
+    std::string name = call.GetUriComponent("name", "");
+    FileContentType contentType = StringToContentType(name);
+
+    if (contentType >= FileContentType_StartUser &&
+        contentType <= FileContentType_EndUser)
+    {
+      // It is forbidden to delete internal attachments
+      context.GetIndex().DeleteAttachment(publicId, contentType);
+      call.GetOutput().AnswerBuffer("{}", "application/json");
+    }
+  }
+
+
+
 
   // Registration of the various REST handlers --------------------------------
 
@@ -2127,6 +2150,7 @@
     Register("/{resourceType}/{id}/metadata/{name}", SetMetadata);
 
     Register("/{resourceType}/{id}/attachments", ListAttachments);
+    Register("/{resourceType}/{id}/attachments/{name}", DeleteAttachment);
     Register("/{resourceType}/{id}/attachments/{name}", GetAttachmentOperations);
     Register("/{resourceType}/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>);
     Register("/{resourceType}/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5);