Mercurial > hg > orthanc
diff Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 2984:db8f360fcb41
OrthancPluginAutodetectMimeType()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 08 Dec 2018 20:59:37 +0100 |
parents | 5947aeedf41f |
children | 32ec5078e32b |
line wrap: on
line diff
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Sat Dec 08 11:54:14 2018 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Sat Dec 08 20:59:37 2018 +0100 @@ -1356,61 +1356,23 @@ } } - const char* GetMimeType(const std::string& path) + + const char* AutodetectMimeType(const std::string& path) { - size_t dot = path.find_last_of('.'); - - std::string extension = (dot == std::string::npos) ? "" : path.substr(dot); - std::transform(extension.begin(), extension.end(), extension.begin(), tolower); + const char* mime = OrthancPluginAutodetectMimeType(GetGlobalContext(), path.c_str()); - if (extension == ".html") - { - return "text/html"; - } - else if (extension == ".css") - { - return "text/css"; - } - else if (extension == ".js") - { - return "application/javascript"; - } - else if (extension == ".gif") + if (mime == NULL) { - return "image/gif"; - } - else if (extension == ".svg") - { - return "image/svg+xml"; - } - else if (extension == ".json") - { - return "application/json"; - } - else if (extension == ".xml") - { - return "application/xml"; - } - else if (extension == ".wasm") - { - return "application/wasm"; - } - else if (extension == ".png") - { - return "image/png"; - } - else if (extension == ".jpg" || extension == ".jpeg") - { - return "image/jpeg"; + // Should never happen, just for safety + return "application/octet-stream"; } else { - return "application/octet-stream"; + return mime; } } - #if HAS_ORTHANC_PLUGIN_PEERS == 1 size_t OrthancPeers::GetPeerIndex(const std::string& name) const {