mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 09:54:30 +01:00
simplifed robots generator
This commit is contained in:
parent
344755cbd0
commit
8b6c4a9383
@ -55,7 +55,6 @@
|
||||
<PackageReference Include="NicolasDorier.StandardConfiguration" Version="1.0.0.18" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.2" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.2" />
|
||||
<PackageReference Include="Robotify.AspNetCore" Version="1.0.0" />
|
||||
<PackageReference Include="Serilog" Version="2.7.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
|
||||
|
@ -8,6 +8,8 @@ using BTCPayServer.Models;
|
||||
using NBitcoin.DataEncoders;
|
||||
using NBitcoin.Payment;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using BTCPayServer.Services;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NBitcoin;
|
||||
using Newtonsoft.Json;
|
||||
@ -16,10 +18,12 @@ namespace BTCPayServer.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly SettingsRepository _SettingsRepository;
|
||||
public IHttpClientFactory HttpClientFactory { get; }
|
||||
|
||||
public HomeController(IHttpClientFactory httpClientFactory)
|
||||
public HomeController(IHttpClientFactory httpClientFactory, SettingsRepository settingsRepository)
|
||||
{
|
||||
_SettingsRepository = settingsRepository;
|
||||
HttpClientFactory = httpClientFactory;
|
||||
}
|
||||
public IActionResult Index()
|
||||
@ -103,5 +107,16 @@ namespace BTCPayServer.Controllers
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
[Route("robots.txt")]
|
||||
public async Task<IActionResult> Robots()
|
||||
{
|
||||
var settings = await _SettingsRepository.GetSettingAsync<PoliciesSettings>();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.AppendLine("user-agent: *");
|
||||
stringBuilder.AppendLine($"disallow: {(settings.DiscourageSearchEngines? "/": string.Empty)}");
|
||||
|
||||
return Content(stringBuilder.ToString(), "text/plain", Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BTCPayServer.Services;
|
||||
using Robotify.AspNetCore;
|
||||
|
||||
namespace BTCPayServer.Hosting
|
||||
{
|
||||
public class BTCPayRobotProvider : IRobotifyRobotGroupProvider
|
||||
{
|
||||
private readonly SettingsRepository _SettingsRepository;
|
||||
|
||||
public BTCPayRobotProvider(SettingsRepository settingsRepository)
|
||||
{
|
||||
_SettingsRepository = settingsRepository;
|
||||
}
|
||||
public IEnumerable<RobotGroup> Get()
|
||||
{
|
||||
var settings = _SettingsRepository.GetSettingAsync<PoliciesSettings>().GetAwaiter().GetResult();
|
||||
if (settings.DiscourageSearchEngines)
|
||||
{
|
||||
yield return new RobotGroup()
|
||||
{
|
||||
UserAgent = "*",
|
||||
Disallow = new[] {"/"}
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return new RobotGroup()
|
||||
{
|
||||
UserAgent = "*",
|
||||
Disallow = Array.Empty<string>()
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -61,7 +61,6 @@ namespace BTCPayServer.Hosting
|
||||
Logs.Configure(LoggerFactory);
|
||||
services.ConfigureBTCPayServer(Configuration);
|
||||
services.AddMemoryCache();
|
||||
services.AddRobotify(configurer => configurer.AddRobotGroupProvider<BTCPayRobotProvider>());
|
||||
services.AddIdentity<ApplicationUser, IdentityRole>()
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
@ -179,7 +178,6 @@ namespace BTCPayServer.Hosting
|
||||
});
|
||||
app.UseWebSockets();
|
||||
app.UseStatusCodePages();
|
||||
app.UseRobotify();
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
|
Loading…
Reference in New Issue
Block a user