Skip to content

Commit b320b22

Browse files
authored
Merge pull request #115 from androidseb25/dev
Release 1.3.1.0
2 parents 5776eb8 + f799ea0 commit b320b22

File tree

11 files changed

+109
-39
lines changed

11 files changed

+109
-39
lines changed

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ jobs:
118118
name: Build dotNet
119119
strategy:
120120
matrix:
121-
dotnet-version: [ '8.x' ]
121+
dotnet-version: [ '9.x' ]
122122
kind: [ 'amd64', 'arm64', 'armv7' ]
123123
include:
124124
- kind: amd64

Controller/DeviceController.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using iGotify_Notification_Assist.Services;
33
using Microsoft.AspNetCore.Mvc;
44
using SecNtfyNuGet;
5+
using Environments = iGotify_Notification_Assist.Services.Environments;
56

67
namespace iGotify_Notification_Assist.Controller;
78

@@ -91,10 +92,11 @@ public async Task<IActionResult> DeleteDevcice(string token)
9192
[HttpGet("Test/{deviceToken}")]
9293
public async Task<IActionResult> Test(string deviceToken)
9394
{
94-
var ntfy = new SecNtfy(Environment.GetEnvironmentVariable("SECNTFY_SERVER_URL") ?? "https://api.secntfy.app");
95+
var ntfy = new SecNtfy(Environments.secNtfyUrl);
9596
if (deviceToken.Length > 0)
9697
_ = await ntfy.SendNotification(deviceToken, "Test", "Test Nachricht");
97-
Console.WriteLine(ntfy.encTitle);
98+
if (Environments.isLogEnabled)
99+
Console.WriteLine(ntfy.encTitle);
98100

99101
return Ok();
100102
}

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# See https://devblogs.microsoft.com/dotnet/improving-multiplatform-container-support/
2-
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
2+
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
33
WORKDIR /app
44
EXPOSE 5047
55
EXPOSE 7221
66

7-
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
7+
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0 AS build
88
ARG TARGETARCH
99
WORKDIR /src
1010

Models/DeviceModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using iGotify_Notification_Assist.Services;
22
using SecNtfyNuGet;
33
using Websocket.Client;
4+
using Environments = iGotify_Notification_Assist.Services.Environments;
45

56
namespace iGotify_Notification_Assist.Models;
67

@@ -52,7 +53,7 @@ public async Task SendNotifications(GotifyMessage iGotifyMessage, WebsocketClien
5253
Console.WriteLine("THERE'S SOMETHING WRONG HERE? NO USER FOUND");
5354
}
5455

55-
var ntfy = new SecNtfy(Environment.GetEnvironmentVariable("SECNTFY_SERVER_URL") ?? "https://api.secntfy.app");
56+
var ntfy = new SecNtfy(Environments.secNtfyUrl);
5657
_ = ntfy.SendNotification(usr.DeviceToken, title, msg, iGotifyMessage.priority == 10, imageUrl, iGotifyMessage.priority);
5758
}
5859
}

Program.cs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
using iGotify_Notification_Assist.Services;
2+
using Microsoft.AspNetCore.Http.Json;
3+
using Microsoft.AspNetCore.Identity;
24
using Microsoft.OpenApi.Models;
5+
using Scalar.AspNetCore;
6+
using Environments = iGotify_Notification_Assist.Services.Environments;
37

48
var builder = WebApplication.CreateBuilder(args);
59

610
// Add services to the container.
711
builder.Services.AddCors();
812

9-
builder.Services.AddControllers(opt => { opt.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true; })
13+
builder.Services.AddControllers(opt =>
14+
{
15+
opt.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true;
16+
})
1017
.AddJsonOptions(opt =>
1118
{
1219
opt.JsonSerializerOptions.PropertyNamingPolicy = null;
1320
opt.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
1421
});
15-
16-
builder.Services.AddSingleton(builder.Configuration);
17-
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
18-
builder.Services.AddEndpointsApiExplorer();
19-
builder.Services.AddSwaggerGen(c =>
22+
builder.Services.Configure<JsonOptions>(options =>
2023
{
21-
c.SwaggerDoc("v1", new OpenApiInfo { Title = "iGotify Notification Assist API", Version = "v1" });
24+
options.SerializerOptions.PropertyNameCaseInsensitive = true; // Enable case-insensitivity
25+
options.SerializerOptions.PropertyNamingPolicy = null; // Preserve exact casing
2226
});
2327

28+
builder.Services.AddSingleton(builder.Configuration);
29+
builder.Services.AddOpenApi();
2430
builder.Services.AddTransient<IStartupFilter, StartUpBuilder>();
2531

2632
var app = builder.Build();
@@ -37,17 +43,18 @@
3743

3844
app.UseRouting();
3945

40-
// Enable middleware to serve generated Swagger as a JSON endpoint.
41-
app.UseSwagger(c => { c.RouteTemplate = "/swagger/{documentName}/swagger.json"; });
42-
43-
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
44-
// specifying the Swagger JSON endpoint.
45-
app.UseSwaggerUI(c =>
46+
if (Environments.enableScalarUi)
4647
{
47-
c.SwaggerEndpoint("/api/swagger/v1/swagger.json", "iGotify Notification Assist API");
48-
c.RoutePrefix = string.Empty;
49-
c.DefaultModelsExpandDepth(-1);
50-
});
48+
app.MapOpenApi();
49+
app.MapScalarApiReference(options =>
50+
{
51+
options.WithTitle("iGotify Notification Assist API")
52+
.WithModels(false)
53+
.WithLayout(ScalarLayout.Classic)
54+
.WithTheme(ScalarTheme.Moon)
55+
.WithDefaultHttpClient(ScalarTarget.CSharp, ScalarClient.HttpClient);
56+
});
57+
}
5158

5259
//app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
5360

Properties/launchSettings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"commandName": "Project",
1414
"dotnetRunMessages": true,
1515
"launchBrowser": true,
16-
"launchUrl": "api/",
16+
"launchUrl": "scalar/v1",
1717
"applicationUrl": "http://localhost:5047",
1818
"environmentVariables": {
1919
"ASPNETCORE_ENVIRONMENT": "Development"
@@ -23,7 +23,7 @@
2323
"commandName": "Project",
2424
"dotnetRunMessages": true,
2525
"launchBrowser": true,
26-
"launchUrl": "api/",
26+
"launchUrl": "scalar/v1",
2727
"applicationUrl": "https://localhost:7221;http://localhost:5047",
2828
"environmentVariables": {
2929
"ASPNETCORE_ENVIRONMENT": "Development"
@@ -32,7 +32,7 @@
3232
"IIS Express": {
3333
"commandName": "IISExpress",
3434
"launchBrowser": true,
35-
"launchUrl": "api/",
35+
"launchUrl": "scalar/v1",
3636
"environmentVariables": {
3737
"ASPNETCORE_ENVIRONMENT": "Development"
3838
}

Services/GotifySocketService.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ private static void StartWsConn(string gotifyServerUrl, string clientToken)
7171
if (_websocketThreads == null)
7272
_websocketThreads = new Dictionary<string, WebSockClient>();
7373

74-
_websocketThreads.Add(clientToken, wsc);
74+
_websocketThreads.TryGetValue(clientToken, out var storedWebSockClient);
75+
if (storedWebSockClient == null)
76+
_websocketThreads.Add(clientToken, wsc);
77+
else
78+
Console.WriteLine($"Client: {clientToken} already connected! Skipping...");
7579

7680
Thread.Sleep(Timeout.Infinite);
7781
}
@@ -89,13 +93,13 @@ private static void StartWsConn(string gotifyServerUrl, string clientToken)
8993
/// </summary>
9094
public async void Start()
9195
{
92-
var secntfyUrl = Environment.GetEnvironmentVariable("SECNTFY_SERVER_URL") ?? "https://api.secntfy.app";
96+
var secntfyUrl = Environments.secNtfyUrl;
9397

9498
// [FEATURE REQUEST] #59 - https://github.com/androidseb25/iGotify-Notification-Assistent/issues/59
9599
// First try of implementing local running instances without app configuration
96-
var gotifyUrls = Environment.GetEnvironmentVariable("GOTIFY_URLS") ?? "";
97-
var gotifyClientTokens = Environment.GetEnvironmentVariable("GOTIFY_CLIENT_TOKENS") ?? "";
98-
var secntfyTokens = Environment.GetEnvironmentVariable("SECNTFY_TOKENS") ?? "";
100+
var gotifyUrls = Environments.gotifyUrls;
101+
var gotifyClientTokens = Environments.gotifyClientTokens;
102+
var secntfyTokens = Environments.secNtfyTokens;
99103

100104
var gotifyUrlList = new List<string>();
101105
var gotifyClientList = new List<string>();

Services/Tool.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,56 @@ public static string UsersDb(string databaseFilePath)
1515
{
1616
return $"Data Source={databaseFilePath}";
1717
}
18+
}
19+
20+
21+
public class Environments
22+
{
23+
public static bool isLogEnabled
24+
{
25+
get
26+
{
27+
return Environment.GetEnvironmentVariable("ENABLE_CONSOLE_LOG") == "true";
28+
}
29+
}
30+
public static bool enableScalarUi
31+
{
32+
get
33+
{
34+
return Environment.GetEnvironmentVariable("ENABLE_SCALAR_UI") == "true";
35+
}
36+
}
37+
38+
public static string gotifyUrls
39+
{
40+
get
41+
{
42+
return Environment.GetEnvironmentVariable("GOTIFY_URLS") ?? "";
43+
}
44+
}
45+
46+
public static string gotifyClientTokens
47+
{
48+
get
49+
{
50+
return Environment.GetEnvironmentVariable("GOTIFY_CLIENT_TOKENS") ?? "";
51+
}
52+
}
53+
54+
public static string secNtfyTokens
55+
{
56+
get
57+
{
58+
return Environment.GetEnvironmentVariable("SECNTFY_TOKENS") ?? "";
59+
}
60+
}
61+
62+
public static string secNtfyUrl
63+
{
64+
get
65+
{
66+
return Environment.GetEnvironmentVariable("SECNTFY_SERVER_URL") ?? "https://api.secntfy.app";
67+
}
68+
}
69+
1870
}

Services/WebSockClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public void Start(string clientToken, bool isRestart = false)
6565
var message = msg.ToString().Replace("client::display", "clientdisplay")
6666
.Replace("client::notification", "clientnotification")
6767
.Replace("android::action", "androidaction");
68-
Console.WriteLine("Message converted: " + message);
68+
if (Environments.isLogEnabled)
69+
Console.WriteLine("Message converted: " + message);
6970
// var jsonData = JsonConvert.SerializeObject(message);
7071
var gm = JsonConvert.DeserializeObject<GotifyMessage>(message);
7172
// If object is null return and listen to the next message

iGotify Notification Assist.csproj

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<InvariantGlobalization>true</InvariantGlobalization>
88
<RootNamespace>iGotify_Notification_Assist</RootNamespace>
9-
<AssemblyVersion>1.3.0.0</AssemblyVersion>
10-
<FileVersion>1.3.0.0</FileVersion>
11-
<Version>1.3.0.0</Version>
9+
<AssemblyVersion>1.3.1.0</AssemblyVersion>
10+
<FileVersion>1.3.1.0</FileVersion>
11+
<Version>1.3.1.0</Version>
12+
<LangVersion>default</LangVersion>
1213
</PropertyGroup>
1314

1415
<ItemGroup>
1516
<PackageReference Include="Dapper" Version="2.1.44" />
1617
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
1718
<PackageReference Include="Dapper.Mapper" Version="2.0.0" />
18-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6" />
19-
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.6" />
19+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
20+
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.0" />
2021
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
22+
<PackageReference Include="Scalar.AspNetCore" Version="1.2.75" />
2123
<PackageReference Include="secntfy.nuget" Version="1.0.5" />
22-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
2324
<PackageReference Include="Websocket.Client" Version="5.1.2" />
2425
</ItemGroup>
2526

0 commit comments

Comments
 (0)