mirror of
https://github.com/yawaflua/yaflay.ru.git
synced 2025-12-08 19:49:36 +02:00
add args parser
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
#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.
|
||||
ARG CLIENTID
|
||||
ARG CLIENTSECRET
|
||||
ARG REDIRECTURL
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
|
||||
WORKDIR /app
|
||||
@@ -11,10 +14,10 @@ COPY ["yaflay.ru.csproj", "."]
|
||||
RUN dotnet restore "./yaflay.ru.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/."
|
||||
RUN dotnet build "yaflay.ru.csproj" -c Release -o /app/build
|
||||
RUN dotnet build "yaflay.ru.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "yaflay.ru.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
RUN dotnet publish "yaflay.ru.csproj" -c Release -o /app/publish /p:UseAppHost=false;redirectUrl=$REDIRECTURL;clientId=$CLIENTID;clientSecret=$CLIENTSECRET
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
new HttpRequestMessage(HttpMethod.Post, "https://discordapp.com/api/oauth2/token"))
|
||||
{
|
||||
requestMessage.Content = new StringContent(
|
||||
@$"grant_type=authorization_code&code={Model.code}&client_id={Startup.clientId}&client_secret={Startup.clientSecret}&scope=identify&redirect_uri=https://yawaflua.ru/authorize",
|
||||
@$"grant_type=authorization_code&code={Model.code}&client_id={Startup.clientId}&client_secret={Startup.clientSecret}&scope=identify&redirect_uri={Startup.redirectUrl}",
|
||||
new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded")
|
||||
);
|
||||
message = await Startup.client.SendAsync(requestMessage);
|
||||
|
||||
11
Program.cs
11
Program.cs
@@ -2,9 +2,18 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using yaflay.ru;
|
||||
public class Program
|
||||
{
|
||||
public static void Main() => CreateHostBuilder()
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var parsedArgs = args.FirstOrDefault(k => k.StartsWith("/p:")).Replace("/p:", "").Split(";");
|
||||
var parse = (string name) => parsedArgs.FirstOrDefault(k => k.StartsWith(name))?.Split("=")[1] ?? null;
|
||||
Startup.clientId = parse("clientId");
|
||||
Startup.clientSecret = parse("clientSecret");
|
||||
Startup.redirectUrl = parse("redirectUrl");
|
||||
|
||||
CreateHostBuilder()
|
||||
.Build()
|
||||
.Run();
|
||||
}
|
||||
private static IHostBuilder CreateHostBuilder()
|
||||
{
|
||||
return Host.CreateDefaultBuilder()
|
||||
|
||||
22
Startup.cs
22
Startup.cs
@@ -17,24 +17,22 @@ namespace yaflay.ru
|
||||
public static HttpClientHandler handler = new() { CookieContainer = cookieContainer};
|
||||
public static HttpClient client = new(handler);
|
||||
public static AppDbContext? dbContext;
|
||||
public static string applicationId;
|
||||
public static string appToken;
|
||||
public static string clientId;
|
||||
public static string clientSecret;
|
||||
public static string redirectUrl;
|
||||
public static string? clientId = null;
|
||||
public static string? clientSecret = null;
|
||||
public static string? redirectUrl = null;
|
||||
public Startup()
|
||||
{
|
||||
configuration = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables(prefix: "m.")
|
||||
.AddJsonFile("appsettings.json", optional: false)
|
||||
.AddJsonFile("appsettings.json", optional: true)
|
||||
.Build();
|
||||
if (clientId == null | clientSecret == null | redirectUrl == null)
|
||||
{
|
||||
clientId = configuration.GetValue<string>("clientId");
|
||||
clientSecret = configuration.GetValue<string>("clientSecret");
|
||||
redirectUrl = configuration.GetValue<string>("redirectUrl");
|
||||
}
|
||||
|
||||
Console.WriteLine(configuration.GetValue<string>("applicationId"));
|
||||
applicationId = configuration.GetValue<string>("applicationId");
|
||||
appToken = configuration.GetValue<string>("appToken");
|
||||
clientId = configuration.GetValue<string>("clientId");
|
||||
clientSecret = configuration.GetValue<string>("clientSecret");
|
||||
redirectUrl = configuration.GetValue<string>("redirectUrl");
|
||||
}
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
|
||||
@@ -5,5 +5,8 @@
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
},
|
||||
"clientId": "111111111111",
|
||||
"clientSecret": "aAbBcCdD",
|
||||
"redirectUrl": "https://example.com/authorize"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user