mirror of
https://github.com/ProjectSynthoria/SynthoriaArchive.git
synced 2025-03-12 15:26:56 +02:00
Integrate tracker API for torrent ban/unban
This commit is contained in:
parent
024c90022a
commit
602d35bab7
3 changed files with 34 additions and 4 deletions
|
@ -43,7 +43,9 @@ MAX_FILES_VIEW = 1000
|
|||
# Setting to make sure main announce url is present in torrent
|
||||
#
|
||||
ENFORCE_MAIN_ANNOUNCE_URL = False
|
||||
MAIN_ANNOUNCE_URL = ''
|
||||
MAIN_ANNOUNCE_URL = 'http://127.0.0.1:6881/announce'
|
||||
TRACKER_API_URL = 'http://127.0.0.1:6881/api'
|
||||
TRACKER_API_AUTH = 'topsecret'
|
||||
|
||||
BACKUP_TORRENT_FOLDER = 'torrents'
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import json
|
||||
import os
|
||||
from ipaddress import ip_address
|
||||
from urllib.parse import urlencode
|
||||
from urllib.request import urlopen
|
||||
|
||||
import flask
|
||||
from werkzeug import secure_filename
|
||||
|
@ -211,3 +213,25 @@ def handle_torrent_upload(upload_form, uploading_user=None, fromAPI=False):
|
|||
torrent_file.close()
|
||||
|
||||
return torrent
|
||||
|
||||
|
||||
def tracker_api(info_hashes, method):
|
||||
url = app.config.get('TRACKER_API_URL')
|
||||
if not url:
|
||||
return False
|
||||
|
||||
qs = []
|
||||
qs.append(('auth', app.config.get('TRACKER_API_AUTH')))
|
||||
qs.append(('method', method))
|
||||
|
||||
for infohash in info_hashes:
|
||||
qs.append(('info_hash', infohash))
|
||||
|
||||
qs = urlencode(qs)
|
||||
url += '?' + qs
|
||||
try:
|
||||
req = urlopen(url)
|
||||
except:
|
||||
return False
|
||||
|
||||
return req.status == 200
|
||||
|
|
|
@ -179,23 +179,27 @@ def delete_torrent(torrent_id):
|
|||
db.session.add(torrent)
|
||||
|
||||
elif form.ban.data and not torrent.banned and editor.is_moderator:
|
||||
action = 'banned'
|
||||
torrent.banned = True
|
||||
if not torrent.deleted:
|
||||
torrent.deleted = True
|
||||
action = 'deleted and banned'
|
||||
else:
|
||||
action = 'banned'
|
||||
backend.tracker_api([torrent.info_hash], 'ban')
|
||||
db.session.add(torrent)
|
||||
|
||||
elif form.undelete.data and torrent.deleted:
|
||||
action = 'undeleted'
|
||||
torrent.deleted = False
|
||||
if torrent.banned:
|
||||
action = 'undeleted and unbanned'
|
||||
torrent.banned = False
|
||||
backend.tracker_api([torrent.info_hash], 'unban')
|
||||
db.session.add(torrent)
|
||||
|
||||
elif form.unban.data and torrent.banned:
|
||||
action = 'unbanned'
|
||||
torrent.banned = False
|
||||
backend.tracker_api([torrent.info_hash], 'unban')
|
||||
db.session.add(torrent)
|
||||
|
||||
if not action:
|
||||
|
|
Loading…
Add table
Reference in a new issue