From c5a4ee89c9af74800263433358608482a6976bad Mon Sep 17 00:00:00 2001 From: Reupen Shah Date: Mon, 27 Feb 2023 20:08:35 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20uploads=20of=20m4a=20fil?= =?UTF-8?q?es=20with=20audio/mp4=20content=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes https://github.com/TryGhost/Ghost/issues/16301 Previously, audio/x-m4a was allowed but not audio/mp4. This meant uploads of m4a files failed in some cases e.g. Firefox on Windows. --- ghost/core/core/shared/config/overrides.json | 1 + ghost/core/test/e2e-api/admin/media.test.js | 28 ++++++++++++++++++ .../core/test/utils/fixtures/media/sample.m4a | Bin 0 -> 5192 bytes 3 files changed, 29 insertions(+) create mode 100644 ghost/core/test/utils/fixtures/media/sample.m4a diff --git a/ghost/core/core/shared/config/overrides.json b/ghost/core/core/shared/config/overrides.json index abd80abed9..6129e95ba4 100644 --- a/ghost/core/core/shared/config/overrides.json +++ b/ghost/core/core/shared/config/overrides.json @@ -41,6 +41,7 @@ "audio/wav", "audio/x-wav", "audio/ogg", + "audio/mp4", "audio/x-m4a" ] }, diff --git a/ghost/core/test/e2e-api/admin/media.test.js b/ghost/core/test/e2e-api/admin/media.test.js index b6d10eb0cb..cfb1b8c9eb 100644 --- a/ghost/core/test/e2e-api/admin/media.test.js +++ b/ghost/core/test/e2e-api/admin/media.test.js @@ -85,6 +85,34 @@ describe('Media API', function () { media.push(res.body.media[0].url.replace(config.get('url'), '')); }); + it('Can upload an m4a with audio/mp4 content type', async function () { + const res = await request.post(localUtils.API.getApiQuery('media/upload')) + .set('Origin', config.get('url')) + .expect('Content-Type', /json/) + .field('ref', 'audio_file_mp4') + .attach('file', path.join(__dirname, '/../../utils/fixtures/media/sample.m4a'), {filename: 'audio-mp4.m4a', contentType: 'audio/mp4'}) + .expect(201); + + res.body.media[0].url.should.match(new RegExp(`${config.get('url')}/content/media/\\d+/\\d+/audio-mp4.m4a`)); + res.body.media[0].ref.should.equal('audio_file_mp4'); + + media.push(res.body.media[0].url.replace(config.get('url'), '')); + }); + + it('Can upload an m4a with audio/x-m4a content type', async function () { + const res = await request.post(localUtils.API.getApiQuery('media/upload')) + .set('Origin', config.get('url')) + .expect('Content-Type', /json/) + .field('ref', 'audio_file_x_m4a') + .attach('file', path.join(__dirname, '/../../utils/fixtures/media/sample.m4a'), {filename: 'audio-x-m4a.m4a', contentType: 'audio/x-m4a'}) + .expect(201); + + res.body.media[0].url.should.match(new RegExp(`${config.get('url')}/content/media/\\d+/\\d+/audio-x-m4a.m4a`)); + res.body.media[0].ref.should.equal('audio_file_x_m4a'); + + media.push(res.body.media[0].url.replace(config.get('url'), '')); + }); + it('Rejects non-media file type', async function () { const res = await request.post(localUtils.API.getApiQuery('media/upload')) .set('Origin', config.get('url')) diff --git a/ghost/core/test/utils/fixtures/media/sample.m4a b/ghost/core/test/utils/fixtures/media/sample.m4a new file mode 100644 index 0000000000000000000000000000000000000000..3e38d80e42733551496720ab03443b7795549581 GIT binary patch literal 5192 zcmeHL&1w`u5U!cstfP2XL|Ks$Cy?MpV~p|d7R7@|JOy(Q1t;6R$(ZSxVY+uAp4Ph$ zl7NsrfgpJF=*fe(fDhn3e$}&^oh*W0C0$H+Raezib$|0yO%qYrGdsoeWz?l0V4T%^ZQ@cHtC*>>~IhtTy70f&G?z#(vY z5O4*-l|F}nL*SngAUgY9<@o?R%Tx`v1bB@aKZ&ll$s@idbYcMY)Ocm$`6tQ8Cic*j z@ivUF%(l(hs5y?JA@77dtDMU7m%MXQ7>y92Otl$>LIjT69L+g+twa*T7AY~k_K#1f z^=bFT7klT;Es>U^7^L%lHkO&MVJx1;nMfu31c6Gj9)z}5CxXt2N*{_+vYm;SbiQAv zQ6-=Gs?A0U`K>m3{4m((r7D(rqD(xl$R`UDrpk0rYQYPp#&9^Chg%c8vvP@5-Y;~) ztr=)$F0|JVsRhZyqo7C|3ln=`?Co24Y!-hPx)3wzvJu3Y(Y%9-x4yyljtv!AeFt*O zHHU$F2TtWX;J$zN|NEc+{};9C=2bnj_3j4bD|)jKT>Q#BppsAL@jM@h@sZMMFVz~-Zji-IE_(`r)fR<7-3v4XaPV?GYT*=a3FW!A;