Browse Source

Migrated to .NET Core 5.0

pull/111/head 5.0.0
Teknikode 1 year ago
parent
commit
f5f2f4da86
  1. 4
      Configuration/Configuration.csproj
  2. 4
      ContentScanningService/ContentScanningService.csproj
  3. 6
      GitService/GitService.csproj
  4. 15
      IdentityServer/IdentityServer.csproj
  5. 8
      IdentityServer/Middleware/ErrorHandlerMiddleware.cs
  6. 4
      Logging/Logging.csproj
  7. 4
      MailService/MailService.csproj
  8. 2
      ServiceWorker/ServiceWorker.csproj
  9. 3
      Teknik.sln
  10. 12
      Teknik/.config/dotnet-tools.json
  11. 1137
      Teknik/App_Data/endpointMappings.json
  12. 1
      Teknik/Areas/API/APIController.cs
  13. 1
      Teknik/Areas/API/V1/Controllers/PasteAPIv1Controller.cs
  14. 1
      Teknik/Areas/API/V1/Controllers/ShortenAPIv1Controller.cs
  15. 1
      Teknik/Areas/API/V1/Controllers/UploadAPIv1Controller.cs
  16. 1
      Teknik/Areas/Blog/Controllers/BlogController.cs
  17. 1
      Teknik/Areas/Dev/Controllers/DevController.cs
  18. 1
      Teknik/Areas/Paste/Controllers/PasteController.cs
  19. 1
      Teknik/Areas/RSS/Controllers/RSSController.cs
  20. 1
      Teknik/Areas/Shortener/Controllers/ShortenerController.cs
  21. 3
      Teknik/Areas/Upload/Controllers/UploadController.cs
  22. 7
      Teknik/Areas/Upload/UploadHelper.cs
  23. 1
      Teknik/Areas/User/Controllers/UserController.cs
  24. 23
      Teknik/Areas/User/Utility/IdentityHelper.cs
  25. 1
      Teknik/Areas/User/Utility/UserHelper.cs
  26. 1
      Teknik/Areas/Vault/Controllers/VaultController.cs
  27. 6
      Teknik/Controllers/DefaultController.cs
  28. 12
      Teknik/Data/TeknikEntities.cs
  29. 1
      Teknik/Filters/TrackPageView.cs
  30. 1
      Teknik/Middleware/CORSMiddleware.cs
  31. 1
      Teknik/Middleware/CSPMiddleware.cs
  32. 21
      Teknik/Middleware/ErrorHandlerMiddleware.cs
  33. 35
      Teknik/Program.cs
  34. 4
      Teknik/Properties/PublishProfiles/Teknik - Development.pubxml
  35. 4
      Teknik/Properties/launchSettings.json
  36. 844
      Teknik/Routes.cs
  37. 72
      Teknik/Startup.cs
  38. 42
      Teknik/Teknik.csproj
  39. 2
      Teknik/Views/Shared/_Footer.cshtml
  40. 3
      Teknik/_ViewImports.cshtml
  41. 6
      Tracking/Tracking.csproj
  42. 4
      Utilities/BufferedFileStreamResult.cs
  43. 1
      Utilities/Constants.cs
  44. 2
      Utilities/FileHelper.cs
  45. 13
      Utilities/IdentityClientScope.cs
  46. 100
      Utilities/Routing/EndpointHelper.cs
  47. 18
      Utilities/Routing/EndpointMapping.cs
  48. 13
      Utilities/Routing/HostType.cs
  49. 78
      Utilities/Routing/SubdomainEndpointExtension.cs
  50. 2
      Utilities/Routing/SubdomainRoute.cs
  51. 2
      Utilities/Routing/SubdomainRouteExtension.cs
  52. 81
      Utilities/Routing/UrlExtensions.cs
  53. 5
      Utilities/TagHelpers/BundleTagHelper.cs
  54. 16
      Utilities/Utilities.csproj
  55. 2
      global.json

4
Configuration/Configuration.csproj

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Teknik.Configuration</RootNamespace>
<AssemblyName>Teknik.Configuration</AssemblyName>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;linux-arm;osx-x64</RuntimeIdentifiers>
@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>

4
ContentScanningService/ContentScanningService.csproj

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>Teknik.ContentScanningService</AssemblyName>
<RootNamespace>Teknik.ContentScanningService</RootNamespace>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;linux-arm;osx-x64</RuntimeIdentifiers>
@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nClam" Version="4.0.1" />
<PackageReference Include="nClam" Version="5.0.1" />
</ItemGroup>
<ItemGroup>

6
GitService/GitService.csproj

@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>Teknik.GitService</AssemblyName>
<RootNamespace>Teknik.GitService</RootNamespace>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;linux-arm;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.0.13" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="MySql.Data" Version="8.0.25" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>

15
IdentityServer/IdentityServer.csproj

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>Teknik.IdentityServer</AssemblyName>
<RootNamespace>Teknik.IdentityServer</RootNamespace>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;linux-arm;osx-x64</RuntimeIdentifiers>
@ -15,12 +15,13 @@ @@ -15,12 +15,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="IdentityServer4" Version="2.5.1" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.7.0" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="2.5.1" />
<PackageReference Include="IdentityServer4.EntityFramework" Version="2.5.1" />
<PackageReference Include="Microsoft.AspNetCore.All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="IdentityServer4" Version="4.1.2" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="4.1.2" />
<PackageReference Include="IdentityServer4.EntityFramework" Version="4.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
</ItemGroup>
<ItemGroup>

8
IdentityServer/Middleware/ErrorHandlerMiddleware.cs

@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Builder; @@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -94,12 +93,7 @@ namespace Teknik.IdentityServer.Middleware @@ -94,12 +93,7 @@ namespace Teknik.IdentityServer.Middleware
{
public static IApplicationBuilder UseErrorHandler(this IApplicationBuilder builder, Config config)
{
var routes = new RouteBuilder(builder)
{
DefaultHandler = builder.ApplicationServices.GetRequiredService<MvcRouteHandler>(),
};
return builder.UseMiddleware<ErrorHandlerMiddleware>(routes.Build());
return builder.UseMiddleware<ErrorHandlerMiddleware>();
}
}
}

4
Logging/Logging.csproj

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>Teknik.Logging</AssemblyName>
<RootNamespace>Teknik.Logging</RootNamespace>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;linux-arm;osx-x64</RuntimeIdentifiers>
@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
</ItemGroup>
<ItemGroup>

4
MailService/MailService.csproj

@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>Teknik.MailService</AssemblyName>
<RootNamespace>Teknik.MailService</RootNamespace>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;linux-arm;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.0.13" />
<PackageReference Include="MySql.Data" Version="8.0.25" />
</ItemGroup>
<ItemGroup>

2
ServiceWorker/ServiceWorker.csproj

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Teknik.ServiceWorker</RootNamespace>
<AssemblyName>Teknik.ServiceWorker</AssemblyName>
</PropertyGroup>

3
Teknik.sln

@ -17,7 +17,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution @@ -17,7 +17,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitattributes = .gitattributes
.gitignore = .gitignore
global.json = global.json
Performance1.psess = Performance1.psess
README.md = README.md
EndProjectSection
EndProject
@ -31,7 +30,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceWorker", "ServiceWor @@ -31,7 +30,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceWorker", "ServiceWor
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer", "IdentityServer\IdentityServer.csproj", "{3434645B-B8B4-457A-8C85-342E6727CCEE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContentScanningService", "ContentScanningService\ContentScanningService.csproj", "{491FE626-ABC8-4D00-8C7F-0849C357201A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContentScanningService", "ContentScanningService\ContentScanningService.csproj", "{491FE626-ABC8-4D00-8C7F-0849C357201A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

12
Teknik/.config/dotnet-tools.json

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "5.0.7",
"commands": [
"dotnet-ef"
]
}
}
}

1137
Teknik/App_Data/endpointMappings.json

File diff suppressed because it is too large Load Diff

1
Teknik/Areas/API/APIController.cs

@ -14,6 +14,7 @@ using Teknik.Configuration; @@ -14,6 +14,7 @@ using Teknik.Configuration;
using Teknik.Data;
using Microsoft.AspNetCore.Mvc;
using Teknik.Logging;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.API.Controllers
{

1
Teknik/Areas/API/V1/Controllers/PasteAPIv1Controller.cs

@ -15,6 +15,7 @@ using Teknik.Data; @@ -15,6 +15,7 @@ using Teknik.Data;
using Teknik.Filters;
using Teknik.Logging;
using Teknik.Utilities;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.API.V1.Controllers
{

1
Teknik/Areas/API/V1/Controllers/ShortenAPIv1Controller.cs

@ -16,6 +16,7 @@ using Teknik.Data; @@ -16,6 +16,7 @@ using Teknik.Data;
using Teknik.Filters;
using Teknik.Logging;
using Teknik.Utilities;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.API.V1.Controllers
{

1
Teknik/Areas/API/V1/Controllers/UploadAPIv1Controller.cs

@ -21,6 +21,7 @@ using Teknik.Data; @@ -21,6 +21,7 @@ using Teknik.Data;
using Teknik.Filters;
using Teknik.Logging;
using Teknik.Utilities;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.API.V1.Controllers
{

1
Teknik/Areas/Blog/Controllers/BlogController.cs

@ -20,6 +20,7 @@ using Microsoft.AspNetCore.Authorization; @@ -20,6 +20,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Teknik.Logging;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.Blog.Controllers
{

1
Teknik/Areas/Dev/Controllers/DevController.cs

@ -8,6 +8,7 @@ using Teknik.Data; @@ -8,6 +8,7 @@ using Teknik.Data;
using Teknik.Filters;
using Teknik.Utilities;
using Teknik.Logging;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.Dev.Controllers
{

1
Teknik/Areas/Paste/Controllers/PasteController.cs

@ -21,6 +21,7 @@ using Teknik.Logging; @@ -21,6 +21,7 @@ using Teknik.Logging;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Diagnostics;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.Paste.Controllers
{

1
Teknik/Areas/RSS/Controllers/RSSController.cs

@ -22,6 +22,7 @@ using System.Text; @@ -22,6 +22,7 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.SyndicationFeed;
using Teknik.Logging;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.RSS.Controllers
{

1
Teknik/Areas/Shortener/Controllers/ShortenerController.cs

@ -14,6 +14,7 @@ using Teknik.Data; @@ -14,6 +14,7 @@ using Teknik.Data;
using Teknik.Filters;
using Teknik.Logging;
using Teknik.Utilities;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.Shortener.Controllers
{

3
Teknik/Areas/Upload/Controllers/UploadController.cs

@ -23,6 +23,7 @@ using Microsoft.AspNetCore.Http; @@ -23,6 +23,7 @@ using Microsoft.AspNetCore.Http;
using Teknik.Logging;
using Teknik.Areas.Users.Models;
using Teknik.ContentScanningService;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.Upload.Controllers
{
@ -259,7 +260,7 @@ namespace Teknik.Areas.Upload.Controllers @@ -259,7 +260,7 @@ namespace Teknik.Areas.Upload.Controllers
IdentityUserInfo userInfo = await IdentityHelper.GetIdentityUserInfo(_config, User.Identity.Name);
premiumAccount = userInfo.AccountType == AccountType.Premium;
}
if (!premiumAccount && upload.User != null)
if (!premiumAccount && upload.UserId != null)
{
IdentityUserInfo userInfo = await IdentityHelper.GetIdentityUserInfo(_config, upload.User.Username);
premiumAccount = userInfo.AccountType == AccountType.Premium;

7
Teknik/Areas/Upload/UploadHelper.cs

@ -135,5 +135,12 @@ namespace Teknik.Areas.Upload @@ -135,5 +135,12 @@ namespace Teknik.Areas.Upload
return false;
}
public static Models.Upload GetUpload(TeknikEntities db, string url)
{
Models.Upload upload = db.Uploads.Where(up => up.Url == url).FirstOrDefault();
return upload;
}
}
}

1
Teknik/Areas/User/Controllers/UserController.cs

@ -36,6 +36,7 @@ using System.Security.Cryptography; @@ -36,6 +36,7 @@ using System.Security.Cryptography;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.AspNetCore.Http;
using IdentityServer4.Models;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.Users.Controllers
{

23
Teknik/Areas/User/Utility/IdentityHelper.cs

@ -15,18 +15,24 @@ namespace Teknik.Areas.Users.Utility @@ -15,18 +15,24 @@ namespace Teknik.Areas.Users.Utility
{
public static class IdentityHelper
{
public static async Task<string> GetAccessToken(Config config)
public static async Task GetAccessToken(this HttpClient client, Config config)
{
return await GetAccessToken(config.UserConfig.IdentityServerConfig.Authority, config.UserConfig.IdentityServerConfig.ClientId, config.UserConfig.IdentityServerConfig.ClientSecret, "auth-api");
var token = await client.GetAccessToken(config.UserConfig.IdentityServerConfig.Authority, config.UserConfig.IdentityServerConfig.ClientId, config.UserConfig.IdentityServerConfig.ClientSecret, "auth-api");
client.SetBearerToken(token);
}
public static async Task<string> GetAccessToken(string authority, string clientId, string secret, string scope)
public static async Task<string> GetAccessToken(this HttpClient client, string authority, string clientId, string secret, string scope)
{
var disco = await DiscoveryClient.GetAsync(authority);
var disco = await client.GetDiscoveryDocumentAsync(authority);
if (disco.IsError) throw new Exception(disco.Error);
var tokenClient = new TokenClient(disco.TokenEndpoint, clientId, secret);
var tokenResponse = await tokenClient.RequestClientCredentialsAsync(scope);
var tokenResponse = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
{
Address = disco.TokenEndpoint,
ClientId = clientId,
ClientSecret = secret,
Scope = scope
});
if (tokenResponse.IsError) throw new Exception(tokenResponse.Error);
@ -42,7 +48,7 @@ namespace Teknik.Areas.Users.Utility @@ -42,7 +48,7 @@ namespace Teknik.Areas.Users.Utility
public static async Task<IdentityResult> Get(Config config, Uri url)
{
var client = new HttpClient();
client.SetBearerToken(await GetAccessToken(config));
await client.GetAccessToken(config);
var content = await client.GetStringAsync(url);
if (!string.IsNullOrEmpty(content))
@ -56,7 +62,8 @@ namespace Teknik.Areas.Users.Utility @@ -56,7 +62,8 @@ namespace Teknik.Areas.Users.Utility
public static async Task<IdentityResult> Post(Config config, Uri url, object data)
{
var client = new HttpClient();
client.SetBearerToken(await GetAccessToken(config));
await client.GetAccessToken(config);
var response = await client.PostAsJsonAsync(url, data);
if (response.IsSuccessStatusCode)

1
Teknik/Areas/User/Utility/UserHelper.cs

@ -32,6 +32,7 @@ using System.Net.Http; @@ -32,6 +32,7 @@ using System.Net.Http;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.Users.Utility
{

1
Teknik/Areas/Vault/Controllers/VaultController.cs

@ -24,6 +24,7 @@ using Teknik.Logging; @@ -24,6 +24,7 @@ using Teknik.Logging;
using Teknik.Models;
using Teknik.Utilities;
using Teknik.Utilities.Cryptography;
using Teknik.Utilities.Routing;
namespace Teknik.Areas.Vault.Controllers
{

6
Teknik/Controllers/DefaultController.cs

@ -52,7 +52,7 @@ namespace Teknik.Controllers @@ -52,7 +52,7 @@ namespace Teknik.Controllers
[HttpGet]
[AllowAnonymous]
[ResponseCache(Duration = 31536000, Location = ResponseCacheLocation.Any)]
public IActionResult Favicon([FromServices] IHostingEnvironment env)
public IActionResult Favicon([FromServices] IWebHostEnvironment env)
{
string imageFile = FileHelper.MapPath(env, Constants.FAVICON_PATH);
FileStream fs = new FileStream(imageFile, FileMode.Open, FileAccess.Read);
@ -63,7 +63,7 @@ namespace Teknik.Controllers @@ -63,7 +63,7 @@ namespace Teknik.Controllers
[HttpGet]
[AllowAnonymous]
[ResponseCache(Duration = 31536000, Location = ResponseCacheLocation.Any)]
public IActionResult Logo([FromServices] IHostingEnvironment env)
public IActionResult Logo([FromServices] IWebHostEnvironment env)
{
string imageFile = FileHelper.MapPath(env, Constants.LOGO_PATH);
FileStream fs = new FileStream(imageFile, FileMode.Open, FileAccess.Read);
@ -73,7 +73,7 @@ namespace Teknik.Controllers @@ -73,7 +73,7 @@ namespace Teknik.Controllers
// Get the Robots.txt
[HttpGet]
[AllowAnonymous]
public IActionResult Robots([FromServices] IHostingEnvironment env)
public IActionResult Robots([FromServices] IWebHostEnvironment env)
{
string dataDir = (string)AppDomain.CurrentDomain.GetData("DataDirectory");
string file = Path.Combine(dataDir, Constants.ROBOTS_PATH);

12
Teknik/Data/TeknikEntities.cs

@ -69,9 +69,9 @@ namespace Teknik.Data @@ -69,9 +69,9 @@ namespace Teknik.Data
// User
modelBuilder.Entity<User>()
.HasKey(u => u.UserId);
modelBuilder.Entity<User>().OwnsOne(u => u.UserSettings);
modelBuilder.Entity<User>().OwnsOne(u => u.BlogSettings);
modelBuilder.Entity<User>().OwnsOne(u => u.UploadSettings);
modelBuilder.Entity<User>().OwnsOne(u => u.UserSettings, us => us.ToTable("Users"));
modelBuilder.Entity<User>().OwnsOne(u => u.BlogSettings, bs => bs.ToTable("Users"));
modelBuilder.Entity<User>().OwnsOne(u => u.UploadSettings, us => us.ToTable("Users"));
modelBuilder.Entity<User>().HasMany(u => u.Features).WithOne(u => u.User);
modelBuilder.Entity<User>().HasMany(u => u.Uploads).WithOne(u => u.User);
modelBuilder.Entity<User>().HasMany(u => u.Pastes).WithOne(u => u.User);
@ -116,9 +116,9 @@ namespace Teknik.Data @@ -116,9 +116,9 @@ namespace Teknik.Data
modelBuilder.Entity<InviteCode>().ToTable("InviteCodes");
modelBuilder.Entity<UserFeature>().ToTable("UserFeatures");
// User Settings
modelBuilder.Entity<UserSettings>().ToTable("Users");
modelBuilder.Entity<BlogSettings>().ToTable("Users");
modelBuilder.Entity<UploadSettings>().ToTable("Users");
//modelBuilder.Entity<UserSettings>().ToTable("Users");
//modelBuilder.Entity<BlogSettings>().ToTable("Users");
//modelBuilder.Entity<UploadSettings>().ToTable("Users");
// Features
modelBuilder.Entity<Feature>().ToTable("Features");
// Blogs

1
Teknik/Filters/TrackPageView.cs

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Mvc.Filters; @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Teknik.Utilities.Routing;
namespace Teknik.Filters
{

1
Teknik/Middleware/CORSMiddleware.cs

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder; @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Teknik.Configuration;
using Teknik.Utilities;
using Teknik.Utilities.Routing;
namespace Teknik.Middleware
{

1
Teknik/Middleware/CSPMiddleware.cs

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder; @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Teknik.Configuration;
using Teknik.Utilities;
using Teknik.Utilities.Routing;
namespace Teknik.Middleware
{

21
Teknik/Middleware/ErrorHandlerMiddleware.cs

@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -25,15 +24,13 @@ namespace Teknik.Middleware @@ -25,15 +24,13 @@ namespace Teknik.Middleware
public class ErrorHandlerMiddleware
{
private readonly RequestDelegate _next;
private readonly IRouter _router;
public ErrorHandlerMiddleware(RequestDelegate next, IRouter router)
public ErrorHandlerMiddleware(RequestDelegate next)
{
_next = next;
_router = router;
}
public async Task Invoke(HttpContext httpContext, ILogger<Logger> logger, Config config, TeknikEntities dbContext)
public async Task Invoke(HttpContext httpContext, ILogger<Logger> logger, Config config, TeknikEntities dbContext, ErrorController errorController)
{
var statusCodeFeature = new StatusCodePagesFeature();
httpContext.Features.Set<IStatusCodePagesFeature>(statusCodeFeature);
@ -64,17 +61,13 @@ namespace Teknik.Middleware @@ -64,17 +61,13 @@ namespace Teknik.Middleware
// Detect if there is a response code or exception occured
if ((httpContext.Response.StatusCode >= 400 && httpContext.Response.StatusCode <= 600) || exception != null)
{
RouteData routeData = new RouteData();
routeData.DataTokens.Add("area", "Error");
routeData.Values.Add("controller", "Error");
routeData.Routers.Add(_router);
var routeData = httpContext.GetRouteData() ?? new RouteData();
var context = new ControllerContext();
context.HttpContext = httpContext;
context.RouteData = routeData;
context.ActionDescriptor = new Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor();
ErrorController errorController = new ErrorController(logger, config, dbContext);
errorController.ControllerContext = context;
if (httpContext.Response.StatusCode == 500 || exception != null)
@ -94,13 +87,7 @@ namespace Teknik.Middleware @@ -94,13 +87,7 @@ namespace Teknik.Middleware
{
public static IApplicationBuilder UseErrorHandler(this IApplicationBuilder builder, Config config)
{
var routes = new RouteBuilder(builder)
{
DefaultHandler = builder.ApplicationServices.GetRequiredService<MvcRouteHandler>(),
};
routes.BuildRoutes(config);
return builder.UseMiddleware<ErrorHandlerMiddleware>(routes.Build());
return builder.UseMiddleware<ErrorHandlerMiddleware>();
}
}
}

35
Teknik/Program.cs

@ -6,7 +6,9 @@ using System.Threading.Tasks; @@ -6,7 +6,9 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using Teknik.Configuration;
using Teknik.Logging;
@ -16,17 +18,32 @@ namespace Teknik @@ -16,17 +18,32 @@ namespace Teknik
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
AppContext.SetSwitch("Microsoft.AspNetCore.Routing.UseCorrectCatchAllBehavior",
true);
BuildWebHost(args).Build().Run();
}
public static IWebHost BuildWebHost(string[] args)
public static IHostBuilder BuildWebHost(string[] args)
{
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true)
.AddCommandLine(args)
.Build();
return Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(config =>
{
config.AddJsonFile("appsettings.json", optional: true);
config.AddCommandLine(args);
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.ConfigureLogging((hostingContext, logging) =>
{
string baseDir = hostingContext.HostingEnvironment.ContentRootPath;
string dataDir = Path.Combine(baseDir, "App_Data");
logging.AddProvider(new LoggerProvider(Config.Load(dataDir)));
logging.AddFilter<ConsoleLoggerProvider>("Microsoft.AspNetCore.Routing", LogLevel.Trace);
});
return WebHost.CreateDefaultBuilder(args)
/*
.UseConfiguration(config)
.UseIISIntegration()
.UseStartup<Startup>()
@ -35,8 +52,8 @@ namespace Teknik @@ -35,8 +52,8 @@ namespace Teknik
string baseDir = hostingContext.HostingEnvironment.ContentRootPath;
string dataDir = Path.Combine(baseDir, "App_Data");
logging.AddProvider(new LoggerProvider(Config.Load(dataDir)));
})
.Build();
});
*/
}
}
}

4
Teknik/Properties/PublishProfiles/Teknik - Development.pubxml

@ -8,10 +8,10 @@ by editing this MSBuild file. In order to learn more about this please visit htt @@ -8,10 +8,10 @@ by editing this MSBuild file. In order to learn more about this please visit htt
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>https://dev.teknik.io/</SiteUrlToLaunchAfterPublish>
<SiteUrlToLaunchAfterPublish>https://dev.teknik.io/Home</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>True</ExcludeApp_Data>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<ProjectGuid>1e52f0d0-9e89-4022-a905-c685ef3564e1</ProjectGuid>
<SelfContained>false</SelfContained>
<_IsPortable>true</_IsPortable>

4
Teknik/Properties/launchSettings.json

@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
"TeknikCore": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "?sub=www",
"launchUrl": "Home",
"environmentVariables": {
"ASPNETCORE_URLS": "https://localhost:8050",
"ASPNETCORE_ENVIRONMENT": "Development"
@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
"launchBrowser": true,
"launchUrl": "?sub=www",
"environmentVariables": {
"ASPNETCORE_URLS": "https://localhost:5050",
"ASPNETCORE_URLS": "https://localhost:8050",
"ASPNETCORE_ENVIRONMENT": "Production"
}
},

844
Teknik/Routes.cs

@ -1,844 +0,0 @@ @@ -1,844 +0,0 @@
using Microsoft.AspNetCore.Routing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Teknik.Configuration;
using Teknik.Utilities;
namespace Teknik
{
public static class Routes
{
public static void BuildRoutes(this IRouteBuilder routes, Config config)
{
routes.BuildDefaultRoutes(config);
routes.BuildAboutRoutes(config);
routes.BuildAbuseRoutes(config);
routes.BuildAdminRoutes(config);
routes.BuildAPIRoutes(config);
routes.BuildBlogRoutes(config);
routes.BuildContactRoutes(config);
routes.BuildDevRoutes(config);
routes.BuildErrorRoutes(config);
routes.BuildFAQRoutes(config);
routes.BuildHelpRoutes(config);
routes.BuildHomeRoutes(config);
routes.BuildPasteRoutes(config);
routes.BuildPodcastRoutes(config);
routes.BuildPrivacyRoutes(config);
routes.BuildRSSRoutes(config);
routes.BuildShortenerRoutes(config);
routes.BuildStatsRoutes(config);
routes.BuildTOSRoutes(config);
routes.BuildUploadRoutes(config);
routes.BuildUserRoutes(config);
routes.BuildVaultRoutes(config);
}
public static void BuildDefaultRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Default.Favicon",
domains: new List<string>() { config.Host, config.ShortenerConfig.ShortenerHost },
subDomains: new List<string>() { "*" },
template: "favicon.ico",
defaults: new { area = "Default", controller = "Default", action = "Favicon" }
);
routes.MapSubdomainRoute(
name: "Default.Logo",
domains: new List<string>() { config.Host, config.ShortenerConfig.ShortenerHost },
subDomains: new List<string>() { "*" },
template: "logo.svg",
defaults: new { area = "Default", controller = "Default", action = "Logo" }
);
routes.MapSubdomainRoute(
name: "Default.Robots",
domains: new List<string>() { config.Host, config.ShortenerConfig.ShortenerHost },
subDomains: new List<string>() { "*" },
template: "robots.txt",
defaults: new { area = "Default", controller = "Default", action = "Robots" }
);
routes.MapSubdomainRoute(
name: "Default.NotFound",
domains: new List<string>() { config.Host, config.ShortenerConfig.ShortenerHost },
subDomains: new List<string>() { "*" },
template: "{url}",
defaults: new { area = "Error", controller = "Error", action = "Http404" },
constraints: new { url = "{*url}" }
);
}
public static void BuildAboutRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "About.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "about" },
template: "",
defaults: new { area = "About", controller = "About", action = "Index" }
);
}
public static void BuildAbuseRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Abuse.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "abuse" },
template: "",
defaults: new { area = "Abuse", controller = "Abuse", action = "Index" }
);
}
public static void BuildAdminRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Admin.Dashboard",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "admin" },
template: "",
defaults: new { area = "Admin", controller = "Admin", action = "Dashboard" }
);
routes.MapSubdomainRoute(
name: "Admin.UserSearch",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "admin" },
template: "Search/Users",
defaults: new { area = "Admin", controller = "Admin", action = "UserSearch" }
);
routes.MapSubdomainRoute(
name: "Admin.UploadSearch",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "admin" },
template: "Search/Uploads",
defaults: new { area = "Admin", controller = "Admin", action = "UploadSearch" }
);
routes.MapSubdomainRoute(
name: "Admin.PasteSearch",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "admin" },
template: "Search/Pastes",
defaults: new { area = "Admin", controller = "Admin", action = "PasteSearch" }
);
routes.MapSubdomainRoute(
name: "Admin.ShortenedUrlSearch",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "admin" },
template: "Search/ShortenedUrls",
defaults: new { area = "Admin", controller = "Admin", action = "ShortenedUrlSearch" }
);
routes.MapSubdomainRoute(
name: "Admin.UserInfo",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "admin" },
template: "User/{username}",
defaults: new { area = "Admin", controller = "Admin", action = "UserInfo", username = string.Empty }
);
routes.MapSubdomainRoute(
name: "Admin.Action",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "admin" },
template: "Action/{action}",
defaults: new { area = "Admin", controller = "Admin", action = "Dashboard" }
);
}
public static void BuildAPIRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "API.v1.Claims",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "api" },
template: "v1/Claims",
defaults: new { area = "API", controller = "AccountAPIv1", action = "GetClaims" }
);
routes.MapSubdomainRoute(
name: "API.v1.Upload",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "api" },
template: "v1/Upload",
defaults: new { area = "API", controller = "UploadAPIv1", action = "Upload" }
);
routes.MapSubdomainRoute(
name: "API.v1.Paste",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "api" },
template: "v1/Paste",
defaults: new { area = "API", controller = "PasteAPIv1", action = "Paste" }
);
routes.MapSubdomainRoute(
name: "API.v1.Shorten",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "api" },
template: "v1/Shorten",
defaults: new { area = "API", controller = "ShortenAPIv1", action = "Shorten" }
);
routes.MapSubdomainRoute(
name: "API.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "api" },
template: "",
defaults: new { area = "API", controller = "API", action = "Index" }
);
}
public static void BuildBlogRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Blog.Blog",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "blog" },
template: "{username}",
defaults: new { area = "Blog", controller = "Blog", action = "Blog", username = string.Empty }
);
routes.MapSubdomainRoute(
name: "Blog.New",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "blog" },
template: "{username}/New",
defaults: new { area = "Blog", controller = "Blog", action = "NewPost", username = string.Empty }
);
routes.MapSubdomainRoute(
name: "Blog.Edit",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "blog" },
template: "{username}/Edit/{id}",
defaults: new { area = "Blog", controller = "Blog", action = "EditPost", username = string.Empty, id = -1 }
);
routes.MapSubdomainRoute(
name: "Blog.Post",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "blog" },
template: "{username}/p/{id}",
defaults: new { area = "Blog", controller = "Blog", action = "Post", username = string.Empty, id = -1 }
);
routes.MapSubdomainRoute(
name: "Blog.Action",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "blog" },
template: "Action/{action}",
defaults: new { area = "Blog", controller = "Blog", action = "Blog" }
);
}
public static void BuildContactRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Contact.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "contact" },
template: "",
defaults: new { area = "Contact", controller = "Contact", action = "Index" }
);
routes.MapSubdomainRoute(
name: "Contact.Action",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "contact" },
template: "Action/{action}",
defaults: new { area = "Contact", controller = "Contact", action = "Index" }
);
}
public static void BuildDevRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Dev.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "dev" },
template: "",
defaults: new { area = "Dev", controller = "Dev", action = "Index" }
);
}
public static void BuildErrorRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Error.HttpError",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "error" },
template: "{statusCode:int}",
defaults: new { area = "Error", controller = "Error", action = "HttpError", statusCode = 500 }
);
routes.MapSubdomainRoute(
name: "Error.Http401",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "error" },
template: "401",
defaults: new { area = "Error", controller = "Error", action = "Http401" }
);
routes.MapSubdomainRoute(
name: "Error.Http403",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "error" },
template: "403",
defaults: new { area = "Error", controller = "Error", action = "Http403" }
);
routes.MapSubdomainRoute(
name: "Error.Http404",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "error" },
template: "404",
defaults: new { area = "Error", controller = "Error", action = "Http404" }
);
routes.MapSubdomainRoute(
name: "Error.Http500",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "error" },
template: "500",
defaults: new { area = "Error", controller = "Error", action = "Http500" }
);
routes.MapSubdomainRoute(
name: "Error.Action",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "error" },
template: "Action/{action}",
defaults: new { area = "Error", controller = "Error", action = "HttpError" }
);
}
public static void BuildFAQRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "FAQ.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "faq" },
template: "",
defaults: new { area = "FAQ", controller = "FAQ", action = "Index" }
);
}
public static void BuildHelpRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Help.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "help" },
template: "",
defaults: new { area = "Help", controller = "Help", action = "Index" }
);
routes.MapSubdomainRoute(
name: "Help.API",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "help" },
template: "API/{version?}/{service?}",
defaults: new { area = "Help", controller = "Help", action = "API" }
);
routes.MapSubdomainRoute(
name: "Help.Blog",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "help" },
template: "Blog",
defaults: new { area = "Help", controller = "Help", action = "Blog" }
);
routes.MapSubdomainRoute(
name: "Help.Git",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "help" },
template: "Git",
defaults: new { area = "Help", controller = "Help", action = "Git" }
);
routes.MapSubdomainRoute(
name: "Help.IRC",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "help" },
template: "IRC",
defaults: new { area = "Help", controller = "Help", action = "IRC" }
);
routes.MapSubdomainRoute(
name: "Help.Mail",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "help" },
template: "Mail",
defaults: new { area = "Help", controller = "Help", action = "Mail" }
);
routes.MapSubdomainRoute(
name: "Help.Markdown",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "help" },
template: "Markdown",
defaults: new { area = "Help", controller = "Help", action = "Markdown" }
);
routes.MapSubdomainRoute(
name: "Help.Mumble",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "help" },
template: "Mumble",
defaults: new { area = "Help", controller = "Help", action = "Mumble" }
);
routes.MapSubdomainRoute(
name: "Help.RSS",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "help" },
template: "RSS",
defaults: new { area = "Help", controller = "Help", action = "RSS" }
);
routes.MapSubdomainRoute(
name: "Help.Tools",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "help" },
template: "Tools",
defaults: new { area = "Help", controller = "Help", action = "Tools" }
);
routes.MapSubdomainRoute(
name: "Help.Upload",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "help" },
template: "Upload",
defaults: new { area = "Help", controller = "Help", action = "Upload" }
);
}
public static void BuildHomeRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Home.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "www", string.Empty },
template: "",
defaults: new { area = "Home", controller = "Home", action = "Index" }
);
}
public static void BuildPasteRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Paste.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" },
template: "",
defaults: new { area = "Paste", controller = "Paste", action = "Index" }
);
routes.MapSubdomainRoute(
name: "Paste.Simple",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" },
template: "Simple/{url}/{password?}",
defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Simple" }
);
routes.MapSubdomainRoute(
name: "Paste.Raw",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" },
template: "Raw/{url}/{password?}",
defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Raw" }
);
routes.MapSubdomainRoute(
name: "Paste.Download",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" },
template: "Download/{url}/{password?}",
defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Download" }
);
routes.MapSubdomainRoute(
name: "Paste.Edit",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" },
template: "Edit/{url}/{password?}",
defaults: new { area = "Paste", controller = "Paste", action = "Edit" }
);
routes.MapSubdomainRoute(
name: "Paste.Delete",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" },
template: "Delete",
defaults: new { area = "Paste", controller = "Paste", action = "Delete" }
);
routes.MapSubdomainRoute(
name: "Paste.Action",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" },
template: "Action/{action}",
defaults: new { area = "Paste", controller = "Paste", action = "Index" }
);
routes.MapSubdomainRoute(
name: "Paste.View",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" },
template: "{url}/{password?}",
defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Full" }
);
}
public static void BuildPodcastRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Podcast.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "podcast" },
template: "",
defaults: new { area = "Podcast", controller = "Podcast", action = "Index" }
);
routes.MapSubdomainRoute(
name: "Podcast.View",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "podcast" },
template: "ep/{episode}",
defaults: new { area = "Podcast", controller = "Podcast", action = "View" }
);
routes.MapSubdomainRoute(
name: "Podcast.Download",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "podcast" },
template: "File/{episode}/{fileName}",
defaults: new { area = "Podcast", controller = "Podcast", action = "Download" }
);
routes.MapSubdomainRoute(
name: "Podcast.Action",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "podcast" },
template: "Action/{action}",
defaults: new { area = "Podcast", controller = "Podcast", action = "Index" }
);
}
public static void BuildPrivacyRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Privacy.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "privacy" },
template: "",
defaults: new { area = "Privacy", controller = "Privacy", action = "Index" }
);
}
public static void BuildRSSRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "RSS.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "rss" },
template: "",
defaults: new { area = "RSS", controller = "RSS", action = "Index" }
);
routes.MapSubdomainRoute(
name: "RSS.Blog",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "rss" },
template: "Blog/{username?}",
defaults: new { area = "RSS", controller = "RSS", action = "Blog" }
);
routes.MapSubdomainRoute(
name: "RSS.Podcast",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "rss" },
template: "Podcast",
defaults: new { area = "RSS", controller = "RSS", action = "Podcast" }
);
}
public static void BuildShortenerRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Shortener.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "shorten", "s" },
template: "",
defaults: new { area = "Shortener", controller = "Shortener", action = "Index" }
);
routes.MapSubdomainRoute(
name: "Shortener.Delete",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "shorten", "s" },
template: "Delete",
defaults: new { area = "Shortener", controller = "Shortener", action = "Delete" }
);
routes.MapSubdomainRoute(
name: "Shortener.Action",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "shorten", "s" },
template: "Action/{action}",
defaults: new { area = "Shortener", controller = "Shortener", action = "Index" }
);
routes.MapSubdomainRoute(
name: "Shortener.View",
domains: new List<string>() { config.ShortenerConfig.ShortenerHost, config.Host },
subDomains: new List<string>() { string.Empty, "shortened" },
template: "{url}",
defaults: new { area = "Shortener", controller = "Shortener", action = "RedirectToUrl" }
);
routes.MapSubdomainRoute(
name: "Shortener.Verify",
domains: new List<string>() { config.ShortenerConfig.ShortenerHost },
subDomains: new List<string>() { string.Empty },
template: "",
defaults: new { area = "Shortener", controller = "Shortener", action = "Verify" }
);
}
public static void BuildStatsRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "Stats.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "stats" },
template: "",
defaults: new { area = "Stats", controller = "Stats", action = "Index" }
);
routes.MapSubdomainRoute(
name: "Stats.Action",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "stats" },
template: "Action/{action}",
defaults: new { area = "Stats", controller = "Stats", action = "Index" }
);
}
public static void BuildTOSRoutes(this IRouteBuilder routes, Config config)
{
routes.MapSubdomainRoute(
name: "TOS.Index",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "tos" },