Skip to content

Commit

Permalink
handle single file torrents
Browse files Browse the repository at this point in the history
  • Loading branch information
canibanoglu committed Nov 4, 2019
1 parent b05d6f5 commit c27b91a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 deletions bin/createTorrent.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#!/usr/bin/env node
import { checkEnvironmentVariables } from '../utils';

checkEnvironmentVariables();

const path = require('path');
const createTorrent = require('create-torrent');
const parseTorrent = require('parse-torrent');
const fs = require('fs').promises;
const fsStatSync = require('fs').statSync;
const argv = require('minimist')(process.argv.slice(2));

const {
addTorrent: addTorrentToDatabase
} = require('../databaseOperations.js');

// TODO: Check for env variables and fail if not present with instructions
checkEnvironmentVariables();

const {
CAN_TRACKER_ANNOUNCE_URL,
Expand Down Expand Up @@ -42,14 +41,26 @@ async function writeTorrentFile(fileName, torrentBuffer) {
});
}

let webSeedUrl = CAN_TRACKER_WEB_SEED_URL;

if (argv._.length === 1) {
const [ fileName ] = argv._;
const stat = fsStatSync(fileName);
if (stat.isFile()) {
const split = fileName.split(path.sep);
const name = split[split.length - 1];
webSeedUrl = path.join(CAN_TRACKER_WEB_SEED_URL, name);
}
}

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

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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "can-tracker",
"version": "0.0.5",
"version": "0.0.6",
"description": "Starts a simple bittorent tracker for filesharing",
"scripts": {
"start": "node -r dotenv/config entry.js",
Expand Down

0 comments on commit c27b91a

Please sign in to comment.