Skip to content

Commit

Permalink
Tracker scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
msimmer committed Nov 1, 2019
1 parent ca27228 commit 6f10a70
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
node_modules
env.sh
.env.sh
public/javascripts/vendor
/sources
/.tmp
Expand Down
16 changes: 15 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class API {
let stdout = ''
let stderr = ''

console.log(`Running %s with arguments %s`, script, args.join(' '))
// console.log(`Running %s with arguments %s`, script, args.join(' '))

proc.stdout.on('data', data => (stdout += String(data)))
proc.stderr.on('data', data => (stderr += String(data)))
Expand Down Expand Up @@ -65,6 +65,20 @@ class API {

this.exec(process.env.SCRIPT_REMOVE_TORRENTS, args, callback)
}

addWhitelistedHashes(hashes, callback) {
const args = hashes.reduce((acc, hash) => acc.concat(['-h', hash]), args)
this.exec(process.env.SCRIPT_TRACKER_ADD_TORRENTS, args, callback)
}

removeWhitelistedHashes(hashes, callback) {
const args = hashes.reduce((acc, hash) => acc.concat(['-h', hash]), args)
this.exec(process.env.SCRIPT_TRACKER_REMOVE_TORRENTS, args, callback)
}

restartTracker(callback) {
this.exec(process.env.SCRIPT_TRACKER_RESTART, callback)
}
}

// const callback = (err, data) => {
Expand Down
12 changes: 10 additions & 2 deletions routes/torrents.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@ router.post('/new', (req, res) => {
const response = JSON.parse(data)
const { hash } = response.data

db.createTorrent(fileName, hash, (error3, result) => {
api.addWhitelistedHashes([hash], error3 => {
if (error3) return res.send({ error: error3, data: {} })
res.send(result)

api.restartTracker(error4 => {
if (error4) return res.send({ error: error4, data: {} })

db.createTorrent(fileName, hash, (error5, result) => {
if (error5) return res.send({ error: error5, data: {} })
res.send(result)
})
})
})
})
})
Expand Down

0 comments on commit 6f10a70

Please sign in to comment.