This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2283ae7
commit 43e94e6
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const express = require('express'); | ||
const app = express.Router(); | ||
const logger = require('node-color-log'); | ||
const uuidv1 = require('uuid/v1'); | ||
|
||
app.post('/moew', async (req, res) => { | ||
const uuid = uuidv1(); | ||
logger.info(`/api/meow: [${uuid}] new request`); | ||
|
||
const info = req.body; | ||
|
||
const meow = path.join(__dirname, '../meow'); | ||
const outputFile = path.join(__dirname, `../${uuid}.jpg`); | ||
// cats is the images folder, and 27 is quantity. | ||
const command = `${meow} bottom-mode cats/${Math.floor(Math.random()*27)}.jpg '${JSON.stringify(info)}' -o ${outputFile}`; | ||
const { | ||
stdout, | ||
stderr | ||
} = await exec(command); | ||
if (stderr) { | ||
logger.warn(`/api/meow: [${uuid}] return 400`); | ||
return res.status(400).send("meow creates image failed."); | ||
} | ||
logger.info(`/api/meow: [${uuid}] the image created.`) | ||
logger.info(`/api/meow: [${uuid}] return 200`); | ||
return res.status(200).json({ | ||
uuid | ||
}); | ||
}) | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters