0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Changed thumbnail to be an optional parameter

refs https://github.com/TryGhost/Toolbox/issues/95

- With incoming support of audio media files thumbnail would not be a required parameter
This commit is contained in:
Naz 2021-11-05 17:06:28 +04:00
parent 65d79f4a74
commit f43eeacfd0
3 changed files with 26 additions and 29 deletions

View file

@ -6,8 +6,12 @@ module.exports = {
statusCode: 201, statusCode: 201,
permissions: false, permissions: false,
async query(frame) { async query(frame) {
let thumbnail = null;
if (frame.files.thumbnail && frame.files.thumbnail[0]) {
thumbnail = await storage.getStorage('media').save(frame.files.thumbnail[0]);
}
const file = await storage.getStorage('media').save(frame.files.file[0]); const file = await storage.getStorage('media').save(frame.files.file[0]);
const thumbnail = await storage.getStorage('media').save(frame.files.thumbnail[0]);
return { return {
filePath: file, filePath: file,

View file

@ -190,8 +190,16 @@ const mediaValidation = function ({type}) {
req.file.type = req.file.mimetype; req.file.type = req.file.mimetype;
req.file.ext = path.extname(req.file.name).toLowerCase(); req.file.ext = path.extname(req.file.name).toLowerCase();
if (!checkFileIsValid(req.file, contentTypes, extensions)) {
return next(new errors.UnsupportedMediaTypeError({
message: tpl(messages[type].invalidFile, {extensions: extensions})
}));
}
const {thumbnail: [thumbnailFile] = []} = req.files; const {thumbnail: [thumbnailFile] = []} = req.files;
if (!thumbnailFile || !checkFileExists(thumbnailFile)) {
if (thumbnailFile) {
if (!checkFileExists(thumbnailFile)) {
return next(new errors.ValidationError({ return next(new errors.ValidationError({
message: tpl(messages.thumbnail.missingFile) message: tpl(messages.thumbnail.missingFile)
})); }));
@ -202,17 +210,12 @@ const mediaValidation = function ({type}) {
req.thumbnail.name = `${path.basename(req.file.name, path.extname(req.file.name))}_thumb${req.thumbnail.ext}`; req.thumbnail.name = `${path.basename(req.file.name, path.extname(req.file.name))}_thumb${req.thumbnail.ext}`;
req.thumbnail.type = req.thumbnail.mimetype; req.thumbnail.type = req.thumbnail.mimetype;
if (!checkFileIsValid(req.file, contentTypes, extensions)) {
return next(new errors.UnsupportedMediaTypeError({
message: tpl(messages[type].invalidFile, {extensions: extensions})
}));
}
if (!checkFileIsValid(req.thumbnail, thumbnailContentTypes, thumbnailExtensions)) { if (!checkFileIsValid(req.thumbnail, thumbnailContentTypes, thumbnailExtensions)) {
return next(new errors.UnsupportedMediaTypeError({ return next(new errors.UnsupportedMediaTypeError({
message: tpl(messages.thumbnail.invalidFile, {extensions: thumbnailExtensions}) message: tpl(messages.thumbnail.invalidFile, {extensions: thumbnailExtensions})
})); }));
} }
}
next(); next();
}; };

View file

@ -41,17 +41,17 @@ describe('Media API', function () {
media.push(res.body.media[0].thumbnail_url.replace(config.get('url'), '')); media.push(res.body.media[0].thumbnail_url.replace(config.get('url'), ''));
}); });
it('Can upload a WebM', async function () { it('Can upload a WebM without a thumbnail', async function () {
const res = await request.post(localUtils.API.getApiQuery('media/upload')) const res = await request.post(localUtils.API.getApiQuery('media/upload'))
.set('Origin', config.get('url')) .set('Origin', config.get('url'))
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.field('purpose', 'video') .field('purpose', 'video')
.field('ref', 'https://ghost.org/sample_640x360.webm') .field('ref', 'https://ghost.org/sample_640x360.webm')
.attach('file', path.join(__dirname, '/../../utils/fixtures/media/sample_640x360.webm')) .attach('file', path.join(__dirname, '/../../utils/fixtures/media/sample_640x360.webm'))
.attach('thumbnail', path.join(__dirname, '/../../utils/fixtures/images/ghost-logo.png'))
.expect(201); .expect(201);
res.body.media[0].url.should.match(new RegExp(`${config.get('url')}/content/media/\\d+/\\d+/sample_640x360.webm`)); res.body.media[0].url.should.match(new RegExp(`${config.get('url')}/content/media/\\d+/\\d+/sample_640x360.webm`));
should(res.body.media[0].thumbnail_url).eql(null);
res.body.media[0].ref.should.equal('https://ghost.org/sample_640x360.webm'); res.body.media[0].ref.should.equal('https://ghost.org/sample_640x360.webm');
media.push(res.body.media[0].url.replace(config.get('url'), '')); media.push(res.body.media[0].url.replace(config.get('url'), ''));
@ -83,14 +83,4 @@ describe('Media API', function () {
res.body.errors[0].message.should.match(/select a valid media file/gi); res.body.errors[0].message.should.match(/select a valid media file/gi);
}); });
it('Rejects when thumbnail is not present', async function () {
const res = await request.post(localUtils.API.getApiQuery('media/upload'))
.set('Origin', config.get('url'))
.expect('Content-Type', /json/)
.attach('file', path.join(__dirname, '/../../utils/fixtures/media/sample_640x360.ogv'))
.expect(422);
res.body.errors[0].message.should.match(/Please select a thumbnail./gi);
});
}); });