mirror of
https://github.com/SrIzan10/makesweet-api.git
synced 2026-05-01 10:55:14 +00:00
Merge pull request #1 from paulfitz/tweak-directories
remove hardcoded repository directory; tweak indentation
This commit is contained in:
19
index.js
19
index.js
@@ -1,15 +1,19 @@
|
||||
// -*- mode: js; js-indent-level: 4; -*-
|
||||
|
||||
const express = require('express')
|
||||
const bodyParser = require('body-parser')
|
||||
const childProcess = require('child_process')
|
||||
const multer = require('multer')
|
||||
const uuid = require('uuid')
|
||||
const fs = require ('fs')
|
||||
const app = express()
|
||||
|
||||
const workDir = '/tmp/api'
|
||||
const port = 3000
|
||||
const upload = multer({ dest: '/tmp/api' })
|
||||
|
||||
const upload = multer({ dest: workDir })
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Hello World!')
|
||||
res.send('Hello World!')
|
||||
})
|
||||
|
||||
app.post('/make/:template', upload.any('images'), (req, res) => {
|
||||
@@ -20,16 +24,17 @@ app.post('/make/:template', upload.any('images'), (req, res) => {
|
||||
if (!fs.existsSync(template)) {
|
||||
return res.status(404).json({error: "i seek the template everywhere, but it is not to be found. try 'heart-locket'"})
|
||||
}
|
||||
const path=`/tmp/api/${uuid.v4()}.gif`
|
||||
const path=`${workDir}/${uuid.v4()}.gif`
|
||||
try {
|
||||
const command = ['run', '-v', '/tmp/api:/tmp/api', '-v', '/home/leo/makesweet-cli:/share', 'paulfitz/makesweet', '--zip', template, '--in']
|
||||
const cwd = process.cwd()
|
||||
const command = ['run', '-v', `${workDir}:${workDir}`, '-v', `${cwd}:/share`, 'paulfitz/makesweet', '--zip', template, '--in']
|
||||
for (const file of req.files) {
|
||||
command.push(file.path)
|
||||
}
|
||||
command.push('--gif', path)
|
||||
console.log(command)
|
||||
|
||||
const result=childProcess.execFileSync('docker', command).stdout
|
||||
const result = childProcess.execFileSync('docker', command).stdout
|
||||
res.send(fs.readFileSync(path))
|
||||
} finally {
|
||||
for (const file of req.files) {
|
||||
@@ -40,6 +45,6 @@ app.post('/make/:template', upload.any('images'), (req, res) => {
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening at http://localhost:${port}`)
|
||||
console.log(`Example app listening at http://localhost:${port}`)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user