From 08d5e0538db2302e5e16c146228e649c66af409e Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Wed, 5 Feb 2020 12:22:34 +1100 Subject: [PATCH] Now distinguishes between not finding an object (which redirects to ocfl_err_pending) and not finding the content within an object (which redirects to ocfl_err_not_found) --- conf.d/ocfl.conf | 7 ++++++- doc/ocfl-nginx.md | 11 +++++++++++ js/ocfl.js | 14 +++++++------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/conf.d/ocfl.conf b/conf.d/ocfl.conf index 28811be..d995df6 100644 --- a/conf.d/ocfl.conf +++ b/conf.d/ocfl.conf @@ -10,14 +10,19 @@ server { root /etc/share/nginx/html/; } + location /error/ { + root /etc/share/nginx/html/; + } + set $ocfl_files /etc/share/nginx/html/ocfl; set $ocfl_versions on; + set $ocfl_err_pending /error/pending.html; + set $ocfl_err_not_found /error/404.html; location /trees/ { set $ocfl_repo trees_ocfl; set $ocfl_path trees; - set $ocfl_index_file ro-crate-preview.html; set $ocfl_autoindex on; js_content ocfl; } diff --git a/doc/ocfl-nginx.md b/doc/ocfl-nginx.md index b9ffde9..1898f7c 100644 --- a/doc/ocfl-nginx.md +++ b/doc/ocfl-nginx.md @@ -75,6 +75,17 @@ Each of the locations representing the OCFL directory needs to set its `root` di These can be configured for the whole server (all repos) or for individual repos +### $ocfl_err_pending + +Relative URL to redirect to when ocfl.js can't find the requested OID. This may be different to a 'resource not found' message because the object may not have been written to the live repository yet + +### $ocfl_err_not_found + +Relative URL to redirect to in two cases: + +- the incoming path can't be parsed by the REPO/OID(.vN)/PATH pattern +- the repo and oid are found, but the path doesn't exist at the requested version + ### $ocfl_index_file This is the equivalent of the nginx `index` directive. If a file with this name is found in the path (and exists in the requested version) it will be returned by default. If no such file is found, a 404 error is returned. diff --git a/js/ocfl.js b/js/ocfl.js index 02b9325..86da6b6 100644 --- a/js/ocfl.js +++ b/js/ocfl.js @@ -20,7 +20,7 @@ function ocfl(req) { var match = req.uri.match(pattern); if( !match ) { req.error("Match failed " + pattern); - req.internalRedirect("/50x.html"); + req.internalRedirect(req.variables.ocfl_err_not_found); } else { var oid = match[1]; var v = match[2]; @@ -37,8 +37,8 @@ function ocfl(req) { } var inv = load_inventory(req, ocfl_files + '/' + opath); if( ! inv ) { - req.error("Couldn't load inventory for " + object); - req.internalRedirect('/404.html'); + req.internalRedirect(req.variables.ocfl_err_pending); + return; } if( !v ) { v = inv.head; @@ -51,7 +51,7 @@ function ocfl(req) { req.error("Looking for version " + v); if( ! inv.versions[v] ) { req.error("Couldn't find version " + v); - req.internalRedirect("/404.html"); + req.internalRedirect(req.variables.ocfl_err_not_found); } if( allow_autoindex === 'on' && ( content === '' || content.slice(-1) === '/' ) ) { auto_index(ocfl_repo, req, oid, inv, v, content); @@ -63,7 +63,7 @@ function ocfl(req) { req.internalRedirect(newroute); } else { req.error("Version not found"); - req.internalRedirect("/404.html"); + req.internalRedirect(req.variables.ocfl_err_not_found); } } } @@ -122,7 +122,7 @@ function auto_index(repo, req, oid, inv, v, path) { send_html(req, page_html(oid + '.' + v + '/' + path, links, null)); } else { req.error("No match found for path " + path); - req.internalRedirect("/404.html"); + req.internalRedirect(req.variables.ocfl_err_not_found); } } @@ -136,7 +136,7 @@ function history(repo_url, req, oid, inv, path) { return state[h].includes(path); }); if( hash.length > 0 ) { - req.error("Adding " + hash + " to versions"); + req.warn("Adding " + hash + " to versions"); versions[v] = hash[0]; } });