mirror of
https://github.com/zoriya/flood.git
synced 2025-12-06 07:16:18 +00:00
server: also modify torrent file on "Set Tracker"
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -3298,6 +3298,14 @@
|
||||
"tweetnacl": "^0.14.3"
|
||||
}
|
||||
},
|
||||
"bencode": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/bencode/-/bencode-2.0.1.tgz",
|
||||
"integrity": "sha512-2uhEl8FdjSBUyb69qDTgOEeeqDTa+n3yMQzLW0cOzNf1Ow5bwcg3idf+qsWisIKRH8Bk8oC7UXL8irRcPA8ZEQ==",
|
||||
"requires": {
|
||||
"safe-buffer": "^5.1.1"
|
||||
}
|
||||
},
|
||||
"big.js": {
|
||||
"version": "5.2.2",
|
||||
"resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz",
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
"axios": "^0.20.0",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"babel-loader": "^8.0.6",
|
||||
"bencode": "^2.0.1",
|
||||
"body-parser": "^1.18.3",
|
||||
"case-sensitive-paths-webpack-plugin": "2.3.0",
|
||||
"chalk": "^4.1.0",
|
||||
|
||||
@@ -249,4 +249,9 @@ torrentListPropMap.set('peersTotal', {
|
||||
transformValue: (value) => Number(value.substr(0, value.indexOf('|||'))),
|
||||
});
|
||||
|
||||
torrentListPropMap.set('session', {
|
||||
methodCall: 'cat=(session.path), (d.hash)',
|
||||
transformValue: defaultTransformer,
|
||||
});
|
||||
|
||||
module.exports = torrentListPropMap;
|
||||
|
||||
@@ -10,6 +10,7 @@ const fileUtil = require('../util/fileUtil');
|
||||
const settings = require('./settings');
|
||||
const torrentFilePropsMap = require('../../shared/constants/torrentFilePropsMap');
|
||||
const torrentPeerPropsMap = require('../../shared/constants/torrentPeerPropsMap');
|
||||
const torrentFileUtil = require('../util/torrentFileUtil');
|
||||
const torrentStatusMap = require('../../shared/constants/torrentStatusMap');
|
||||
const torrentTrackerPropsMap = require('../../shared/constants/torrentTrackerPropsMap');
|
||||
|
||||
@@ -385,6 +386,9 @@ const client = {
|
||||
|
||||
request.setTracker(data);
|
||||
request.onComplete((response, error) => {
|
||||
// Modify tracker URL in torrent files
|
||||
torrentFileUtil.setTracker(services, data);
|
||||
|
||||
// Fetch the latest torrent list to re-index trackerURI.
|
||||
services.torrentService.fetchTorrentList();
|
||||
callback(response, error);
|
||||
|
||||
29
server/util/torrentFileUtil.js
Normal file
29
server/util/torrentFileUtil.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const bencode = require('bencode');
|
||||
const fs = require('fs');
|
||||
|
||||
const setTracker = (services, options) => {
|
||||
const {tracker, hashes} = options;
|
||||
|
||||
[...new Set(hashes)].forEach((hash) => {
|
||||
const torrent = services.torrentService.getTorrent(hash).session.concat('.torrent');
|
||||
fs.readFile(torrent, (err, data) => {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
const torrentData = bencode.decode(data);
|
||||
|
||||
if (torrentData.announce != null) {
|
||||
torrentData.announce = Buffer.from(tracker);
|
||||
|
||||
fs.writeFileSync(torrent, bencode.encode(torrentData));
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const torrentFileUtil = {
|
||||
setTracker,
|
||||
};
|
||||
|
||||
module.exports = torrentFileUtil;
|
||||
Reference in New Issue
Block a user