Merge pull request #1 from paulfitz/tweak-directories

remove hardcoded repository directory; tweak indentation
This commit is contained in:
gliggy
2021-11-11 15:44:12 -05:00
committed by GitHub

View File

@@ -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}`)
})