-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
46 lines (29 loc) · 1.1 KB
/
main.js
File metadata and controls
46 lines (29 loc) · 1.1 KB
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
const express = require('express')
const app = express()
const fs = require('fs-extra')
const utils = require('./lib/utils')
function parserUrl(req, ...args) {
return `${req.protocol}://${req.get('host')}/${args}`
}
app.get('/twtfake', async(req, res) => {
const twtfake = require('./command/twtfake')
await twtfake(req.query.username, req.query.text).then(async buffer => {
const file = await utils.writeTempFile(buffer, 'png')
res.status(200).json({
status: 'success',
url: parserUrl(req, `file?fileId=${file}`),
delete: `This file will be deleted in 5 minutes`
})
})
})
app.get('/file', async(req, res) => {
var filepath = `./temp/${req.query.fileId}`
let file = await fs.readFile(filepath)
res.setHeader('Content-Type', 'image/png');
res.setHeader("Content-Disposition", 'attachment;\ filename=' + 'JonazBOT-' + req.query.fileId );
res.send(file)
})
const port = process.env.PORT || 8080
app.listen(port, () => {
console.log(`listening on port ${port}`)
})