add public/private torrent swarms
This commit is contained in:
parent
4cb06525a4
commit
c780572e69
2 changed files with 13 additions and 7 deletions
|
@ -15,7 +15,7 @@ from storage import Storage
|
|||
|
||||
from util.registry.queuefile import QueueFile
|
||||
from util.registry.queueprocess import QueueProcess
|
||||
from util.registry.torrent import make_torrent, private_torrent_name
|
||||
from util.registry.torrent import make_torrent, per_user_torrent_filename, public_torrent_filename
|
||||
from formats.squashed import SquashedDockerImage
|
||||
from formats.aci import ACIImage
|
||||
from endpoints.v2.blob import BLOB_DIGEST_ROUTE
|
||||
|
@ -284,7 +284,8 @@ def get_squashed_tag(namespace, repository, tag):
|
|||
@process_auth
|
||||
def get_tag_torrent(namespace, repository, digest):
|
||||
permission = ReadRepositoryPermission(namespace, repository)
|
||||
if not permission.can() and not model.repository.repository_is_public(namespace, repository):
|
||||
public_repo = model.repository.repository_is_public(namespace, repository)
|
||||
if not permission.can() and not public_repo:
|
||||
abort(403)
|
||||
|
||||
user = get_authenticated_user()
|
||||
|
@ -307,12 +308,14 @@ def get_tag_torrent(namespace, repository, digest):
|
|||
except model.TorrentInfoDoesNotExist:
|
||||
abort(404)
|
||||
|
||||
name = private_torrent_name(user.uuid, blob.uuid)
|
||||
if public_repo:
|
||||
name = public_torrent_filename(blob.uuid)
|
||||
else:
|
||||
name = per_user_torrent_filename(user.uuid, blob.uuid)
|
||||
torrent_file = make_torrent(name, webseed, blob.image_size,
|
||||
torrent_info.piece_length, torrent_info.pieces)
|
||||
|
||||
headers = {'Content-Type': 'application/x-bittorrent',
|
||||
'Content-Disposition': 'attachment; filename={0}.torrent'.format(name),
|
||||
'Content-Length': len(torrent_file)}
|
||||
'Content-Disposition': 'attachment; filename={0}.torrent'.format(name)}
|
||||
|
||||
return make_response((torrent_file, 200, headers))
|
||||
return make_response(torrent_file, 200, headers)
|
||||
|
|
|
@ -10,7 +10,10 @@ from app import app
|
|||
TRACKER_ANNOUNCE_URL = app.config.get('BT_TRACKER_ANNOUNCE_URL')
|
||||
NAMING_SALT = app.config.get('BT_NAMING_SALT')
|
||||
|
||||
def private_torrent_name(user_uuid, blob_uuid):
|
||||
def public_torrent_filename(blob_uuid):
|
||||
return hashlib.sha256(blob_uuid).hexdigest()
|
||||
|
||||
def per_user_torrent_filename(user_uuid, blob_uuid):
|
||||
return hashlib.sha256(blob_uuid + user_uuid + NAMING_SALT).hexdigest()
|
||||
|
||||
|
||||
|
|
Reference in a new issue