mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-07-12 18:53:22 +02:00
change announce url to default value when user download torrent file,and append passkey value at announce url
This commit is contained in:
@@ -104,8 +104,8 @@
|
||||
ENTER_TMDB_ID: 'Please enter theMovieDB id <span style="font-size: 10pt;">[<a href="https://www.themoviedb.org/" target="_blank">find id on themofiedb.org</a>]</span>',
|
||||
LOAD_TMDB_INFO: 'Load info',
|
||||
TMDB_ID: 'TMDB ID',
|
||||
TMDB_ID_OK: 'MDB ID is ok! Get info successfully',
|
||||
TMDB_ID_ERROR: 'MDB ID is error! Get info failed',
|
||||
TMDB_ID_OK: 'TMDB ID is ok! Get info successfully',
|
||||
TMDB_ID_ERROR: 'TMDB ID is error! Get info failed',
|
||||
TMDB_ID_REQUIRED: 'Please enter TMDB ID',
|
||||
TMDB_MOVIE_INFO: 'The movie info from TMDB',
|
||||
TMDB_IS_LOADING: 'Loading the movie info, please wait...',
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
template: '<ui-view/>'
|
||||
})
|
||||
.state('torrents.movie', {
|
||||
url: '/torrents/movie',
|
||||
url: '/movie',
|
||||
templateUrl: '/modules/torrents/client/views/movie-list.client.view.html'
|
||||
})
|
||||
.state('torrents.uploads', {
|
||||
url: '/torrents/uploads',
|
||||
url: '/uploads',
|
||||
templateUrl: '/modules/torrents/client/views/uploads-torrents.client.view.html'
|
||||
});
|
||||
}
|
||||
|
||||
@@ -209,10 +209,10 @@
|
||||
});
|
||||
}
|
||||
}, function (err) {
|
||||
Notification.error({
|
||||
message: err.data.message,
|
||||
title: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TORRENT_DOWNLOAD_ERROR')
|
||||
});
|
||||
//Notification.error({
|
||||
// message: 'ERROR',
|
||||
// title: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TORRENT_DOWNLOAD_ERROR')
|
||||
//});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@
|
||||
|
||||
var torrent = new TorrentsService({
|
||||
info_hash: vm.torrentInfo.info_hash,
|
||||
torrent_filename: vm.tFile.name,
|
||||
torrent_filename: vm.torrentInfo.filename,
|
||||
torrent_tmdb_id: vm.tmdb_id,
|
||||
torrent_imdb_id: vm.movieinfo.imdb_id,
|
||||
torrent_title: vm.movieinfo.title,
|
||||
|
||||
@@ -12,6 +12,7 @@ var path = require('path'),
|
||||
Torrent = mongoose.model('Torrent'),
|
||||
fs = require('fs'),
|
||||
nt = require('nt'),
|
||||
benc = require('bncode'),
|
||||
validator = require('validator'),
|
||||
tmdb = require('moviedb')(config.meanTorrentConfig.tmdbConfig.key);
|
||||
|
||||
@@ -99,6 +100,7 @@ exports.upload = function (req, res) {
|
||||
|
||||
function checkAnnounce() {
|
||||
return new Promise(function (resolve, reject) {
|
||||
console.log(req.file.filename);
|
||||
var newfile = config.uploads.torrent.file.dest + req.file.filename;
|
||||
nt.read(newfile, function (err, torrent) {
|
||||
var message = '';
|
||||
@@ -107,8 +109,8 @@ exports.upload = function (req, res) {
|
||||
message = 'Read torrent file faild';
|
||||
reject(message);
|
||||
} else {
|
||||
if (!config.announce.open_tracker) {
|
||||
if (torrent.metadata.announce !== config.announce.url) {
|
||||
if (!config.meanTorrentConfig.announce.open_tracker) {
|
||||
if (torrent.metadata.announce !== config.meanTorrentConfig.announce.url) {
|
||||
console.log(torrent.metadata.announce);
|
||||
message = 'ANNOUNCE_URL_ERROR';
|
||||
|
||||
@@ -124,6 +126,7 @@ exports.upload = function (req, res) {
|
||||
}
|
||||
torrentinfo = torrent.metadata;
|
||||
torrentinfo.info_hash = torrent.infoHash();
|
||||
torrentinfo.filename = req.file.filename;
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
@@ -174,33 +177,67 @@ exports.upload = function (req, res) {
|
||||
* @param res
|
||||
*/
|
||||
exports.download = function (req, res) {
|
||||
var torrent_data = null;
|
||||
var filePath = config.uploads.torrent.file.dest + req.torrent.torrent_filename;
|
||||
var stat = fs.statSync(filePath);
|
||||
|
||||
fs.exists(filePath, function (exists) {
|
||||
if (exists) {
|
||||
var options = {
|
||||
root: path.join(__dirname, '../../../../'),
|
||||
headers: {
|
||||
'Content-Type': 'application/x-bittorrent',
|
||||
'Content-Disposition': 'attachment; filename=' + config.meanTorrentConfig.announce.announce_prefix + req.torrent.torrent_filename,
|
||||
'Content-Length': stat.size
|
||||
}
|
||||
};
|
||||
res.sendFile(filePath, options);
|
||||
getTorrentFileData(filePath)
|
||||
.then(function () {
|
||||
//var options = {
|
||||
// root: path.join(__dirname, '../../../../'),
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/x-bittorrent',
|
||||
// 'Content-Disposition': 'attachment; filename=' + config.meanTorrentConfig.announce.announce_prefix + req.torrent.torrent_filename,
|
||||
// 'Content-Length': stat.size
|
||||
// }
|
||||
//};
|
||||
//res.sendFile(filePath, options);
|
||||
|
||||
//res.writeHead(200, {
|
||||
// 'Content-Type': 'application/octet-stream',
|
||||
// 'Content-Disposition': 'attachment; filename=' + config.meanTorrentConfig.announce.announce_prefix + req.torrent.torrent_filename,
|
||||
// 'Content-Length': stat.size
|
||||
//});
|
||||
//fs.createReadStream(filePath).pipe(res);
|
||||
res.set('Content-Type', 'application/x-bittorrent');
|
||||
res.set('Content-Disposition', 'attachment; filename=' + config.meanTorrentConfig.announce.announce_prefix + req.torrent.torrent_filename);
|
||||
res.set('Content-Length', stat.size);
|
||||
|
||||
console.log(torrent_data);
|
||||
res.send(benc.encode(torrent_data));
|
||||
|
||||
//res.writeHead(200, {
|
||||
// 'Content-Type': 'application/octet-stream',
|
||||
// 'Content-Disposition': 'attachment; filename=' + config.meanTorrentConfig.announce.announce_prefix + req.torrent.torrent_filename,
|
||||
// 'Content-Length': stat.size
|
||||
//});
|
||||
//fs.createReadStream(filePath).pipe(res);
|
||||
})
|
||||
.catch(function (err) {
|
||||
res.status(422).send(err);
|
||||
});
|
||||
} else {
|
||||
res.status(401).send({
|
||||
message: 'FILE_DOES_NOT_EXISTS'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function getTorrentFileData(file) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
nt.read(file, function (err, torrent) {
|
||||
var message = '';
|
||||
|
||||
if (err) {
|
||||
message = 'Read torrent file faild';
|
||||
reject(message);
|
||||
} else {
|
||||
if (!config.meanTorrentConfig.announce.open_tracker) {
|
||||
var announce = config.meanTorrentConfig.announce.url + '/' + req.user.passkey;
|
||||
torrent.metadata.announce = announce;
|
||||
}
|
||||
torrent_data = torrent.metadata;
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user