diff options
| author | 8cy <[email protected]> | 2020-06-08 03:37:36 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-06-08 03:37:36 -0700 |
| commit | 91b5db9a30f6e5891d68ceb9e511ba704aed8c19 (patch) | |
| tree | 7550f2bd0e6ab487ab92442395af3a7ee77d1e12 /server.js | |
| download | twittlet-91b5db9a30f6e5891d68ceb9e511ba704aed8c19.tar.xz twittlet-91b5db9a30f6e5891d68ceb9e511ba704aed8c19.zip | |
epic
Diffstat (limited to 'server.js')
| -rw-r--r-- | server.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/server.js b/server.js new file mode 100644 index 0000000..8af4eef --- /dev/null +++ b/server.js @@ -0,0 +1,64 @@ +const express = require('express'); +const app = express(); +const path = require('path'); +const vul = require('video-url-link'); + +// side-note: this is best used with a api testing service like postman for now. reason being; when actually performing a query, +// the page just spits out a bunch of json shit so it not super readable for now. +// never mind i fixed this with the prettify package lol +// never mind, package don't wanna work so stack overflow it is ))) +// https://stackoverflow.com/questions/32679505/node-and-express-send-json-formatted +// holy shit JSON.parse() broke this shit + +app.use(express.static(path.join(__dirname, 'public'))); +app.set('view engine', 'ejs'); +app.use(express.urlencoded({ extended: false })); +app.set('json spaces', 2); + +app.get('/', (req, res) => { + res.render('index', { error: '' }); +}); + +app.post('/submitData', (req, res) => { + //console.log(req.body.urlInput); + let twitterPostURL = req.body.urlInput; + + if (twitterPostURL.length < 40) return res.redirect('/'); + // 40 chars is the length of the entire twitter url without the protocol nor the user's handle + + let localURL = req.protocol + '://' + req.get('host'); // + req.originalUrl; + //console.log(localURL); + + res.redirect(localURL + '/api/v1?video=' + twitterPostURL); +}); + +app.get('/api/v1', (req, res) => { + let videoURL = req.query.video; + + //let video = 'https://twitter.com/threatenedcats/status/1269917580497522689'; + + vul.twitter.getInfo(videoURL, {}, (error, info) => { + if (error) return console.log(error); + + //console.log(info.full_text); + //console.log(info.variants); + res.json({ + _comment: 'This is a link to the same Twitter post, except short.', + videoURLShort: info.full_text, + _comment2: 'These are links to the Twitter post media in various different formats.', + videoURLs: info.variants + }); + // no idea why but shit don't stop erroring, however, + // it does stop erroring when its in a separate file + // and honestly i don't have a care in the world + // why it does it, u can fix this if u want ) + }); +}); + +// app.get('*', (req, res) => { +// res.redirect('/'); +// }); + +app.listen(1337, () => { + console.log('Listening on port 1337'); +});
\ No newline at end of file |