comparison 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
comparison
equal deleted inserted replaced
701:f9052558eada 702:7592a48e97e4
2026 std::string publicId = call.GetUriComponent("id", ""); 2026 std::string publicId = call.GetUriComponent("id", "");
2027 std::string name = call.GetUriComponent("name", ""); 2027 std::string name = call.GetUriComponent("name", "");
2028 2028
2029 const void* data = call.GetPutBody().size() ? &call.GetPutBody()[0] : NULL; 2029 const void* data = call.GetPutBody().size() ? &call.GetPutBody()[0] : NULL;
2030 2030
2031 if (context.AddAttachment(publicId, StringToContentType(name), data, call.GetPutBody().size())) 2031 FileContentType contentType = StringToContentType(name);
2032 if (contentType >= FileContentType_StartUser && // It is forbidden to modify internal attachments
2033 contentType <= FileContentType_EndUser &&
2034 context.AddAttachment(publicId, StringToContentType(name), data, call.GetPutBody().size()))
2032 { 2035 {
2033 call.GetOutput().AnswerBuffer("{}", "application/json"); 2036 call.GetOutput().AnswerBuffer("{}", "application/json");
2034 } 2037 }
2035 } 2038 }
2039
2040
2041 static void DeleteAttachment(RestApi::DeleteCall& call)
2042 {
2043 RETRIEVE_CONTEXT(call);
2044 CheckValidResourceType(call);
2045
2046 std::string publicId = call.GetUriComponent("id", "");
2047 std::string name = call.GetUriComponent("name", "");
2048 FileContentType contentType = StringToContentType(name);
2049
2050 if (contentType >= FileContentType_StartUser &&
2051 contentType <= FileContentType_EndUser)
2052 {
2053 // It is forbidden to delete internal attachments
2054 context.GetIndex().DeleteAttachment(publicId, contentType);
2055 call.GetOutput().AnswerBuffer("{}", "application/json");
2056 }
2057 }
2058
2036 2059
2037 2060
2038 2061
2039 // Registration of the various REST handlers -------------------------------- 2062 // Registration of the various REST handlers --------------------------------
2040 2063
2125 Register("/{resourceType}/{id}/metadata/{name}", DeleteMetadata); 2148 Register("/{resourceType}/{id}/metadata/{name}", DeleteMetadata);
2126 Register("/{resourceType}/{id}/metadata/{name}", GetMetadata); 2149 Register("/{resourceType}/{id}/metadata/{name}", GetMetadata);
2127 Register("/{resourceType}/{id}/metadata/{name}", SetMetadata); 2150 Register("/{resourceType}/{id}/metadata/{name}", SetMetadata);
2128 2151
2129 Register("/{resourceType}/{id}/attachments", ListAttachments); 2152 Register("/{resourceType}/{id}/attachments", ListAttachments);
2153 Register("/{resourceType}/{id}/attachments/{name}", DeleteAttachment);
2130 Register("/{resourceType}/{id}/attachments/{name}", GetAttachmentOperations); 2154 Register("/{resourceType}/{id}/attachments/{name}", GetAttachmentOperations);
2131 Register("/{resourceType}/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>); 2155 Register("/{resourceType}/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>);
2132 Register("/{resourceType}/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5); 2156 Register("/{resourceType}/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5);
2133 Register("/{resourceType}/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize); 2157 Register("/{resourceType}/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize);
2134 Register("/{resourceType}/{id}/attachments/{name}/data", GetAttachmentData<1>); 2158 Register("/{resourceType}/{id}/attachments/{name}/data", GetAttachmentData<1>);