Mercurial > hg > orthanc-stone
diff Applications/StoneWebViewer/Plugin/Plugin.cpp @ 1700:f1bd464dc3e1
the plugin uses the Orthanc configuration instead of the default configuration
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Nov 2020 10:55:21 +0100 |
parents | 1ed2af7332a2 |
children | 2931f5e15320 |
line wrap: on
line diff
--- a/Applications/StoneWebViewer/Plugin/Plugin.cpp Fri Nov 27 10:21:48 2020 +0100 +++ b/Applications/StoneWebViewer/Plugin/Plugin.cpp Fri Nov 27 10:55:21 2020 +0100 @@ -160,6 +160,46 @@ } +void ServeConfiguration(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request) +{ + OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); + + if (request->method != OrthancPluginHttpMethod_Get) + { + OrthancPluginSendMethodNotAllowed(context, output, "GET"); + } + else + { + static const char* CONFIG_SECTION = "StoneWebViewer"; + + std::string config; + + OrthancPlugins::OrthancConfiguration orthanc; + if (orthanc.IsSection(CONFIG_SECTION)) + { + OrthancPlugins::OrthancConfiguration section(false); + orthanc.GetSection(section, CONFIG_SECTION); + + Json::Value wrapper = Json::objectValue; + wrapper[CONFIG_SECTION] = section.GetJson(); + config = wrapper.toStyledString(); + } + else + { + LOG(WARNING) << "The Orthanc configuration file doesn't contain a section \"" + << CONFIG_SECTION << "\" to configure the Stone Web viewer: " + << "Will use default settings"; + Orthanc::EmbeddedResources::GetDirectoryResource( + config, Orthanc::EmbeddedResources::WEB_APPLICATION, "/configuration.json"); + } + + OrthancPluginAnswerBuffer(context, output, config.c_str(), config.size(), "application/json"); + } +} + + extern "C" { ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) @@ -192,6 +232,9 @@ explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER); OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), explorer.c_str()); + OrthancPlugins::RegisterRestCallback<ServeConfiguration> + ("/stone-webviewer/configuration.json", true); + OrthancPlugins::RegisterRestCallback <ServeEmbeddedFile<Orthanc::EmbeddedResources::STONE_WEB_VIEWER_WASM> > ("/stone-webviewer/StoneWebViewer.wasm", true);