Skip to content

Commit

Permalink
Sanitize announce URL by removing the trailing / if it's there
Browse files Browse the repository at this point in the history
This should probably be configurable if others ever want to use it
  • Loading branch information
canibanoglu committed Nov 9, 2019
1 parent cd329a4 commit 4fec718
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
8 changes: 6 additions & 2 deletions bin/createTorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ async function writeTorrentFile(fileName, torrentBuffer) {
});
}

const sanitizedAnnounceUURL = CAN_TRACKER_ANNOUNCE_URL.endsWith('/') ?
CAN_TRACKER_ANNOUNCE_URL.slice(0, CAN_TRACKER_ANNOUNCE_URL.length - 1) :
CAN_TRACKER_ANNOUNCE_URL;

console.info("Creating torrent...");
createTorrent(argv._, {
private: true,
announceList: [
[CAN_TRACKER_ANNOUNCE_URL],
[sanitizedAnnounceUURL],
],
urlList: [CAN_TRACKER_WEB_SEED_URL],
}, (err, torrentBuffer) => {
if (err) throw err;

const parsedTorrent = parseTorrent(torrentBuffer);
const torrentFileName = `can_tracker_${parsedTorrent.info.name}.torrent`;
return Promise.all([
addTorrentToDatabase(parsedTorrent),
writeTorrentFile(`can_tracker_${parsedTorrent.info.name}.torrent`, torrentBuffer)
writeTorrentFile(torrentFileName, torrentBuffer)
]).then(() => {

})
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {


function filterTorrents(infoHash, params, cb) {
console.log('infoHash:', infoHash);
return checkTorrentIsTracked(infoHash).then(isTracked => {
if (isTracked) {
cb(null);
Expand Down
4 changes: 1 addition & 3 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ export function checkEnvironmentVariables() {
'CAN_TRACKER_WEB_SEED_URL'
]);
} catch (err) {
console.error('You need to set the following environment variables for CanTracker to work');
console.error('CAN_TRACKER_ANNOUNCE_URL', 'CAN_TRACKER_PATH', 'CAN_TRACKER_PORT');
console.log(process.env);
console.error(err.message);
process.exit(1);
}
}

0 comments on commit 4fec718

Please sign in to comment.