forked from Kieran/void.cat
Add trackers
This commit is contained in:
parent
ef3ebb867d
commit
0a827651a2
@ -54,7 +54,7 @@ public class DownloadController : Controller
|
||||
{
|
||||
var t = await voidFile.Metadata!.MakeTorrent(
|
||||
await _storage.Open(new(gid, Enumerable.Empty<RangeRequest>()), CancellationToken.None),
|
||||
_settings.SiteUrl);
|
||||
_settings.SiteUrl, _settings.TorrentTrackers);
|
||||
|
||||
Response.Headers.ContentDisposition = $"inline; filename=\"{id}\"";
|
||||
Response.ContentType = "application/x-bittorent";
|
||||
|
@ -49,6 +49,7 @@ public static class Extensions
|
||||
base58 = Path.GetFileNameWithoutExtension(base58);
|
||||
var guidBytes = enc.DecodeData(base58);
|
||||
if (guidBytes.Length != 16) throw new VoidInvalidIdException(base58);
|
||||
|
||||
return new Guid(guidBytes);
|
||||
}
|
||||
|
||||
@ -275,7 +276,7 @@ public static class Extensions
|
||||
public static bool HasGoogle(this VoidSettings settings)
|
||||
=> settings.Google != null;
|
||||
|
||||
public static async Task<Torrent> MakeTorrent(this FileMeta meta, Stream fileStream, Uri baseAddress)
|
||||
public static async Task<Torrent> MakeTorrent(this FileMeta meta, Stream fileStream, Uri baseAddress, List<string> trackers)
|
||||
{
|
||||
const int pieceSize = 262_144;
|
||||
const int pieceHashLen = 20;
|
||||
@ -313,6 +314,8 @@ public static class Extensions
|
||||
IsPrivate = false,
|
||||
PieceSize = pieceSize,
|
||||
Pieces = await BuildPieces(),
|
||||
// ReSharper disable once CoVariantArrayConversion
|
||||
Trackers = trackers.Select(a => new[] {a}).ToArray(),
|
||||
ExtraFields = new BDictionary
|
||||
{
|
||||
{"url-list", webSeed.ToString()}
|
||||
|
@ -110,6 +110,18 @@ namespace VoidCat.Model
|
||||
/// Google application settings
|
||||
/// </summary>
|
||||
public OAuthDetails? Google { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// A list of trackers to attach to torrent files
|
||||
/// </summary>
|
||||
public List<string> TorrentTrackers { get; init; } = new()
|
||||
{
|
||||
"wss://tracker.btorrent.xyz",
|
||||
"wss://tracker.openwebtorrent.com",
|
||||
"udp://tracker.opentrackr.org:1337/announce",
|
||||
"udp://tracker.openbittorrent.com:6969/announce",
|
||||
"http://tracker.openbittorrent.com:80/announce"
|
||||
};
|
||||
}
|
||||
|
||||
public sealed class TorSettings
|
||||
|
@ -86,8 +86,15 @@ public class LocalDiskFileStore : StreamFileStore, IFileStore
|
||||
|
||||
if (payload.Segment == payload.TotalSegments)
|
||||
{
|
||||
var t = await vf.Metadata!.MakeTorrent(new FileStream(finalPath, FileMode.Open), _settings.SiteUrl);
|
||||
vf.Metadata!.MagnetLink = t.GetMagnetLink();
|
||||
var t = await vf.Metadata!.MakeTorrent(
|
||||
new FileStream(finalPath, FileMode.Open),
|
||||
_settings.SiteUrl,
|
||||
_settings.TorrentTrackers);
|
||||
|
||||
var ub = new UriBuilder(_settings.SiteUrl);
|
||||
ub.Path = $"/d/{vf.Id.ToBase58()}.torrent";
|
||||
|
||||
vf.Metadata!.MagnetLink = $"{t.GetMagnetLink()}&xs={Uri.EscapeDataString(ub.ToString())}";
|
||||
}
|
||||
|
||||
return vf;
|
||||
|
Loading…
Reference in New Issue
Block a user