Skip to content

Commit

Permalink
Support multiple mirror feeds
Browse files Browse the repository at this point in the history
Added possibility to specify multiple PackageSources in the appsettings.
  • Loading branch information
lkonrad-q-soft authored Jul 19, 2024
2 parents fe7781d + ab5c5f3 commit 400c35d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 29 deletions.
26 changes: 0 additions & 26 deletions src/BaGetter.Core/Configuration/MirrorOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace BaGetter.Core;

Expand Down Expand Up @@ -79,28 +78,3 @@ private void UpdateSources()
Sources = [new MirrorSource { PackageSource = PackageSource, Legacy = Legacy }];
}
}

public class MirrorSource
{
public Uri PackageSource { get; set; }
public bool Legacy { get; set; }

public override bool Equals(object obj)
{
// Check for null and compare run-time types.
if (obj is null || !GetType().Equals(obj.GetType()))
{
return false;
}
else
{
var ms = (MirrorSource)obj;
return (PackageSource.Equals(ms.PackageSource)) && (Legacy == ms.Legacy);
}
}

public override int GetHashCode()
{
return HashCode.Combine(PackageSource, Legacy);
}
}
33 changes: 33 additions & 0 deletions src/BaGetter.Core/Configuration/MirrorSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaGetter.Core;

public class MirrorSource
{
public Uri PackageSource { get; set; }
public bool Legacy { get; set; }

public override bool Equals(object obj)
{
// Check for null and compare run-time types.
if (obj is null || !GetType().Equals(obj.GetType()))
{
return false;
}
else
{
var ms = (MirrorSource)obj;
return (PackageSource.Equals(ms.PackageSource)) && (Legacy == ms.Legacy);
}
}

public override int GetHashCode()
{
return HashCode.Combine(PackageSource, Legacy);
}
}

4 changes: 2 additions & 2 deletions src/BaGetter.Core/Extensions/DependencyInjectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ private static List<IUpstreamClient> CreateUpstreamClients(IServiceProvider prov
private static V2UpstreamClient CreateV2Client(IServiceProvider scopedProvider, MirrorSource mirrorSource)
{
var logger = scopedProvider.GetRequiredService<ILogger<V2UpstreamClient>>();
var mirrorOptions = new MirrorOptions() { PackageSource = mirrorSource.PackageSource, Legacy = true };

var mirrorOptions = new MirrorSource() { PackageSource = mirrorSource.PackageSource, Legacy = true };
return new V2UpstreamClient(mirrorOptions, logger);
}

Expand Down
2 changes: 1 addition & 1 deletion src/BaGetter.Core/Upstream/Clients/V2UpstreamClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class V2UpstreamClient : IUpstreamClient, IDisposable
private static readonly char[] AuthorsSeparators = new[] { ',', ';', '\t', '\n', '\r' };

public V2UpstreamClient(
MirrorOptions options,
MirrorSource options,
ILogger logger)
{
ArgumentNullException.ThrowIfNull(options);
Expand Down

0 comments on commit 400c35d

Please sign in to comment.