Skip to content

Commit 1f33c07

Browse files
committed
Don't process legacy gifs with imgproxy
1 parent 0461778 commit 1f33c07

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

app/controllers/api/v1/AttachmentsController.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,16 @@ export default class AttachmentsController {
241241
response.width = prv.w;
242242
response.height = prv.h;
243243

244-
// With imgproxy, we can resize images (except SVG) and change their format
245-
if (useImgProxy && type === 'image' && attachment.fileExtension !== 'svg') {
244+
// With imgproxy, we can resize images (except some types) and change
245+
// their format
246+
if (
247+
useImgProxy &&
248+
type === 'image' &&
249+
// We don't need to resize SVGs
250+
attachment.fileExtension !== 'svg' &&
251+
// We should not resize (probably) animated legacy GIFs
252+
!(attachment.fileExtension === 'gif' && attachment.isLegacyImage)
253+
) {
246254
let { format } = query;
247255

248256
if (!format) {

app/models.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ export class Attachment {
210210
updatedAt: Date;
211211
userId: UUID;
212212
postId: UUID | null;
213+
isLegacyImage: boolean;
213214

214215
constructor(params: AttachmentParams);
215216
static create(

app/models/attachment.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ export function addModel(dbAdapter) {
5858

5959
this.createdAt = params.createdAt;
6060
this.updatedAt = params.updatedAt;
61+
62+
/**
63+
* This image attachment was created before the 'previews' field was
64+
* introduced (i.e. before the v4 API).
65+
*/
66+
this.isLegacyImage = this.mediaType === 'image' && this._previews === null;
6167
}
6268

6369
get previews() {

test/integration/models/attachment.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ describe('Attachments', () => {
319319
previews: expect.it('to equal', { image: { '': { h: 150, w: 150, ext: 'png' } } }),
320320
width: 150,
321321
height: 150,
322+
isLegacyImage: true,
322323
});
323324
});
324325

@@ -343,6 +344,7 @@ describe('Attachments', () => {
343344
}),
344345
width: 900,
345346
height: 300,
347+
isLegacyImage: true,
346348
});
347349
});
348350

@@ -369,6 +371,7 @@ describe('Attachments', () => {
369371
}),
370372
width: 1500,
371373
height: 1000,
374+
isLegacyImage: true,
372375
});
373376
});
374377

0 commit comments

Comments
 (0)