mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-01-20 20:01:25 +00:00
ugly fix to keep the path segment on kubernetes
TODO: refactor me
This commit is contained in:
parent
9c224b0e2e
commit
68e8a80665
@ -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', () => {
|
||||
|
||||
@ -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 } }) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user