Skip to content
Snippets Groups Projects
Commit 5c03543c authored by Ann Yanich's avatar Ann Yanich
Browse files

Fix issue with loading excalidraw libraries on the private/shared whiteboard pages

parent 364c289c
No related branches found
No related tags found
No related merge requests found
......@@ -11,18 +11,34 @@ class ExcalidrawController extends PluginController
// The base of the URL is statically configured when building the app.
// But we are building a plugin for Stud.IP which will be built once and run at many
// different universities. So the question is, what can we do?
// We must provide a base URL, so we provide the base URL '.' (the path of the current page).
// We provide CRA with the base URL '.', causing our app to use relative paths for resources.
// Then, we use before_filter to redirect the requests it makes to the correct URLs.
// There are two cases to handle:
// Case 1: The action which displays Excalidraw has been requested with an argument.
// This causes our app to make requests for resources which look like this:
// https://<studip-base-url>/plugins.php/excalidrawplugin/<current controller>/<current action>/static/media/<filename>.excalidrawlib
// We want them to look like this:
// Case 2: The action which displays Excalidraw has been requested without an argument.
// The requests our app makes will look slightly different:
// https://<studip-base-url>/plugins.php/excalidrawplugin/<current controller>/static/media/<filename>.excalidrawlib
// In both cases, we want to redirect the requests to the following URL:
// https://<studip-base-url>/plugins_packages/UOL/ExcalidrawPlugin/excalidraw-selfhosted/build/static/media/<filename>.excalidrawlib
// We provide a 302 redirect to the appropriate url.
if (count($args) === 3 && $args[0] === 'static' && $args[1] === 'media' && str_ends_with(
$_SERVER['REQUEST_URI'],
'excalidrawlib'
)) {
$url = $this->plugin->getPluginUrl(
) . '/excalidraw-selfhosted/build/static/media/' . $args[2] . '.excalidrawlib';
$isCase1 = count($args) === 3 && $args[0] === 'static' && $args[1] === 'media' &&
str_ends_with($_SERVER['REQUEST_URI'], 'excalidrawlib');
$isCase2 = $action === 'static' && count($args) === 2 && $args[0] === 'media' &&
str_ends_with($_SERVER['REQUEST_URI'], 'excalidrawlib');
if ($isCase1) {
$url = $this->plugin->getPluginUrl() . '/excalidraw-selfhosted/build/static/media/' .
$args[2] . '.excalidrawlib';
$this->redirect($url);
return;
}
if ($isCase2) {
$url = $this->plugin->getPluginUrl() . '/excalidraw-selfhosted/build/static/media/' .
$args[1] . '.excalidrawlib';
$this->redirect($url);
return;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment