Robert Schäfer 00da9e8ecb
feat(backend): resize images with imagor (#8558)
* feat(backend): resize images with imagor

Open questions:
* Do we have external URLs for images? E.g. we have them for seeds. But
  in production?

* Do we want to apply image transformations on these as well? My current
implementation does not apply image transformations as of now. If we
want to do that, we will also expose internal URLs in the kubernetes
Cluster to the S3 endpoint to the client.

TODOs:
* The chat component is using a fixed size for all avatars at the moment.
Maybe we can pair-program on this how to implement responsive images in
this component library.

Commits:
* do not replace upload domain url in the database

* fix all webapp specs

* refactor: remove behaviour we won't need

We don't want to apply image transformations on files, right?

* refactor: replace the domain on read not on write

* wip: webapp fixes

* refactor(backend): add another url to config

I've given up. There seems to be no nice way to tell the minio to return
a location which differs from it's host name.

* refactor: add test for s3Service

* refactor(backend): proxy minio via backend in local development

Commits:
* provide tests for message attachments
* remove S3_PUBLIC_URL config value

* refactor: follow @ulfgebhardt's review

* add missing environment variable

---------

Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>
2025-08-19 10:11:12 +02:00

53 lines
2.0 KiB
TypeScript

import { TEST_CONFIG } from '@root/test/helpers'
import ImageResolver from './images'
describe('Image', () => {
const { Image } = ImageResolver
const Location =
'https://fsn1.your-objectstorage.com/ocelot-social-staging/original/f965ea15-1f6b-43aa-a535-927410e2585e-dsc02586.jpg'
const defaultConfig = {
...TEST_CONFIG,
AWS_ENDPOINT: 'https://fsn1.your-objectstorage.com',
IMAGOR_PUBLIC_URL: 'https://imagor-public-url.com',
IMAGOR_SECRET: 'IMAGOR_SECRET',
}
describe('.transform', () => {
describe('no transformations', () => {
const config = { ...defaultConfig }
const args = {}
it('just points the original url to imagor and adds a signature', () => {
const expectedUrl =
'https://imagor-public-url.com/f_qz7PlAWIQx-IrMOZfikzDFM6I=/ocelot-social-staging/original/f965ea15-1f6b-43aa-a535-927410e2585e-dsc02586.jpg'
expect(Image.transform({ url: Location }, args, { config })).toEqual(expectedUrl)
})
describe('if `IMAGOR_PUBLIC_URL` has a path segment', () => {
const config = {
...defaultConfig,
IMAGOR_PUBLIC_URL: 'https://imagor-public-url.com/path-segment',
}
it('keeps the path segment', () => {
const expectedUrl =
'https://imagor-public-url.com/path-segment/f_qz7PlAWIQx-IrMOZfikzDFM6I=/ocelot-social-staging/original/f965ea15-1f6b-43aa-a535-927410e2585e-dsc02586.jpg'
expect(Image.transform({ url: Location }, args, { config })).toEqual(expectedUrl)
})
})
})
describe('resize transformations', () => {
const config = { ...defaultConfig }
const args = { width: 320 }
it('encodes `fit-in` imagor transformations in the URL', () => {
const expectedUrl =
'https://imagor-public-url.com/1OEqC7g0YFxuvnRCX2hOukYMJEY=/fit-in/320x5000/ocelot-social-staging/original/f965ea15-1f6b-43aa-a535-927410e2585e-dsc02586.jpg'
expect(Image.transform({ url: Location }, args, { config })).toEqual(expectedUrl)
})
})
})
})