Skip to content

Instantly share code, notes, and snippets.

@drewbitt
Last active May 10, 2019 06:24
Show Gist options
  • Save drewbitt/25e6416ac73d4ede4b06129c428c562c to your computer and use it in GitHub Desktop.
Save drewbitt/25e6416ac73d4ede4b06129c428c562c to your computer and use it in GitHub Desktop.
Upload File, Return Torrent Json
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
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