Skip to content

feat(webdav): extract thumbnails through Tika - #3332

Open
dschmidt wants to merge 19 commits into
mainfrom
feat/thumbnails-raw-embedded-preview
Open

dschmidt wants to merge 19 commits into
mainfrom
feat/thumbnails-raw-embedded-preview

Conversation

@dschmidt

@dschmidt dschmidt commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Thumbnails for everything webdav should not decode in-process: raw camera images, audio cover art, the first page of a pdf, the metafile an office document carries, the icon of a windows binary. One generic step, no format-specific code.

Routing, typical setups and the cache are documented in the rendered webdav README.

webdav PUTs the file to Tika's /unpack/preset/thumbnail and hands the image on undecoded. The image is taken out of the answer by its type, not by what the package calls its own files, which Tika renamed once already (TIKA-4971).

Extraction happens once per file, not once per size. What an extractor makes of a file does not depend on the size that was asked for, so the extracted image is cached under one key per file, its checksum, and that entry is read before the file is even downloaded. The first requested size pays for the download and the extraction, every other size and every later request is scaled from the cached image, and an empty entry records that a file carries no image at all so Tika is never asked for it twice. The thumbnails themselves keep their own entry per size as before.

Tika has to run with the thumbnail catalog preset active, otherwise the route answers 404:

TIKA_PRESETS=thumbnail

That needs Tika 4.2.0 or newer. CI and the example deployment run apache/tika:4.2.0-SNAPSHOT-full until it is out.

With a Tika before 4.2.0 the same route is served once the preset is activated in its config file, which is what it takes there:

{ "server": { "port": 9998, "host": "0.0.0.0" }, "presets": { "thumbnail": true } }

Two size limits sit in front of the extraction, and they have to agree. WEBDAV_THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE (50 MB by default) gates every source before it is downloaded, the Tika path included, so an audiobook or a large PDF answers 403 until it is raised, although Tika would have had no trouble with it. Tika itself refuses a request body over maxRequestSizeBytes (1 GiB by default) with 413, which webdav reports as 404 and does not remember, so every request for such a file streams it to Tika again. Until TIKA-5025 (apache/tika#3519) lands, that limit can only be raised in Tika's config file, where the server block is then required:

{ "server": { "port": 9998, "host": "0.0.0.0", "maxRequestSizeBytes": 4294967296 }, "presets": { "thumbnail": true } }

Measured with three MPEG-4 audiobooks of 0.75, 1.07 and 1.46 GB: with the webdav limit at 2 GB and Tika's at 4 GiB all three give up their cover in 4 to 8 seconds, every later request comes from the cache.

Measured against 4.1.0 and a current 4.2.0 build: the same image for the same file, for documents, audio cover art, ebooks and raw photos, only the package it arrives in differs (4.2.0 wraps it in datapackage.json, rmeta.json and an unpacked/ directory), and this service takes the image by its type, not by its name. What 4.1.0 does not have are the raw formats added after it, an Epson .erf, an Olympus .orf and a Panasonic .rw2 carry no preview there and answer 404.

Which types go to Tika is a list, and the default is the formats a release serves a thumbnail for: documents, ebooks, office and iWork files, GeoGebra, audio cover art, windows binaries and the camera raws reva knows. OC_TIKA_THUMBNAIL_MIME_TYPES replaces that list, OC_TIKA_ADDITIONAL_THUMBNAIL_MIME_TYPES adds to it, a single * in either takes every type nothing else claims, and an empty list sends nothing, which leaves a Tika shared with the search service to the search service alone.

The camera raws are in the list for a reason: reva types them as images, and every type has exactly one taker, the first that applies. A type the Tika list names goes to Tika, an image too; then the built-in extractors take text, audio and GeoGebra; then an image goes to the generator as it is; then a * in the Tika list takes what is left; and anything else goes to the generator as it is, which answers whether it can read it (as it does on main since #3884). So * never sends an image: images belong to the generator, and sending one to Tika would only move the file. An image type only Tika can read has to be named in the Tika list. Announcing a type in OC_THUMBNAILS_ADDITIONAL_SOURCE_TYPES and naming it in the Tika list are separate decisions: the first is what oc:has-preview reports, the second says who makes the image.

On the webdav side this is the whole configuration:

OC_TIKA_URL=http://127.0.0.1:9996

# only decides what oc:has-preview announces, never what is extracted:
OC_THUMBNAILS_ADDITIONAL_SOURCE_TYPES=application/epub+zip,application/msword,application/octet-stream,\
application/pdf,application/vnd.apple.numbers,application/vnd.apple.pages,\
application/vnd.geogebra.file,application/vnd.geogebra.slides,application/vnd.ms-powerpoint,\
application/vnd.ms-xpsdocument,application/vnd.oasis.opendocument.presentation,\
application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.text,\
application/vnd.openxmlformats-officedocument.presentationml.presentation,\
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,\
application/vnd.openxmlformats-officedocument.wordprocessingml.document,\
application/x-msdownload,audio/mpeg,audio/ogg,audio/x-flac,audio/x-m4a,\
image/x-adobe-dng,image/x-canon-cr2,image/x-epson-erf,image/x-icon,image/x-nikon-nef,\
image/x-olympus-orf,image/x-pentax-pef,image/x-sony-arw,image/x-sony-sr2

OC_TIKA_URL alone gets the previews, the default list covers the formats; what the list above still buys is the announcement, until #3210 answers oc:has-preview from the index. Measured over the corpus (Tika's test documents, raw.pixls.us camera raws, generated audio and video), 37 of 40 files give up an image, the three that do not being a README, an xls whose thumbnail sits in an attachment and an ico, which the generator reads itself. application/octet-stream is in the announcement list above because reva reports it for iWork keynotes and, until the bumps land, for .m4b audiobooks and .azw3 ebooks; it is deliberately not in the Tika list, so those need reva to learn their types (opencloud-eu/reva#905 did it for RW2, opencloud-eu/reva#965 does audio/x-m4b and application/vnd.amazon.mobi8-ebook). audio/x-m4b is already in the Tika list here, so the audiobook covers work as soon as the reva bump arrives; .azw3 waits for a Tika that extracts Mobipocket covers (TIKA-5026, apache/tika#3520).

Icons and windows binaries map to png by default, since the jpeg fallback would turn transparency black. A file that carries no thumbnail answers 404, not 500.

What a client is told it can preview still comes from the static mime list, so these formats are reachable by direct request but not advertised. #3210 answers that from the index and is stacked on top.

Open: the source cache key

Notes from a read of ed740def, to be done in this PR before it merges. None of them changes the cache interface or the configuration.

  • Build the source key like the thumbnail key. sourceStorageKey used the raw checksum and no mime type, while thumbnailStorageKey hashes checksum + "\x00" + mimeType: the checksum comes from a remote PROPFIND on an OCM share and ends up as a path and an object key, and the type picks the extractor, so the same bytes under two types are not the same extraction (a copy of report.pdf saved as report.txt would otherwise hand the pdf the text rendering). Both keys now share one prefix function, so they cannot drift apart again (9ee07e9).
  • Put the extractor into the source key. Setting OC_TIKA_URL moves audio and GeoGebra from the built-in converters to Tika, and an empty answer from one must not stand in for the other. Each converter names itself (tika, oc-audio, oc-ggs, oc-ggp, oc-text) and the source entry is source-<name>. The empty entry per size is gone: whether a file has an image does not depend on the size, so only the source entry records it (79fe3b2).
  • Follow-up: the master's content type. Tika tells us the type of the image it extracted, but the cache only stores bytes, so a cache hit has lost it and falls back to http.DetectContentType. The type belongs next to the bytes, together with the Tika version below. How is open: a header in the value works the same in every backend, a sibling entry or native metadata (xattrs, S3 object metadata) keep the image a plain file but cost a second read or an interface change. A new key suffix for the source entry keeps any of them additive, old entries are simply not found and extracted once more.
  • Minor: rememberSource also checked maxInputSize, which only kept a source out of the cache when the input limit was set below 8 MB, and then made every further size extract again; maxCachedSourceBytes alone bounds what is kept (4fb37e9).

Limitation: the Tika version is not tracked. The key cannot carry it, because the lookup happens before anyone asks Tika which version it is. A file Tika had no preview for (ERF, ORF and RW2 before 4.2) keeps its empty entry after an upgrade until the cache is emptied, as the README says. The fix is to store the extractor's version next to the bytes, so an empty answer from an older version is retried. That fits with storing the content type above, since both need metadata next to the bytes, and is left for a follow-up.

Not for this PR: the input size check in statSource runs before the source cache is read, and the converters read the whole file into memory. Both are right for what this PR extracts and would have to change for video, where the master would sit in the cache while the file itself is far above any sensible input limit.

@codacy-production

codacy-production Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 4 critical

Alerts:
⚠ 4 issues (≤ 0 issues of at least minor severity)

Results:
4 new issues

Category Results
Security 4 critical

View in Codacy

🟢 Metrics 106 complexity

Metric Results
Complexity 106

View in Codacy

🟢 Coverage 80.70% diff coverage

Metric Results
Coverage variation Report missing for 413082e1
Diff coverage ✅ 80.70% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (413082e) Report Missing Report Missing Report Missing
Head commit (4fb37e9) 93639 26999 28.83%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3332) 228 184 80.70%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@dschmidt dschmidt changed the title feat(thumbnails): serve the embedded jpeg preview of nikon raw files feat(thumbnails): serve the embedded jpeg preview of raw files Aug 18, 2026
@dschmidt
dschmidt marked this pull request as ready for review August 18, 2026 12:58
@dschmidt
dschmidt force-pushed the feat/thumbnails-raw-embedded-preview branch 2 times, most recently from 4043342 to 47a7136 Compare August 19, 2026 05:31
@dschmidt
dschmidt requested a balanced review from Copilot August 19, 2026 08:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds embedded JPEG preview extraction for TIFF-based camera RAW thumbnails.

Changes:

  • Adds RAW MIME routing and documentation.
  • Implements bounded TIFF/BigTIFF preview extraction with EXIF orientation.
  • Adds extraction, hardening, orientation, and decoder tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
services/thumbnails/README.md Documents RAW thumbnail support.
pkg/thumbnail/mimetypes.go Registers RAW MIME types.
pkg/thumbnail/mimetypes_vips.go Registers RAW types for VIPS.
pkg/service/grpc/v0/service.go Handles missing RAW previews quietly.
pkg/preprocessor/rawtiff.go Extracts and validates embedded JPEGs.
pkg/preprocessor/rawtiff_test.go Tests RAW extraction and hardening.
pkg/preprocessor/preprocessor.go Routes RAW types to the decoder.
pkg/preprocessor/preprocessor_test.go Tests RAW MIME routing.
pkg/errors/error.go Adds the missing-preview error.
Suppressed comments (4)

services/thumbnails/pkg/preprocessor/rawtiff.go:142

  • This bounds check can overflow before it checks the untrusted BigTIFF offset. For example, a first-IFD offset near MaxUint64 makes ifdOffset + 8 wrap below dlen, after which the slice on line 147 panics. Use subtraction-based bounds checks (or explicit overflow checks) before slicing so a crafted raw upload cannot crash the service.
		if ifdOffset == 0 || ifdOffset+uint64(countSize) > dlen {

services/thumbnails/pkg/preprocessor/rawtiff.go:204

  • arrayOffset is file-controlled, so both additions here can wrap. With an offset near MaxUint64, pos + offW becomes a small number and passes the check, then data[pos:] panics. Reject offsets using subtraction/overflow-safe bounds checks before reading the SubIFD array.
					pos := arrayOffset + j*uint64(offW)
					if pos+uint64(offW) > dlen || len(queue) >= maxIFDs {

services/thumbnails/pkg/preprocessor/rawtiff.go:117

  • BigTIFF widens the entry value field, but accepted LONG values are still 4 bytes. Reading every BigTIFF field as Uint64 misreads a big-endian inline LONG as value << 32; the 8-byte stride used later also misreads LONG SubIFD lists. Decode values and array strides from typ, not only from the container, otherwise valid big-endian BigTIFF/DNG previews are missed.
	// readOff reads a 4- or 8-byte offset/value depending on the container.
	readOff := func(b []byte) uint64 {
		if bigTiff {
			return order.Uint64(b[:8])
		}
		return uint64(order.Uint32(b[:4]))
	}

services/thumbnails/pkg/preprocessor/rawtiff.go:261

  • Returning true immediately on a DCT SOF marker does not establish that the JPEG is renderable: the SOF length may be invalid, or the stream may be truncated before any scan. Because extraction keeps only the largest candidate, a larger corrupt candidate can then mask a valid smaller preview and make Convert fail instead of falling back. Validate enough of the stream to reject malformed candidates, or try candidates in size order until one decodes.
		case 0xc0, 0xc1, 0xc2: // baseline, extended sequential, progressive
			return true

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

dschmidt added a commit that referenced this pull request Aug 19, 2026
… width

Review of #3332 surfaced two BigTIFF-only defects in the embedded-preview
walker (attacker-controlled input):

- 64-bit IFD and SubIFD-array offsets were bounds-checked with `off + n > len`,
  which wraps for a crafted offset near 2^64, bypassing the guard and slicing
  out of range -> panic (recovered by the framework into a 500 + stack log on
  every crafted request, defeating the no-panic goal). Now overflow-safe.
- a tag value was always read as an 8-byte Uint64 in BigTIFF; a LONG (4-byte)
  offset in a big-endian BigTIFF was thereby shifted. Read it at its declared
  type width instead.

Adds tests for the overflow paths (assert ErrNoImageFromRawFile, no panic),
the big-endian LONG offset, and strengthens the truncation test to assert the
error. Trims a few over-long comments.
@dschmidt
dschmidt requested a balanced review from Copilot August 19, 2026 09:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (3)

services/thumbnails/pkg/preprocessor/rawtiff.go:201

  • SubIFD pointers may use TIFF type IFD (13) and BigTIFF type IFD8 (18), but isLongType accepts only LONG/LONG8, so valid preview-bearing SubIFDs using the pointer-specific types are skipped. Extend the type-width/read helpers to accept IFD/IFD8; otherwise such DNG/BigTIFF files incorrectly report no preview.
			case tiffTagSubIFDs:
				if !isLongType(typ, bigTiff) {
					continue

services/thumbnails/pkg/preprocessor/rawtiff.go:221

  • In BigTIFF the value-or-offset field is 8 bytes, so a SubIFDs value containing exactly two LONG offsets is stored inline. Treating every count > 1 value as an array pointer interprets those two offsets as one bogus uint64 file offset and misses both preview IFDs.
				// count > 1: the value field points at an array of count offsets,
				// each of the tag's own width (LONG 4B, LONG8 8B)
				arrayOffset := readOff(entry[valAt:])

services/thumbnails/pkg/preprocessor/rawtiff.go:196

  • Valid TIFF encodes both StripOffsets and StripByteCounts as either SHORT or LONG, but these guards reject SHORT. A raw file whose only embedded JPEG is a single strip using SHORT values will therefore produce ErrNoImageFromRawFile. Please read scalar SHORT values as 16-bit values for both tags (and add a regression case).
				if isLongType(typ, bigTiff) && count == 1 {
					stripOffset = readVal(entry[valAt:], typ)
				}
			case tiffTagStripByteCounts:
				if isLongType(typ, bigTiff) && count == 1 {

@rhafer rhafer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As much as I'd like to have previews for my raw images (DNG in my case), I'd really prefer us to get not into the business of creating/maintaining a TIFF parser (even with the help of AI). Especially given the experience with the recent security flaws in libvips (which were also TIFF related).

I see your PR to evanoberholster/imagemeta got merged. So using that might help.

And then there is #1128 which suggests to replace the embedded thumbnailer with something like https://github.com/cshum/imagor for better scalability and broader images format support. (Unfortunately AFAICS imagor does not extract the embedded previews though, but tries to render the rawdata)

I am not giving this a 👎 , but I think we should not merge without further consideration.

@butonic any thoughts on this?

@dschmidt

Copy link
Copy Markdown
Contributor Author

Thanks for the considerate review, @rhafer :)

One more idea - tika has a concept of embedded files. I've already implemented audio artwork support using that mechanism.
Currently I'm trying to get the jpeg extraction from raw tiff into tika as well: apache/tika#3037

I mainly wanted both extractions to implement the thumbnails relationship on driveItems, but thinking about it in the context of your concerns and the possible move to imagor it makes me think:

We could pipe audio files and raw images from the thumbnails service to tika for preview extraction.
If that works out well enough, it could be a blueprint for piping regular images to imagor (or to whatever image server else).
This would even rid us of the vendored https://github.com/dhowden/tag (which seems dead and I had to patch and fork for #3208).

Having implemented the original audio artwork thumbnails feature, I can say I'd happily drop the built in support for something more maintained like tika. Moreover, we'd use the same mechanism as in the search service and the supported file formats and features would always align (unlike with a completely different code path like right now).

Thoughts?

@dschmidt

Copy link
Copy Markdown
Contributor Author

I liked my idea so much, that I immediately wanted to give it a spin 😁

+395 now, the built in approach had +936 - I'm satisfied :D
Main downside, we need to wait for the tika upstream pr and a release :)
... but I'm patient, you know ... ;-)

What do you think?

@dschmidt

Copy link
Copy Markdown
Contributor Author

Tika PR is merged 🙂

@dschmidt
dschmidt force-pushed the feat/thumbnails-raw-embedded-preview branch from 4ba384f to 0d0a6a6 Compare August 30, 2026 11:47
@dschmidt dschmidt changed the title feat(thumbnails): serve the embedded jpeg preview of raw files feat(webdav): thumbnails through a Tika server Aug 30, 2026
@dschmidt
dschmidt marked this pull request as draft August 30, 2026 11:48
@dschmidt
dschmidt changed the base branch from main to imagor August 30, 2026 11:49
@dschmidt
dschmidt force-pushed the feat/thumbnails-raw-embedded-preview branch from 0d0a6a6 to 9ac2bc4 Compare August 30, 2026 11:51
@dschmidt dschmidt changed the title feat(webdav): thumbnails through a Tika server feat(webdav): extract thumbnails through a Tika server Aug 30, 2026
@dschmidt
dschmidt force-pushed the feat/thumbnails-raw-embedded-preview branch 4 times, most recently from 05072f1 to 92a183b Compare August 30, 2026 11:57
Every file the built-in converters cannot render goes to /unpack/thumbnail
(Tika 4.1) and comes back with the image Tika marks as its thumbnail.
Tika merged the thumbnail catalog preset and ThumbnailUnpackSelector
(TIKA-4856): PUT /unpack/preset/thumbnail returns exactly the one raster
image a client would show for the document, a stored thumbnail, the
rendering of a metafile thumbnail, or the rendered first page. The
client-side selection over /unpack/all (embedded-resource-type marks,
metafile renderings, id-path matching) moves to the server; the preset
zip carries one image without metadata sidecars, so the entry's
extension names the type and the bytes break the tie. The preset has to
be active, so this needs a Tika 4.2.0 or newer started with
TIKA_PRESETS=thumbnail, and a 404 says so.
PUT /unpack/preset/thumbnail answers 404 unless the thumbnail catalog preset is
active, and the thumbnailer then finds no thumbnail for any document.
TIKA_PRESETS=thumbnail activates it and needs Tika 4.2.0, so the acceptance
stack and the example deployment follow the snapshot image until the release is
out. The deployment also reads the shared OC_TIKA_URL so the thumbnailer uses
the Tika that is already there.
The cache key is derived from configuration again: a thumbnail is written in
the type the file's own type maps to, so the answer no longer depends on what
Tika hands back and needs no placeholder in the key.

Which types Tika gets is decided in one place now. An image type goes to Tika
only when a deployment names it, because the generator behind the URL may read
it itself, which also lets a raw photo reach Tika at all.
What an extractor makes of a file does not depend on the size that was asked
for, so it is kept under one key per file and read before the file is even
downloaded. An empty entry says the file carries nothing, which keeps the
next size from asking Tika again; a failed extraction is not remembered. The
file cache now replaces what a key holds, as the other two backends already
did, because an entry whose value can change has to be replaceable.
Both answer with the same image for the same file, only the package differs, and a 4.1.x server has no preview for erf, orf and rw2. The 404 now names both ways to activate the preset.
The catch-all was hidden in NewTika, so neither the yaml nor the env documentation showed it. It is a plain default now, like the CORS origins, and an empty list means what it says: nothing goes to Tika, and the server behind OC_TIKA_URL stays the search service's.
The type decides which parser reads the file, so a raw photo that Tika only detected as a plain tiff is parsed as a tiff and its embedded preview is never found. No shipped format needs the hint, which is why the knob reads like dead code and has to say that it is not.
ForType decided by the name of the type: anything starting with image/ was
handed to the generator, and no converter meant handing it over as well. A
camera raw is an image by that rule, so it travelled to a generator that cannot
read it, and an announced pdf travelled there too. It now asks in one order who
claims the file: a type the Tika list names, an image the generator reads, a
converter here, a catch-all, and otherwise nobody, which answers 404 before the
file is read at all.

The Tika list carries the formats a release serves a thumbnail for, the camera
raws among them, and the default config hands it in, so an empty list still
means nothing goes to Tika and a shared server stays the search service's.
OC_TIKA_ADDITIONAL_THUMBNAIL_MIME_TYPES adds to it.
…eilings in writing

The description said an empty list leaves the built-in list in place, which is
what an unset variable does; an explicitly empty one sends nothing. And a ladder
that reaches past the generator's output ceiling asks for a box the generator
refuses, which nothing checks for us, so the thumbnails README says it.
A named Tika type goes to Tika, then the built-in converters, then images
to the generator, then the rest to Tika under "*" or to the generator.
"*" never sends an image, which only moved the file to come back empty,
and an announced type without a converter reaches the generator again, as
it does on main since the generator pass-through.
Comment thread services/webdav/README.md Outdated

So `*` never sends an image: images belong to the generator, and sending one to Tika would only move the file. An image type that only Tika can read has to be named in the Tika list. Announcing a type in `OC_THUMBNAILS_ADDITIONAL_SOURCE_TYPES` and sending it to Tika are separate decisions: the announcement is what `oc:has-preview` reports, the Tika list says who makes the image. Naming a type also restricts Tika to the named ones, so a deployment that sends raw photos to Tika has to name the document types it wants from Tika as well, and an empty list sends nothing at all, which leaves the Tika server to the search service alone. The thumbnail is written in the type the **file's** own type maps to (`OC_THUMBNAILS_ADDITIONAL_OUTPUT_TYPES`), not in whatever type Tika hands back, so the answer is the same before and after a cache hit. That is also why a windows binary is mapped to `image/png` by default: the icon Tika reads out of it carries transparency that a JPEG would flatten onto black.

Generated thumbnails are cached by the webdav service itself. The cache backend defaults to `file`, storing entries under `$OC_BASE_DATA_PATH/thumbnails/cache` (override with `WEBDAV_THUMBNAILS_CACHE_BACKEND` and `WEBDAV_THUMBNAILS_CACHE_DIR`). Use the `s3` backend when running multiple instances behind a load balancer so they share one cache. A backend nobody can serve, an unknown name or an `s3` backend without bucket, region and credentials, fails at startup instead of serving without a cache, as long as previews are enabled. A service that is not AWS needs `WEBDAV_THUMBNAILS_CACHE_S3_ENDPOINT` too, and it is always addressed over https. The `memory` backend is bounded and drops its oldest entries; `none` disables caching on purpose. The cache also keeps the image an extractor made of a file, under one entry per file, so a second size does not extract again and a file that carries no image is only asked once. Nothing expires: a changed file is a new entry because the key carries its checksum, but an extractor that learns to read a format it could not read before does not reach the files it already answered for. After such an upgrade, an Apache Tika release among them, empty the cache (`WEBDAV_THUMBNAILS_CACHE_DIR`, or the bucket) to have them asked again.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite the wall of dense text. This last "caching" paragraph especially caould proably be use subsections for the different options.

Comment thread services/webdav/README.md Outdated
When `OC_TIKA_URL` (or `WEBDAV_TIKA_URL`) is set, an Apache Tika server (4.2.0 or newer) supplies the preview image for documents, raw photos, audio cover art and other types. Which types go there is a list, and the default is the formats a Tika release serves a thumbnail for: documents, ebooks, office and iWork files, audio cover art and the camera raws. `OC_TIKA_THUMBNAIL_MIME_TYPES` (or `WEBDAV_TIKA_THUMBNAIL_MIME_TYPES`) replaces that list, `OC_TIKA_ADDITIONAL_THUMBNAIL_MIME_TYPES` adds to it, a single `*` in either sends every type that nothing else claims, and an empty list sends nothing at all, which leaves a Tika server shared with the search service to the search service alone. An entry like `image/x-nikon-nef:image/x-raw-nikon` maps a type to the one Tika knows the format by. Tika takes a declared type only when it refines what it detected itself, so an entry pins the leaf type its detector left at the parent, a raw photo it only read as a plain tiff. The type decides which parser reads the file: a raw read as a tiff is parsed as a tiff, its maker notes stay unread, and the embedded preview a thumbnail would be made of is never found. The formats in the default list are detected down to the leaf type, so none of them needs the hint, and it is there for the next format whose detection stops one level short. The webdav service calls `PUT /unpack/preset/thumbnail`, so the Tika server has to run with the `thumbnail` catalog preset active: start it with `TIKA_PRESETS=thumbnail`, a comma separated list of the presets to activate. Without Tika, audio cover art and GeoGebra thumbnails are still extracted by the webdav service itself; those built-in extractors are deprecated. A type Tika takes is attempted even when `OC_THUMBNAILS_ADDITIONAL_SOURCE_TYPES` does not announce it, so a direct request can get a preview that a listing reports as absent. Who gets a file is decided in one order, first match wins, and every type has exactly one taker:

1. a type the Tika list names goes to Tika, an image too, which is why the camera raws are named there: reva types them as images and no generator reads them
2. text, audio and GeoGebra go to the built-in extractors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should drop the in process extractors ... I really don't want to look at bytes in the webdav service. The idea of the thumbnails service is that it is a drop in replacement for imagor in case there is a security issue in vips, so there are at least some thumbnails. Production deployments can then just deploy the thumbnails service standalone as a replacement for imagor. maybe we can move the built in extractors to a tika drop in as well? or just add a handler to the thumbnails service that acts like tika? That way we can disable the built in extractors when tika is used and use a fallback otherwise.

@dschmidt what do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fully agree with getting rid of the in process extractors.

To be honest, I would just like to drop these code paths from OpenCloud.
Then if we switch off Tika or just never enable it we/users lose GeoGebra and Audio thumbnails - I think that's really not too bad. I love them as a feature, but it really doesn't stop me from working with OpenCloud if I don't have it - especially not temporarily - so I think it's reasonable to say: if you want those and 30 other preview formats, just use Tika.

What I can do tho is to check Tika turned off doesn't cache "no preview" permanently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you insist, I would move the in process extractors to the thumbnails service instead of to a new service, but honestly I don't think it's worth the effort at all.
And same as the Imagor refactor needing an Imagor URL in a distributed setup, this would still be a breaking change. I'd argue if we do a breaking change anyhow, let's get rid of it completely.

If you like I can try to upstream the text rendering to Tika as well, so we get rid of that too.

Comment thread services/webdav/README.md Outdated
The webdav service provides various `GET` endpoints to get the thumbnails of a file in authenticated and unauthenticated contexts. It also provides thumbnails for spaces on different endpoints.

Generated thumbnails are cached by the webdav service itself. The cache backend defaults to `file`, storing entries under `$OC_BASE_DATA_PATH/thumbnails/cache` (override with `WEBDAV_THUMBNAILS_CACHE_BACKEND` and `WEBDAV_THUMBNAILS_CACHE_DIR`). Use the `s3` backend when running multiple instances behind a load balancer so they share one cache. A backend nobody can serve, an unknown name or an `s3` backend without bucket, region and credentials, fails at startup instead of serving without a cache, as long as previews are enabled. A service that is not AWS needs `WEBDAV_THUMBNAILS_CACHE_S3_ENDPOINT` too, and it is always addressed over https. The `memory` backend is bounded and drops its oldest entries; `none` disables caching on purpose.
When `OC_TIKA_URL` (or `WEBDAV_TIKA_URL`) is set, an Apache Tika server (4.2.0 or newer) supplies the preview image for documents, raw photos, audio cover art and other types. Which types go there is a list, and the default is the formats a Tika release serves a thumbnail for: documents, ebooks, office and iWork files, audio cover art and the camera raws. `OC_TIKA_THUMBNAIL_MIME_TYPES` (or `WEBDAV_TIKA_THUMBNAIL_MIME_TYPES`) replaces that list, `OC_TIKA_ADDITIONAL_THUMBNAIL_MIME_TYPES` adds to it, a single `*` in either sends every type that nothing else claims, and an empty list sends nothing at all, which leaves a Tika server shared with the search service to the search service alone. An entry like `image/x-nikon-nef:image/x-raw-nikon` maps a type to the one Tika knows the format by. Tika takes a declared type only when it refines what it detected itself, so an entry pins the leaf type its detector left at the parent, a raw photo it only read as a plain tiff. The type decides which parser reads the file: a raw read as a tiff is parsed as a tiff, its maker notes stay unread, and the embedded preview a thumbnail would be made of is never found. The formats in the default list are detected down to the leaf type, so none of them needs the hint, and it is there for the next format whose detection stops one level short. The webdav service calls `PUT /unpack/preset/thumbnail`, so the Tika server has to run with the `thumbnail` catalog preset active: start it with `TIKA_PRESETS=thumbnail`, a comma separated list of the presets to activate. Without Tika, audio cover art and GeoGebra thumbnails are still extracted by the webdav service itself; those built-in extractors are deprecated. A type Tika takes is attempted even when `OC_THUMBNAILS_ADDITIONAL_SOURCE_TYPES` does not announce it, so a direct request can get a preview that a listing reports as absent. Who gets a file is decided in one order, first match wins, and every type has exactly one taker:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow the logic makes my head hurt ... can you document this with examples for typical scenarios?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

4 participants