1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| const kue = require('kue') const queue = kue.createQueue()
router.post('/', upload.single('upload_img'), (req, res) => { const { ext, mime } = fileType(req.file.buffer) if (!supportImageExt.includes(ext)) { res.status(400) res.send('지원하지 않는 파일입니다.') } else if (req.file.size > maxFileSize) { res.status(400) res.send('파일 용량은 3mb 까지 입니다.') }
const fileName = `${uuid.v4()}.${ext}`
Promise.all([googleVision(req.file.buffer), s3upload(req.file.buffer, fileName, mime)]) .then(result => { const filterText = ['food', 'cuisine', 'american food', 'baking', 'flavor', 'recipe', 'fast food', 'dessert', 'dish', 'cookie', 'organism', 'snack', 'font', 'baked goods', 'finger food', 'junk food', 'side dish', 'vegetarian food']
const out = result[0].filter(item => { if (filterText.indexOf(item.description) < 0) { return item } }) const output = { 'visionAnalysis': out, 'imgUrl': result[1].Location } res.send(output) return output }) .then(result => { return new Promise((resolve, reject) => { queue.create('thumbnail', { 'imgUrl': result.imgUrl }) .removeOnComplete(true) .save(err => { if (err) { reject(err) } else { resolve() } }) }) }) .catch(err => { res.status(400) res.send(err) }) })
|