diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/Controllers/OembedController.cs b/Controllers/OembedController.cs new file mode 100644 index 0000000..a689536 --- /dev/null +++ b/Controllers/OembedController.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Mvc; +using System.Xml.Linq; + +namespace OembedTests.Controllers +{ + [Route("/oembed")] + [ApiController] + public class OembedController : ControllerBase + { + [HttpGet] + public async Task GetOembed([FromQuery]string url, [FromQuery] string? format = "json") + { + var userName = url.Replace("https://oembed-test.yawaflua.ru/pay/", ""); + var response = $@"{{ + ""version"": ""1.0"", + ""type"": ""link"", + ""provider_name"": ""SP-Donate"", + ""provider_url"": ""https://sp-donate.ru/"", + ""title"": ""Donate to {userName} right now!"", + ""thumbnail_url"": ""https://avatar.spworlds.ru/front/240/{userName}"" + }}"; + return Ok(response); + } + } +} diff --git a/Controllers/WeatherForecastController.cs b/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..64fb5cd --- /dev/null +++ b/Controllers/WeatherForecastController.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Mvc; + +namespace OembedTests.Controllers +{ + [ApiController] + [Route("pay")] + public class WeatherForecastController : ControllerBase + { + + [HttpGet("/{userName}")] + public async Task Get(string userName) + { + return Ok(userName); + } + } +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9daaaf2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER app +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["OembedTests.csproj", "."] +RUN dotnet restore "./OembedTests.csproj" +COPY . . +WORKDIR "/src/." +RUN dotnet build "./OembedTests.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./OembedTests.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "OembedTests.dll"] \ No newline at end of file diff --git a/OembedTests.csproj b/OembedTests.csproj new file mode 100644 index 0000000..6f38e7b --- /dev/null +++ b/OembedTests.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + 5a8aa1d4-191d-41df-a985-bd3376a38224 + Linux + . + + + + + + + + diff --git a/OembedTests.http b/OembedTests.http new file mode 100644 index 0000000..c6e9e36 --- /dev/null +++ b/OembedTests.http @@ -0,0 +1,6 @@ +@OembedTests_HostAddress = http://localhost:5052 + +GET {{OembedTests_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/OembedTests.sln b/OembedTests.sln new file mode 100644 index 0000000..90f3c10 --- /dev/null +++ b/OembedTests.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OembedTests", "OembedTests.csproj", "{4E788BB3-1E69-4EA5-A4C3-BF89F97CACED}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4E788BB3-1E69-4EA5-A4C3-BF89F97CACED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4E788BB3-1E69-4EA5-A4C3-BF89F97CACED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4E788BB3-1E69-4EA5-A4C3-BF89F97CACED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4E788BB3-1E69-4EA5-A4C3-BF89F97CACED}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F81C49C6-5456-40F1-997C-812D773364B6} + EndGlobalSection +EndGlobal diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..cfe627a --- /dev/null +++ b/Program.cs @@ -0,0 +1,36 @@ + +namespace OembedTests +{ + public class Program + { + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + + builder.Services.AddControllers(); + // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen(); + + var app = builder.Build(); + + // Configure the HTTP request pipeline. + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(); + } + + app.UseHttpsRedirection(); + + app.UseAuthorization(); + + + app.MapControllers(); + + app.Run(); + } + } +} diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..402742d --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,52 @@ +{ + "profiles": { + "http": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5052" + }, + "https": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7250;http://localhost:5052" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_HTTPS_PORTS": "8081", + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": true + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:26517", + "sslPort": 44326 + } + } +} \ No newline at end of file diff --git a/WeatherForecast.cs b/WeatherForecast.cs new file mode 100644 index 0000000..84aa3b1 --- /dev/null +++ b/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace OembedTests +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}