Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions frontend/src/services/abstractService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function serviceWithBlobResponse(blob: Blob) {
describe('getBlobUrl', () => {
afterEach(() => {
vi.restoreAllMocks()
vi.unstubAllGlobals()
})

it('keeps the mime type of the fetched blob', async () => {
Expand All @@ -34,4 +35,14 @@ describe('getBlobUrl', () => {

expect(url).toMatch(/^data:image\/svg\+xml/)
})

it('falls back to a blob url for svg when FileReader is unavailable', async () => {
const service = serviceWithBlobResponse(new Blob(['<svg xmlns="http://www.w3.org/2000/svg"/>'], {type: 'image/svg+xml'}))
vi.spyOn(window.URL, 'createObjectURL').mockReturnValue('blob:mock')
vi.stubGlobal('FileReader', undefined)

const url = await service.getBlobUrl({taskId: 1, id: 3} as IAttachment)

expect(url).toBe('blob:mock')
})
})
5 changes: 3 additions & 2 deletions frontend/src/services/abstractService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ export default abstract class AbstractService<Model extends IAbstract = IAbstrac
data,
})

// Handle SVG blobs specially - convert to data URL for better browser compatibility
if (response.data.type === 'image/svg+xml') {
// Handle SVG blobs specially - convert to data URL for better browser compatibility.
// FileReader is absent in some environments (iOS Lockdown Mode, embedded webviews), fall back to a blob url there.
if (response.data.type === 'image/svg+xml' && typeof FileReader !== 'undefined') {
return new Promise<string>((resolve, reject) => {
const reader = new FileReader()
reader.onload = () => resolve(reader.result as string)
Expand Down
Loading