dbmdz / iiif-server-hymir

Hymir is a Java based IIIF Server. It is based on "IIIF Image API Java Libraries" and "IIIF Presentation API Java Libraries" projects (see https://github.com/dbmdz)
MIT License
27 stars 7 forks source link

Image IDs containing urlencoded characters or '/' fail to be served #11

Closed somnolik closed 6 years ago

somnolik commented 6 years ago

The same behaviour occurs with other urlencoded characters like '(' (%28) or ')' (%29). I'm aware that directly including the character '/' in the ID is forbidden per IIIF Image API; some other IIIF-Servers support it though.

Is there currently a way in Hymir to serve images in arbitrarily deep directory structures without explicitly enumerating each subdirectory?

datazuul commented 6 years ago

you could try a safe identifier and matching it using regular expressions to your path. see https://github.com/dbmdz/iiif-server-hymir/blob/master/src/main/resources/de/digitalcollections/core/config/multiPatternResolving-PROD.yml

something like this: identifier "images-set01-01" could be matched by a regular expression using groups

maybe you have to write one regex for each directory depthness (number of "-" hyphens)...

Could this work for you?

somnolik commented 6 years ago

Yes, thank you, this is a suitable workaround. For future reference, this is the regex pattern we use, with double hyphens '--' as substitution for forward slashes, no hyphens allowed within the path, and file extensions with 3 or 4 letters, digits or underscore:

- pattern: ^([^-/]+)\.(\w{3,4})$
  substitutions:
    - 'file:/images/$1.$2'

- pattern: ^([^-/]+)(?:--)([^-/]+)\.(\w{3,4})$
  substitutions:
    - 'file:/images/$1/$2.$3'

- pattern: ^([^-/]+)(?:--)([^-/]+)(?:--)([^-/]+)\.(\w{3,4})$
  substitutions:
    - 'file:/images/$1/$2/$3.$4'

# iterate as needed

Example identifier: 1874--18740501--page0004.jpg which would be mapped to 1874/18740501/page0004.jpg