mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-12-05 22:46:09 -05:00
refactor(webdav): keep the Tika type default in the default config
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.
This commit is contained in:
1 parent
31b6cf6bd9
commit
f24659fdf4
6 files changed
+14
-11
No files matched your search
@@ -10,7 +10,7 @@ Currently, the webdav service handles request for two functionalities, which are
|
||||
|
||||
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.
|
||||
|
||||
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. Every file that is not a directly supported image is sent to Tika; `OC_TIKA_THUMBNAIL_MIME_TYPES` (or `WEBDAV_TIKA_THUMBNAIL_MIME_TYPES`) restricts that to a list of mime types, where 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 a subtype its detector left at the parent type, a raw photo it only read as a tiff. 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. An image type is only sent to Tika when the list names it, because the generator behind the URL may read it itself, an imagor with ImageMagick reads heic where the built-in one does not. 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. 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.
|
||||
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. Every file that is not a directly supported image is sent to Tika, which is what the default `*` in `OC_TIKA_THUMBNAIL_MIME_TYPES` (or `WEBDAV_TIKA_THUMBNAIL_MIME_TYPES`) says. That setting restricts it to a list of mime types instead, where 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 a subtype its detector left at the parent type, a raw photo it only read as a tiff. 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. An image type is only sent to Tika when the list names it, because the generator behind the URL may read it itself, an imagor with ImageMagick reads heic where the built-in one does not. 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.
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ type Config struct {
|
||||
Thumbnails Thumbnails `yaml:"thumbnails"`
|
||||
|
||||
TikaURL string `yaml:"tika_url" env:"OC_TIKA_URL;WEBDAV_TIKA_URL" desc:"URL of an Apache Tika server. When set, thumbnails are generated for documents, raw photos, audio cover art and other formats Tika can extract a preview from. Needs Tika 4.2.0 or newer, started with TIKA_PRESETS=thumbnail. A 4.1.x server works as well, with the preset activated in its config file instead." introductionVersion:"%%NEXT%%"`
|
||||
TikaThumbnailMimeTypes []string `yaml:"tika_thumbnail_mime_types" env:"OC_TIKA_THUMBNAIL_MIME_TYPES;WEBDAV_TIKA_THUMBNAIL_MIME_TYPES" desc:"Restrict thumbnail generation via Tika to these mime types. Empty means all types that are not handled directly. An entry can map a type to the one Tika knows the format by, e.g. image/x-nikon-nef:image/x-raw-nikon. Tika takes a declared type only when it refines what it detected itself, so an entry pins a subtype its detector left at the parent type, a raw photo it only read as a tiff." introductionVersion:"%%NEXT%%"`
|
||||
TikaThumbnailMimeTypes []string `yaml:"tika_thumbnail_mime_types" env:"OC_TIKA_THUMBNAIL_MIME_TYPES;WEBDAV_TIKA_THUMBNAIL_MIME_TYPES" desc:"Restrict thumbnail generation via Tika to these mime types. The default, a single '*', sends every type that is not handled directly and lets Tika decide; an empty list sends nothing, which leaves the Tika server behind OC_TIKA_URL to the search service alone. An entry can map a type to the one Tika knows the format by, e.g. image/x-nikon-nef:image/x-raw-nikon. Tika takes a declared type only when it refines what it detected itself, so an entry pins a subtype its detector left at the parent type, a raw photo it only read as a tiff." introductionVersion:"%%NEXT%%"`
|
||||
|
||||
Context context.Context `yaml:"-"`
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ func DefaultConfig() *config.Config {
|
||||
WebdavNamespace: "/users/{{.Id.OpaqueId}}",
|
||||
RevaGateway: shared.DefaultRevaConfig().Address,
|
||||
|
||||
TikaThumbnailMimeTypes: []string{"*"},
|
||||
|
||||
Thumbnails: config.Thumbnails{
|
||||
GeneratorURL: "http://127.0.0.1:9186",
|
||||
GeneratorTimeout: "30s",
|
||||
|
||||
@@ -139,7 +139,7 @@ var _ = Describe("TikaThumbnail", func() {
|
||||
|
||||
var _ = Describe("ForType with a Tika server", func() {
|
||||
It("routes everything Tika is asked for to Tika, text and gif stay native", func() {
|
||||
opts := Options{Tika: thumbnail.NewTika("http://tika:9998", nil), Filename: "song.mp3"}
|
||||
opts := Options{Tika: thumbnail.NewTika("http://tika:9998", []string{"*"}), Filename: "song.mp3"}
|
||||
Expect(ForType("audio/mpeg", opts)).To(BeAssignableToTypeOf(TikaThumbnail{}))
|
||||
Expect(ForType("application/vnd.geogebra.slides", opts)).To(BeAssignableToTypeOf(TikaThumbnail{}))
|
||||
Expect(ForType("application/pdf", opts)).To(BeAssignableToTypeOf(TikaThumbnail{}))
|
||||
|
||||
@@ -7,14 +7,15 @@ import (
|
||||
|
||||
// Tika is the configured Tika server: its URL and the types it is asked for.
|
||||
// It only decides which file goes there, the call lives in the preprocessor.
|
||||
// By default every non-image file is sent and Tika decides.
|
||||
// The default list is a single "*", so every non-image file is sent and Tika
|
||||
// decides; a list that names types restricts it, an empty one sends nothing.
|
||||
type Tika struct {
|
||||
URL string
|
||||
// our mime type -> Tika's, "" when equal; "*" means every type
|
||||
mimeTypes map[string]string
|
||||
}
|
||||
|
||||
// NewTika parses "mime[:tika-mime]" entries; empty means every type.
|
||||
// NewTika parses "mime[:tika-mime]" entries, "*" being every type.
|
||||
func NewTika(url string, mimeTypes []string) Tika {
|
||||
t := Tika{URL: url, mimeTypes: map[string]string{}}
|
||||
for _, entry := range mimeTypes {
|
||||
@@ -23,9 +24,7 @@ func NewTika(url string, mimeTypes []string) Tika {
|
||||
t.mimeTypes[ours] = strings.TrimSpace(theirs)
|
||||
}
|
||||
}
|
||||
if len(t.mimeTypes) == 0 {
|
||||
t.mimeTypes["*"] = ""
|
||||
}
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ import (
|
||||
|
||||
var _ = Describe("Tika", func() {
|
||||
none := thumbnail.NewTika("", nil)
|
||||
all := thumbnail.NewTika("http://tika:9998", nil)
|
||||
all := thumbnail.NewTika("http://tika:9998", []string{"*"})
|
||||
nothing := thumbnail.NewTika("http://tika:9998", nil)
|
||||
some := thumbnail.NewTika("http://tika:9998", []string{" Application/PDF ", "audio/mpeg", "image/x-nikon-nef:image/x-raw-nikon"})
|
||||
|
||||
DescribeTable("Supports",
|
||||
@@ -17,7 +18,8 @@ var _ = Describe("Tika", func() {
|
||||
Expect(tika.Supports(mimeType)).To(Equal(want))
|
||||
},
|
||||
Entry("nothing without a server", none, "application/pdf", false),
|
||||
Entry("everything by default", all, "application/x-anything; charset=binary", true),
|
||||
Entry("nothing with an empty list", nothing, "application/pdf", false),
|
||||
Entry("everything with the default list", all, "application/x-anything; charset=binary", true),
|
||||
Entry("but no directories", all, "httpd/unix-directory", false),
|
||||
Entry("nor an unparsable type", all, "not a mime", false),
|
||||
Entry("a listed type", some, "application/pdf", true),
|
||||
@@ -32,6 +34,6 @@ var _ = Describe("Tika", func() {
|
||||
},
|
||||
Entry("maps a type to the one Tika knows", some, "image/x-nikon-nef", "image/x-raw-nikon"),
|
||||
Entry("passes an unmapped type through, without parameters", some, "application/pdf; charset=binary", "application/pdf"),
|
||||
Entry("passes everything through by default", all, "audio/mpeg", "audio/mpeg"),
|
||||
Entry("passes everything through with the default list", all, "audio/mpeg", "audio/mpeg"),
|
||||
)
|
||||
})
|
||||
Reference in new issue
Block a user