ugly fix to keep the path segment on kubernetes

TODO: refactor me
This commit is contained in:
Robert Schäfer 2025-05-31 00:10:08 +08:00
parent 9c224b0e2e
commit 68e8a80665
2 changed files with 24 additions and 3 deletions

View File

@ -7,7 +7,7 @@ describe('Image', () => {
const args = {}
const Location =
'https://fsn1.your-objectstorage.com/ocelot-social-staging/original/f965ea15-1f6b-43aa-a535-927410e2585e-dsc02586.jpg'
const config = {
const defaultConfig = {
...TEST_CONFIG,
AWS_ENDPOINT: 'https://fsn1.your-objectstorage.com',
S3_PUBLIC_GATEWAY: 'https://your-public-gateway.com',
@ -15,15 +15,30 @@ describe('Image', () => {
}
describe('.url', () => {
const config = { ...defaultConfig }
it('replaces the internal domain of the S3 `Location` with a public domain', () => {
const expectedUrl =
'https://your-public-gateway.com/f_qz7PlAWIQx-IrMOZfikzDFM6I=/ocelot-social-staging/original/f965ea15-1f6b-43aa-a535-927410e2585e-dsc02586.jpg'
expect(Image.url({ url: Location }, args, { config })).toEqual(expectedUrl)
})
describe('given `S3_PUBLIC_GATEWAY` has a path segment', () => {
const config = {
...defaultConfig,
S3_PUBLIC_GATEWAY: 'https://your-public-gateway.com/imagor',
}
it('keeps the path segment', () => {
const expectedUrl =
'https://your-public-gateway.com/imagor/f_qz7PlAWIQx-IrMOZfikzDFM6I=/ocelot-social-staging/original/f965ea15-1f6b-43aa-a535-927410e2585e-dsc02586.jpg'
expect(Image.url({ url: Location }, args, { config })).toEqual(expectedUrl)
})
})
})
describe('.transform', () => {
describe('resize transformations', () => {
const config = { ...defaultConfig }
const args = { width: 320 }
it('encodes `fit-in` imagor transformations in the URL', () => {

View File

@ -29,8 +29,14 @@ const changeDomain: (opts: { transformations: UrlResolver[] }) => UrlResolver =
const publicUrl = new URL(S3_PUBLIC_GATEWAY)
publicUrl.pathname = originalUrl.pathname
const newUrl = publicUrl.href
return chain(...transformations)({ url: newUrl }, _args, context)
let newUrl = publicUrl.href
newUrl = chain(...transformations)({ url: newUrl }, _args, context)
const result = new URL(newUrl)
if (new URL(S3_PUBLIC_GATEWAY).pathname === '/') {
return result.href
}
result.pathname = new URL(S3_PUBLIC_GATEWAY).pathname + result.pathname
return result.href
}
const sign: UrlResolver = ({ url }, _args, { config: { IMAGOR_SECRET } }) => {