Last active
May 10, 2019 06:24
-
-
Save drewbitt/25e6416ac73d4ede4b06129c428c562c to your computer and use it in GitHub Desktop.
Upload File, Return Torrent Json
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
const express = require('express') | |
const fileUpload = require('express-fileupload') | |
const createTorrent = require('create-torrent') | |
const parseTorrentFile = require('parse-torrent-file') | |
var parsed | |
const app = express() | |
app.use(fileUpload()) | |
app.post('/upload', function(req, res) { | |
createTorrent(req.files.data.data, function (err, torrent) { | |
if (!err) { | |
console.log("Error in creating torrent") | |
} | |
try { | |
parsed = parseTorrentFile.decode(torrent) | |
res.status(201).send(parsed) | |
} catch (e) { | |
// the torrent file was corrupt | |
console.error(e) | |
} | |
}) | |
}) | |
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
const app = require('./app') | |
const port = process.env.PORT || 3000 | |
app.listen(port, () => { | |
console.log('Application started on port', port) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment