Skip to content

Commit

Permalink
🆕 change form multi handler
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnath committed Dec 21, 2016
1 parent 54ab7fc commit 2779b86
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,6 @@ module.exports = {
dest: 'public/files',
settings: {},
public: '/files', // Can include {{dest}} for the dest path
temp: 'public/tmp/',
},
};
9 changes: 4 additions & 5 deletions lib/routes/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/
const config = require('config');
const types = require('punchcard-content-types');
const multipart = require('connect-multiparty');
const multer = require('multer');
const upload = multer({ dest: config.storage.temp || 'public/tmp/' });
const uuid = require('uuid');
const _ = require('lodash');
const isUUID = require('validator/lib/isUUID');
Expand All @@ -17,8 +18,6 @@ const workflows = require('../workflows');
const schedule = require('../schedule');
const storage = require('../storage');

const multipartMiddleware = multipart();

/*
* Content Route Resolution
*
Expand Down Expand Up @@ -283,7 +282,7 @@ const routes = application => {
* @param {object} res - HTTP Response
* @param {object} next - Express callback
*/
app.post(`/${config.content.base}/:type/${config.content.actions.save}`, multipartMiddleware, (req, res, next) => {
app.post(`/${config.content.base}/:type/${config.content.actions.save}`, upload.any(), (req, res, next) => {
const referrer = _.get(req.session, 'referrer') || req.get('Referrer');
let audits;
let publishable = false;
Expand Down Expand Up @@ -343,7 +342,7 @@ const routes = application => {

// language
let language = 'us-en';
if (req.body.hasOwnProperty('language')) {
if (req.body.language) {
language = req.body.language;
}

Expand Down
12 changes: 6 additions & 6 deletions lib/storage/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ const fileDJ = file => {
const f = new PunchcardFile({
cwd: '/',
base: '/',
path: `/${file.originalFilename}`,
path: `/${file.originalname}`,
contents: data,
});

f.field = file.fieldName;
f.type = file.type;
f.path = `/${f.uuid}${path.extname(file.originalFilename)}`;
f.rel = `/${f.uuid}${path.extname(file.originalFilename)}`;
f.original = file.originalFilename;
f.field = file.fieldname;
f.type = file.mimetype;
f.path = `/${f.uuid}${path.extname(file.originalname)}`;
f.rel = `/${f.uuid}${path.extname(file.originalname)}`;
f.original = file.originalname;

res(f);
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"moment": "^2.15.0",
"moment-timezone": "^0.5.4",
"morgan": "^1.6.1",
"multer": "^1.2.1",
"multiparty": "^4.1.2",
"node-dir": "^0.1.11",
"node-schedule": "^1.1.1",
Expand Down
4 changes: 2 additions & 2 deletions tests/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ test('Storage - Default', t => {
Object.keys(files).forEach(file => {
const result = files[file];
const expected = input.find(inp => {
return inp.fieldName === file;
return inp.fieldname === file;
});

t.true(result.hasOwnProperty('original'), 'Has original filename');
t.true(result.hasOwnProperty('type'), 'Has a type');
t.true(result.hasOwnProperty('relative'), 'Has a relative path');
t.is(result.type, expected.type, 'Have the same type');
t.is(result.type, expected.mimetype, 'Have the same type');

const output = fs.readFileSync(path.join(__dirname, 'public/files', result.relative));
const original = fs.readFileSync(expected.path);
Expand Down

0 comments on commit 2779b86

Please sign in to comment.