comparison Sources/Plugin.cpp @ 6:e8e7ba4371e3

fix access to OHIF study list
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 17 Jun 2023 17:45:05 +0200
parents 8c1fe0ca24f5
children eab054ee7537
comparison
equal deleted inserted replaced
5:8c1fe0ca24f5 6:e8e7ba4371e3
343 // (https://web.dev/coop-coep/) 343 // (https://web.dev/coop-coep/)
344 OrthancPluginSetHttpHeader(context, output, "Cross-Origin-Embedder-Policy", "require-corp"); 344 OrthancPluginSetHttpHeader(context, output, "Cross-Origin-Embedder-Policy", "require-corp");
345 OrthancPluginSetHttpHeader(context, output, "Cross-Origin-Opener-Policy", "same-origin"); 345 OrthancPluginSetHttpHeader(context, output, "Cross-Origin-Opener-Policy", "same-origin");
346 OrthancPluginSetHttpHeader(context, output, "Cross-Origin-Resource-Policy", "same-origin"); 346 OrthancPluginSetHttpHeader(context, output, "Cross-Origin-Resource-Policy", "same-origin");
347 347
348 const std::string uri = request->groups[0]; 348 std::string uri;
349 if (request->groupsCount > 0)
350 {
351 uri = request->groups[0];
352 }
349 353
350 if (uri == "app-config.js") 354 if (uri == "app-config.js")
351 { 355 {
352 std::string system, user; 356 std::string system, user;
353 Orthanc::EmbeddedResources::GetFileResource(system, Orthanc::EmbeddedResources::APP_CONFIG_SYSTEM); 357 Orthanc::EmbeddedResources::GetFileResource(system, Orthanc::EmbeddedResources::APP_CONFIG_SYSTEM);
360 system = Orthanc::Toolbox::SubstituteVariables(system, dictionary); 364 system = Orthanc::Toolbox::SubstituteVariables(system, dictionary);
361 365
362 std::string s = (user + "\n" + system); 366 std::string s = (user + "\n" + system);
363 OrthancPluginAnswerBuffer(context, output, s.c_str(), s.size(), "application/json"); 367 OrthancPluginAnswerBuffer(context, output, s.c_str(), s.size(), "application/json");
364 } 368 }
365 else if (uri == "viewer") 369 else if (uri == "" || // Study list
366 { 370 uri == "tmtv" || // Total metabolic tumor volume
371 uri == "viewer") // Default viewer (including MPR)
372 {
373 // Those correspond to the different modes of the OHIF platform:
374 // https://v3-docs.ohif.org/platform/modes/
367 cache_.Answer(context, output, "index.html"); 375 cache_.Answer(context, output, "index.html");
368 } 376 }
369 else 377 else
370 { 378 {
371 cache_.Answer(context, output, uri); 379 cache_.Answer(context, output, uri);
543 551
544 OrthancPluginAnswerBuffer(context, output, s.c_str(), s.size(), "application/json"); 552 OrthancPluginAnswerBuffer(context, output, s.c_str(), s.size(), "application/json");
545 } 553 }
546 554
547 555
548 static OrthancPluginErrorCode RedirectRoot(OrthancPluginRestOutput* output,
549 const char* url,
550 const OrthancPluginHttpRequest* request)
551 {
552 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext();
553
554 if (request->method != OrthancPluginHttpMethod_Get)
555 {
556 OrthancPluginSendMethodNotAllowed(context, output, "GET");
557 }
558 else
559 {
560 // TODO - Is there a better way to go to the list of studies in DICOMweb?
561 // TODO - What if not using DICOMweb?
562 OrthancPluginRedirect(context, output, "ohif/viewer?StudyInstanceUIDs=");
563 }
564
565 return OrthancPluginErrorCode_Success;
566 }
567
568
569 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, 556 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType,
570 OrthancPluginResourceType resourceType, 557 OrthancPluginResourceType resourceType,
571 const char* resourceId) 558 const char* resourceId)
572 { 559 {
573 try 560 try
642 } 629 }
643 630
644 routerBasename_ = configuration.GetStringValue("RouterBasename", "/ohif"); 631 routerBasename_ = configuration.GetStringValue("RouterBasename", "/ohif");
645 useDicomWeb_ = configuration.GetBooleanValue("DicomWeb", false); 632 useDicomWeb_ = configuration.GetBooleanValue("DicomWeb", false);
646 633
634 // Make sure that the router basename ends with a trailing slash
635 if (routerBasename_.empty() ||
636 routerBasename_[routerBasename_.size() - 1] != '/')
637 {
638 routerBasename_ += "/";
639 }
640
647 OrthancPluginSetDescription(context, "OHIF plugin for Orthanc."); 641 OrthancPluginSetDescription(context, "OHIF plugin for Orthanc.");
648 642
649 OrthancPluginRegisterRestCallback(context, "/ohif", RedirectRoot); 643 OrthancPlugins::RegisterRestCallback<ServeFile>("/ohif", true);
650 OrthancPlugins::RegisterRestCallback<ServeFile>("/ohif/(.*)", true); 644 OrthancPlugins::RegisterRestCallback<ServeFile>("/ohif/(.*)", true);
651 OrthancPlugins::RegisterRestCallback<GetOhifStudy>("/ohif-source/(.*)", true); 645 OrthancPlugins::RegisterRestCallback<GetOhifStudy>("/ohif-source/(.*)", true);
652 646
653 OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback); 647 OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback);
654 648