From cd69ec80a00dc3667854f9d20cf3abe3675bdfae Mon Sep 17 00:00:00 2001 From: Paul Fitzpatrick Date: Thu, 11 Nov 2021 13:37:23 -0500 Subject: [PATCH] remove hardcoded repository directory; tweak indentation --- index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 9924570..b570f54 100644 --- a/index.js +++ b/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}`) })