Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let the user disable schema url redirects if enabled #501

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/tasty-ladybugs-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@zazuko/trifid-entity-renderer": patch
---

If `enableSchemaUrlRedirect` configuration option is set to `true`, the plugin is performing a redirect if the URI contains a `schema:URL` predicate pointing to a resource of type `xsd:anyURI` (already in place).

The user can now disable this behavior by either:

- setting the `disableSchemaUrlRedirect` query parameter to `true`
- setting the `x-disable-schema-url-redirect` header to `true`
3 changes: 3 additions & 0 deletions packages/entity-renderer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ The default redirect query supports `http://www.w3.org/2011/http#` and `http://w
- `replace`: the string to replace with (optional, the default value will be the current hostname)
- `enableSchemaUrlRedirect` (experimental): If set to `true`, the plugin will perform a redirect if the URI contains a `schema:URL` predicate pointing to a resource of type `xsd:anyURI`.
The default value is `false`.
If enabled, the user can still disable this behavior by either:
- setting the `disableSchemaUrlRedirect` query parameter to `true`
- setting the `x-disable-schema-url-redirect` header to `true`

## Run an example instance

Expand Down
6 changes: 5 additions & 1 deletion packages/entity-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,16 @@ const factory = async (trifid) => {
const dataset = await rdf.dataset().import(quadStream)

if (mergedConfig.enableSchemaUrlRedirect && acceptHeader === 'text/html') {
const disabledSchemaUrlRedirect =
request.headers['x-disable-schema-url-redirect'] === 'true' ||
request.query.disableSchemaUrlRedirect === 'true'

// Get all triples that have a schema:URL property with value of type xsd:anyURI
const urls = []
dataset.match(iriUrlString, rdf.ns.schema.URL)
.filter(({ object }) => object.datatype.value === 'xsd:anyURI')
.map(({ object }) => urls.push(object.value))
if (urls.length > 0) {
if (!disabledSchemaUrlRedirect && urls.length > 0) {
const redirectUrl = urls[0]
logger.debug(`Redirecting to ${redirectUrl}`)
reply.redirect(redirectUrl)
Expand Down