From 46982c265acb4db2cc1b151e7c75b7dfd060c2e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Fri, 23 Oct 2026 14:18:36 +0200 Subject: [PATCH] Read the thumbnail input size limit in the same order as the generator With both the old and the new name set, webdav and the thumbnails service picked different values. --- services/webdav/MIGRATION.md | 2 +- services/webdav/pkg/config/config.go | 2 +- .../webdav/pkg/config/parser/parse_test.go | 48 +++++++++++++++++++ .../pkg/config/parser/parser_suite_test.go | 16 +++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 services/webdav/pkg/config/parser/parse_test.go create mode 100644 services/webdav/pkg/config/parser/parser_suite_test.go diff --git a/services/webdav/MIGRATION.md b/services/webdav/MIGRATION.md index 05dd70a34e..c7925175d5 100644 --- a/services/webdav/MIGRATION.md +++ b/services/webdav/MIGRATION.md @@ -30,7 +30,7 @@ Nothing has to be set in the single binary. The URL may also point at a real | Old name | Now | | | --- | --- | --- | | `THUMBNAILS_RESOLUTIONS` | `WEBDAV_THUMBNAILS_RESOLUTIONS` | a ladder of edge lengths, not a list of boxes | -| `THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE` | `OC_THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE` | read by webdav and the generator, which have to agree | +| `THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE` | `OC_THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE` | read by webdav and the generator, which have to agree; the old name still wins over the new one in both, so drop it when setting the new one | | `THUMBNAILS_TXT_FONTMAP_FILE` | `WEBDAV_THUMBNAILS_TXT_FONTMAP_FILE` | webdav renders text before it posts | | `THUMBNAILS_FILESYSTEMSTORAGE_ROOT` | `WEBDAV_THUMBNAILS_CACHE_DIR` | the old name is the directory that holds `files/`, the new one is the directory itself | diff --git a/services/webdav/pkg/config/config.go b/services/webdav/pkg/config/config.go index 43eabeeddb..4a0b1a80aa 100644 --- a/services/webdav/pkg/config/config.go +++ b/services/webdav/pkg/config/config.go @@ -38,7 +38,7 @@ type Config struct { type Thumbnails struct { GeneratorURL string `yaml:"generator_url" env:"WEBDAV_THUMBNAILS_GENERATOR_URL" desc:"Base URL of the thumbnail generator service, e.g. http://thumbnails:9186" introductionVersion:"%%NEXT%%"` GeneratorTimeout string `yaml:"generator_timeout" env:"WEBDAV_THUMBNAILS_GENERATOR_TIMEOUT" desc:"HTTP timeout for requests to the thumbnail generator, e.g. 30s" introductionVersion:"%%NEXT%%"` - MaxInputFileSize string `yaml:"max_input_image_file_size" env:"THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE;OC_THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE;WEBDAV_THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE" desc:"Maximum file size of an input image a thumbnail is made of. The generator refuses a larger body, so both read the same name by default. Usable common abbreviations: [KB, KiB, MB, MiB, GB, GiB], example: 50MB" introductionVersion:"%%NEXT%%"` + MaxInputFileSize string `yaml:"max_input_image_file_size" env:"OC_THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE;THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE;WEBDAV_THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE" desc:"Maximum file size of an input image a thumbnail is made of. The generator refuses a larger body, so both read the same name by default. Usable common abbreviations: [KB, KiB, MB, MiB, GB, GiB], example: 50MB" introductionVersion:"%%NEXT%%"` CacheBackend string `yaml:"cache_backend" env:"WEBDAV_THUMBNAILS_CACHE_BACKEND" desc:"Cache backend for imagor thumbnails: 'none', 'memory', 'file', or 's3'. Default: file." introductionVersion:"%%NEXT%%"` CacheDir string `yaml:"cache_dir" env:"WEBDAV_THUMBNAILS_CACHE_DIR" desc:"Directory for file-based thumbnail cache (Default: $OC_BASE_DATA_PATH/thumbnails/files). Only used when WEBDAV_THUMBNAILS_CACHE_BACKEND is 'file'." introductionVersion:"%%NEXT%%"` diff --git a/services/webdav/pkg/config/parser/parse_test.go b/services/webdav/pkg/config/parser/parse_test.go new file mode 100644 index 0000000000..475c3222e9 --- /dev/null +++ b/services/webdav/pkg/config/parser/parse_test.go @@ -0,0 +1,48 @@ +// Copyright 2026 OpenCloud GmbH +// SPDX-License-Identifier: Apache-2.0 + +package parser_test + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + thumbnailsdefaults "github.com/opencloud-eu/opencloud/services/thumbnails/pkg/config/defaults" + thumbnailsparser "github.com/opencloud-eu/opencloud/services/thumbnails/pkg/config/parser" + "github.com/opencloud-eu/opencloud/services/webdav/pkg/config/defaults" + "github.com/opencloud-eu/opencloud/services/webdav/pkg/config/parser" +) + +var _ = Describe("ParseConfig", func() { + BeforeEach(func() { + GinkgoT().Setenv("OC_CONFIG_DIR", GinkgoT().TempDir()) + }) + + // a body webdav allows and the generator refuses is downloaded and posted for nothing + DescribeTable("reads the maximum input file size the way the thumbnails service does", + func(env map[string]string, want string) { + for k, v := range env { + GinkgoT().Setenv(k, v) + } + + cfg := defaults.DefaultConfig() + Expect(parser.ParseConfig(cfg)).To(Succeed()) + + generator := thumbnailsdefaults.DefaultConfig() + Expect(thumbnailsparser.ParseConfig(generator)).To(Succeed()) + + Expect(cfg.Thumbnails.MaxInputFileSize).To(Equal(want)) + Expect(generator.Thumbnail.MaxInputImageFileSize).To(Equal(want)) + }, + Entry("from the shared name", map[string]string{ + "OC_THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE": "100MB", + }, "100MB"), + Entry("from the old name", map[string]string{ + "THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE": "20MB", + }, "20MB"), + Entry("from the old name when both are set", map[string]string{ + "THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE": "20MB", + "OC_THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE": "100MB", + }, "20MB"), + ) +}) diff --git a/services/webdav/pkg/config/parser/parser_suite_test.go b/services/webdav/pkg/config/parser/parser_suite_test.go new file mode 100644 index 0000000000..0d931b456c --- /dev/null +++ b/services/webdav/pkg/config/parser/parser_suite_test.go @@ -0,0 +1,16 @@ +// Copyright 2026 OpenCloud GmbH +// SPDX-License-Identifier: Apache-2.0 + +package parser_test + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestParser(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Parser Suite") +}