Skip to content

Commit

Permalink
File name
Browse files Browse the repository at this point in the history
  • Loading branch information
msimmer committed Dec 6, 2019
1 parent b762fdd commit c740c31
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
4 changes: 1 addition & 3 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ class Database {
}

// Adds torrent data to the db
createTorrent(fileName, hash, callback) {
const name = `${fileName}.torrent`;
createTorrent(name, hash, callback) {
const data = [[[name, hash]]];
return this.connection.query(
"INSERT INTO torrents (name, hash) VALUES ?",
Expand All @@ -311,7 +310,6 @@ class Database {

// Adds a torrent to all active clients
addTorrents(torrentIds, clientIds, callback) {
const torrentIds_ = torrentIds.join();
const clientTorrentIds = clientIds
.reduce(
(acc, cId) => acc.concat(torrentIds.map(tId => `(${cId}, ${tId})`)),
Expand Down
14 changes: 0 additions & 14 deletions routes/torrents.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,21 @@ router.post("/new", (req, res) => {

// Use the mv() method to place the file somewhere on your server
torrent.mv(path.join(process.env.FILE_DIR, fileName), error1 => {
console.log("moving torrent to %s", process.env.FILE_DIR);

if (error1) return res.send({ error: error1, data: {} });

api.getTorrentHash(fileName, (error2, data) => {
console.log("getTorrentHash");

if (error2) return res.send({ error: error2, data: {} });

const response = JSON.parse(data);
const { hash } = response.data;

api.addWhitelistedHashes([hash], error3 => {
console.log("addWhitelistedHashes");

if (error3) return res.send({ error: error3, data: {} });

api.restartTracker(error4 => {
console.log("restartTracker");

if (error4) return res.send({ error: error4, data: {} });

db.getClients((error5, clients) => {
console.log("getClients");

if (error5) return res.send({ error: error5, data: {} });

const rpcPorts = clients.reduce(
Expand All @@ -51,13 +41,9 @@ router.post("/new", (req, res) => {
);

api.reannounceTorrents(rpcPorts, error6 => {
console.log("reannounceTorrents");

if (error6) return res.send({ error: error6, data: {} });

db.createTorrent(fileName, hash, (error7, result) => {
console.log("createTorrent");

if (error7) return res.send({ error: error7, data: {} });
res.send(result);
});
Expand Down

0 comments on commit c740c31

Please sign in to comment.