Commit d327b81d authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

digilib in controller | we omit REST-API

parent d618302a
xquery version "3.1";
import module namespace config="http://textgrid.de/ns/SADE/config" at "modules/config/config.xqm";
import module namespace digilib="http://textgrid.info/namespaces/xquery/digilib" at "../textgrid-connect/digilibProxy.xqm";
declare variable $exist:path external;
declare variable $exist:resource external;
......@@ -11,25 +12,40 @@ declare variable $exist:root external;
let $project := tokenize( $exist:path, "/" )[. != ""][not(ends-with(., "html"))][1]
let $listproject := config:list-projects()[1]
return
(: forward requests without resources to index.html :)
if ($exist:path eq '') then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{request:get-uri()}/"/>
</dispatch>
(: forward requests without project to the first project listed :)
else if (empty($project)) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{config:list-projects()[1]}/index.html"/>
</dispatch>
(: forward requests without resources to index.html :)
else if (ends-with($exist:path, "/") or empty($exist:resource)) then
(: forward root path to index.xql :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="index.html"/>
</dispatch>
(: forward REST requests to data collection of the project:)
else if (tokenize($exist:path, '/') = "rest") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="/../sade-projects/{$project}/data/xml/{substring-after($exist:path, "/rest/")}" >
</forward>
<forward url="/../sade-projects/{$project}/data/xml/{substring-after($exist:path, "/rest/")}"/>
</dispatch>
(: forward DIGILIB requests to the proxy function :)
else if (tokenize($exist:path, '/') = "digilib") then
let $path := tokenize($exist:path, '/'),
$id := $path[last()],
$if-modified-since := request:get-header("if-modified-since")
return
digilib:proxy($project, $id, $if-modified-since)
(: the important stuff :)
else if (ends-with($exist:resource, ".html")) then
let $doc-path := $config:projects-dir || $project || config:get("template") || $exist:resource
return
......@@ -45,13 +61,15 @@ else if (ends-with($exist:resource, ".html")) then
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
(: Resource paths starting with $shared are loaded from the shared-resources app :)
(: resource paths starting with $shared are loaded from the shared-resources app :)
else if (contains($exist:path, "/$shared/")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="/shared-resources/{substring-after($exist:path, '/$shared/')}">
<set-header name="Cache-Control" value="max-age=3600, must-revalidate"/>
</forward>
</dispatch>
else
(: check if the resource comes from the template or the data
we try to leave the template manipulation as minimal as
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment