Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"cwd": "${workspaceFolder}/SnakeAid.Api",
"stopAtEntry": false,
"serverReadyAction": {
"pattern": "\\bNow listening on:\\s+(https?://\\S+)",
"pattern": "Now listening on:\\s+(https?://[^\\s]+)",
"uriFormat": "%s",
"action": "openExternally"
},
Expand All @@ -33,7 +33,7 @@
"cwd": "${workspaceFolder}/SnakeAid.Api",
"stopAtEntry": false,
"serverReadyAction": {
"pattern": "\\bNow listening on:\\s+(https://.*:7026)",
"pattern": "Now listening on:\\s+(https://[^\\s]+:7026)",
"uriFormat": "%s",
"action": "openExternally"
},
Expand All @@ -58,7 +58,7 @@
"cwd": "${workspaceFolder}/SnakeAid.Api",
"stopAtEntry": false,
"serverReadyAction": {
"pattern": "\\bNow listening on:\\s+(http://.*:5009)",
"pattern": "Now listening on:\\s+(http://[^\\s]+:5009)",
"uriFormat": "%s",
"action": "openExternally"
},
Expand All @@ -83,7 +83,7 @@
"cwd": "${workspaceFolder}/SnakeAid.Api",
"stopAtEntry": false,
"serverReadyAction": {
"pattern": "\\bNow listening on:\\s+(https://.*:7026)",
"pattern": "Now listening on:\\s+(https://[^\\s]+:7026)",
"uriFormat": "%s",
"action": "openExternally"
},
Expand Down
40 changes: 39 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
{
"dotnet.defaultSolution": "SnakeAid.Api/SnakeAid.Api.sln"
"dotnet.defaultSolution": "SnakeAid.Backend.sln",
"files.exclude": {
"**/bin": false,
"**/obj": false,
"**/Properties": false,
".vscode": false,
"**/node_modules": false,
"**/packages": false,
"**/.vs": false,
"**/dist": false,
"**/coverage": false,
"**/artifacts": false,
"**/logs": false,
"**/*.dll": false,
"**/*.pdb": false,
"**/*.exe": false,
"**/*.nupkg": false,
"**/*.zip": false,
"**/*.tar.gz": false,
"**/*.so": false,
"**/*.dylib": false,
"**/*.pyc": false,
"**/*.db": false,
"**/*.sqlite": false
},
"search.exclude": {
"**/bin": true,
"**/obj": true,
"**/node_modules": true,
"**/.vs": true,
"**/dist": true
},
"files.watcherExclude": {
"**/bin/**": true,
"**/obj/**": true,
"**/.git/**": true,
"**/node_modules/**": true,
"**/.vs/**": true
}
}
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Doppler.Extensions.Configuration" Version="1.0.1" />
<PackageVersion Include="FirebaseAdmin" Version="3.4.0" />
<PackageVersion Include="Mapster" Version="7.4.0" />
<PackageVersion Include="Mapster.DependencyInjection" Version="1.0.1" />
Expand Down
44 changes: 44 additions & 0 deletions SnakeAid.Api/DI/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,54 @@
using System.Security.Claims;
using System.Text;

using Serilog;
using Doppler.Extensions.Configuration; // Ensure this is available

namespace SnakeAid.Api.DI;

public static class DependencyInjection
{
#region service he thong

#region Doppler
public static WebApplicationBuilder AddConfigurationFromDopplerCloud(this WebApplicationBuilder builder)
{
// 1. Load Doppler Token (Process -> User)
var token = Environment.GetEnvironmentVariable("DOPPLER_TOKEN");

if (string.IsNullOrEmpty(token))
{
token = Environment.GetEnvironmentVariable("DOPPLER_TOKEN", EnvironmentVariableTarget.User);
if (!string.IsNullOrEmpty(token))
{
// Propagate User token and other User env vars to Process
Environment.SetEnvironmentVariable("DOPPLER_TOKEN", token, EnvironmentVariableTarget.Process);
foreach (System.Collections.DictionaryEntry userEnvVar in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User))
{
if (userEnvVar.Key is string key && userEnvVar.Value is string value && key != "DOPPLER_TOKEN")
{
Environment.SetEnvironmentVariable(key, value, EnvironmentVariableTarget.Process);
}
}
}
}

// 2. Register and Log results
if (!string.IsNullOrEmpty(token))
{
builder.Configuration.AddDoppler(token);
Serilog.Log.Information("🚀 Configuration: Doppler Cloud (ENABLED)");
}
else
{
Serilog.Log.Information("ℹ️ Configuration: Local Settings (AppSettings.json & Env Vars)");
}

return builder;
}
#endregion

#region Services
public static IServiceCollection AddServices(this IServiceCollection services, IConfiguration configuration)
{
var cloudinarySection = configuration.GetSection("Cloudinary");
Expand Down Expand Up @@ -77,6 +119,8 @@ private static IAsyncPolicy<HttpResponseMessage> GetCircuitBreakerPolicy()

#endregion

#endregion

#region authen vs author

public static IServiceCollection AddAuthenticateAuthor(this IServiceCollection services,
Expand Down
5 changes: 4 additions & 1 deletion SnakeAid.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using SQLitePCL;
using Swashbuckle.AspNetCore.SwaggerUI;
using System.Text.Json.Serialization;
using Doppler.Extensions.Configuration;

namespace SnakeAid.Api
{
Expand All @@ -33,6 +34,8 @@ public static async Task Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

builder.AddConfigurationFromDopplerCloud();

Batteries_V2.Init();

var sqliteLogPath = Path.Combine(builder.Environment.ContentRootPath, "logs", "logs.db");
Expand Down Expand Up @@ -149,7 +152,7 @@ public static async Task Main(string[] args)
});

builder.Services.AddControllers();

// Add Razor Pages for lightweight UI admin pages
builder.Services.AddRazorPages();

Expand Down
8 changes: 3 additions & 5 deletions SnakeAid.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5009",
"launchUrl": "",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand All @@ -23,16 +22,15 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7026;http://localhost:5009",
"launchUrl": "",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"launchUrl": "",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
1 change: 1 addition & 0 deletions SnakeAid.Api/SnakeAid.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<PackageReference Include="Carter" />
<PackageReference Include="Doppler.Extensions.Configuration" />
<PackageReference Include="FirebaseAdmin" />
<PackageReference Include="Microsoft.AspNetCore.SignalR"/>
<PackageReference Include="Serilog.AspNetCore" />
Expand Down
8 changes: 8 additions & 0 deletions SnakeAid.Core/Exceptions/ApiException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ public TooManyRequestsException(string reason, DateTime? retryAfter, int? limit
Period = period;
Endpoint = endpoint;
}
}

public class ConfigurationException : ApiException
{
public ConfigurationException(string reason)
: base(reason, HttpStatusCode.InternalServerError)
{
}
}
3 changes: 2 additions & 1 deletion SnakeAid.Core/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ public class SnakeAISettings
public bool SaveImage { get; set; } = false;
public float Confidence { get; set; } = 0.25f;
public int TimeoutSeconds { get; set; } = 30;
}
}