fix file parsing

This commit is contained in:
Travis Eden 2018-10-17 09:32:21 -04:00
parent 70ef8b9eed
commit 3daf0ce214
2 changed files with 10 additions and 16 deletions

View file

@ -14,7 +14,7 @@ const publish = require('./publish.js');
const createPublishParams = require('./createPublishParams.js'); const createPublishParams = require('./createPublishParams.js');
const createThumbnailPublishParams = require('./createThumbnailPublishParams.js'); const createThumbnailPublishParams = require('./createThumbnailPublishParams.js');
const parsePublishApiRequestBody = require('./parsePublishApiRequestBody.js'); const parsePublishApiRequestBody = require('./parsePublishApiRequestBody.js');
const {parsePublishApiRequestFiles} = require('./parsePublishApiRequestFiles.js'); const parsePublishApiRequestFiles = require('./parsePublishApiRequestFiles.js');
const authenticateUser = require('./authentication.js'); const authenticateUser = require('./authentication.js');
const CLAIM_TAKEN = 'CLAIM_TAKEN'; const CLAIM_TAKEN = 'CLAIM_TAKEN';

View file

@ -1,7 +1,7 @@
const path = require('path'); const path = require('path');
const validateFileTypeAndSize = require('./validateFileTypeAndSize.js'); const validateFileTypeAndSize = require('./validateFileTypeAndSize.js');
const parsePublishApiRequestFiles = ({file}, isUpdate) => { const parsePublishApiRequestFiles = ({file, thumbnail}, isUpdate) => {
// make sure a file was provided // make sure a file was provided
if (!file && !isUpdate) { if (!file && !isUpdate) {
throw new Error('no file with key of [file] found in request'); throw new Error('no file with key of [file] found in request');
@ -32,26 +32,20 @@ const parsePublishApiRequestFiles = ({file}, isUpdate) => {
// validate the file // validate the file
if (file) validateFileTypeAndSize(file); if (file) validateFileTypeAndSize(file);
// return results // return results
return { const obj = {
fileName : file.name, fileName : file.name,
filePath : file.path, filePath : file.path,
fileExtension: path.extname(file.path), fileExtension: path.extname(file.path),
fileType : file.type, fileType : file.type,
}; };
};
const parsePublishApiRequestThumbnail = ({thumbnail}) => { if (thumbnail) {
if (!thumbnail) { obj.thumbnailFileName = thumbnail.name;
return; obj.thumbnailFilePath = thumbnail.path;
obj.thumbnailFileType = thumbnail.type;
} }
return {
thumbnailFileName: thumbnail.name, return obj;
thumbnailFilePath: thumbnail.path,
thumbnailFileType: thumbnail.type,
};
}; };
module.exports = { module.exports = parsePublishApiRequestFiles;
parsePublishApiRequestFiles,
parsePublishApiRequestThumbnail,
};