mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 21:33:24 +03: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:
parent
65d79f4a74
commit
f43eeacfd0
@ -6,8 +6,12 @@ module.exports = {
|
||||
statusCode: 201,
|
||||
permissions: false,
|
||||
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 thumbnail = await storage.getStorage('media').save(frame.files.thumbnail[0]);
|
||||
|
||||
return {
|
||||
filePath: file,
|
||||
|
@ -190,28 +190,31 @@ const mediaValidation = function ({type}) {
|
||||
req.file.type = req.file.mimetype;
|
||||
req.file.ext = path.extname(req.file.name).toLowerCase();
|
||||
|
||||
const {thumbnail: [thumbnailFile] = []} = req.files;
|
||||
if (!thumbnailFile || !checkFileExists(thumbnailFile)) {
|
||||
return next(new errors.ValidationError({
|
||||
message: tpl(messages.thumbnail.missingFile)
|
||||
}));
|
||||
}
|
||||
|
||||
req.thumbnail = thumbnailFile;
|
||||
req.thumbnail.ext = path.extname(thumbnailFile.originalname).toLowerCase();
|
||||
req.thumbnail.name = `${path.basename(req.file.name, path.extname(req.file.name))}_thumb${req.thumbnail.ext}`;
|
||||
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)) {
|
||||
return next(new errors.UnsupportedMediaTypeError({
|
||||
message: tpl(messages.thumbnail.invalidFile, {extensions: thumbnailExtensions})
|
||||
}));
|
||||
const {thumbnail: [thumbnailFile] = []} = req.files;
|
||||
|
||||
if (thumbnailFile) {
|
||||
if (!checkFileExists(thumbnailFile)) {
|
||||
return next(new errors.ValidationError({
|
||||
message: tpl(messages.thumbnail.missingFile)
|
||||
}));
|
||||
}
|
||||
|
||||
req.thumbnail = thumbnailFile;
|
||||
req.thumbnail.ext = path.extname(thumbnailFile.originalname).toLowerCase();
|
||||
req.thumbnail.name = `${path.basename(req.file.name, path.extname(req.file.name))}_thumb${req.thumbnail.ext}`;
|
||||
req.thumbnail.type = req.thumbnail.mimetype;
|
||||
|
||||
if (!checkFileIsValid(req.thumbnail, thumbnailContentTypes, thumbnailExtensions)) {
|
||||
return next(new errors.UnsupportedMediaTypeError({
|
||||
message: tpl(messages.thumbnail.invalidFile, {extensions: thumbnailExtensions})
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
|
@ -41,17 +41,17 @@ describe('Media API', function () {
|
||||
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'))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect('Content-Type', /json/)
|
||||
.field('purpose', 'video')
|
||||
.field('ref', 'https://ghost.org/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);
|
||||
|
||||
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');
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user