mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-01-20 20:01:25 +00:00
fix silly bug on upload
This commit is contained in:
parent
4ea6e5ba0e
commit
0dd8f41808
@ -44,16 +44,14 @@ export interface Images {
|
||||
resource: { id: string },
|
||||
relationshipType: 'HERO_IMAGE' | 'AVATAR_IMAGE',
|
||||
opts?: DeleteImageOpts,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
) => Promise<any>
|
||||
) => Promise<Image>
|
||||
|
||||
mergeImage: (
|
||||
resource: { id: string },
|
||||
relationshipType: 'HERO_IMAGE' | 'AVATAR_IMAGE',
|
||||
imageInput: ImageInput | null | undefined,
|
||||
opts?: MergeImageOpts,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
) => Promise<any>
|
||||
) => Promise<Image>
|
||||
}
|
||||
|
||||
export const images = (config: Context['config']) =>
|
||||
|
||||
@ -324,6 +324,26 @@ describe('mergeImage', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('edge cases: `Location` is not a valid URL (e.g. hetzner object storage)', () => {
|
||||
beforeEach(async () => {
|
||||
uploadCallback = jest.fn(
|
||||
() =>
|
||||
'fsn1.your-objectstorage.com/ocelot-social-staging/original/f965ea15-1f6b-43aa-a535-927410e2585e-dsc02586.jpg',
|
||||
)
|
||||
})
|
||||
|
||||
it('adds missing https:// protocol', async () => {
|
||||
const result = await mergeImage(post, 'HERO_IMAGE', imageInput, {
|
||||
uploadCallback,
|
||||
deleteCallback,
|
||||
})
|
||||
expect(result).toMatchObject({
|
||||
url: 'https://fsn1.your-objectstorage.com/ocelot-social-staging/original/f965ea15-1f6b-43aa-a535-927410e2585e-dsc02586.jpg',
|
||||
})
|
||||
expect(new URL(result.url)).toBeDefined()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -104,7 +104,10 @@ export const images = (config: S3Configured) => {
|
||||
const upload = await uploadPromise
|
||||
const { name, ext } = path.parse(upload.filename)
|
||||
const uniqueFilename = `${uuid()}-${slug(name)}${ext}`
|
||||
const Location = await uploadCallback({ ...upload, uniqueFilename })
|
||||
let Location = await uploadCallback({ ...upload, uniqueFilename })
|
||||
if (!Location.startsWith('https://') && !Location.startsWith('http://')) {
|
||||
Location = `https://${Location}` // assume https
|
||||
}
|
||||
return Location
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user