Compare commits

..

No commits in common. "c3342984ea2baf07692fad6aa2a3e4791fccb1dc" and "abc66511d882443b752dee7cbd05d928dfbce23e" have entirely different histories.

6 changed files with 15 additions and 42 deletions

View File

@ -80,11 +80,11 @@ public class RequestHandler
private Dictionary<string, string> GetRequestVariables(string query)
{
Dictionary<string, string> ret = new();
Regex queryRex = new (@"\?{1}&?([A-z]+=[A-z]+)+(&[A-z]+=[A-z]+)*");
Regex queryRex = new (@"\?{1}([A-z]+=[A-z]+)+(&[A-z]+=[A-z]+)*");
if (!queryRex.IsMatch(query))
return ret;
query = query.Substring(1);
foreach(string kvpair in query.Split('&').Where(str => str.Length>=3 ))
foreach(string kvpair in query.Split('&'))
ret.Add(kvpair.Split('=')[0], kvpair.Split('=')[1]);
return ret;
}

View File

@ -67,6 +67,8 @@ public class Server
internal void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
{
if (!response.OutputStream.CanWrite)
return;
//logger?.WriteLine(this.GetType().ToString(), $"Sending response: {statusCode}");
response.StatusCode = (int)statusCode;
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
@ -74,16 +76,9 @@ public class Server
response.AddHeader("Access-Control-Max-Age", "1728000");
response.AppendHeader("Access-Control-Allow-Origin", "*");
response.ContentType = "application/json";
try
{
response.OutputStream.Write(content is not null
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
: Array.Empty<byte>());
}
catch (HttpListenerException)
{
}
response.OutputStream.Write(content is not null
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
: Array.Empty<byte>());
response.OutputStream.Close();
}

View File

@ -6,18 +6,18 @@ namespace Tranga.NotificationManagers;
public class LunaSea : NotificationManager
{
public string id { get; }
public string webhook { get; }
private readonly HttpClient _client = new();
public LunaSea(string id, Logger? logger = null) : base(NotificationManagerType.LunaSea, logger)
public LunaSea(string webhook, Logger? logger = null) : base(NotificationManagerType.LunaSea, logger)
{
this.id = id;
this.webhook = webhook;
}
public override void SendNotification(string title, string notificationText)
{
logger?.WriteLine(this.GetType().ToString(), $"Sending notification: {title} - {notificationText}");
MessageData message = new(title, notificationText);
HttpRequestMessage request = new(HttpMethod.Post, $"https://notify.lunasea.app/v1/custom/{id}");
HttpRequestMessage request = new(HttpMethod.Post, webhook);
request.Content = new StringContent(JsonConvert.SerializeObject(message, Formatting.None), Encoding.UTF8, "application/json");
HttpResponseMessage response = _client.Send(request);
if (!response.IsSuccessStatusCode)

View File

@ -363,7 +363,9 @@ public class TaskManager
private void ExportDataAndSettings()
{
logger?.WriteLine(this.GetType().ToString(), $"Exporting settings to {settings.settingsFilePath}");
settings.ExportSettings();
while(IsFileInUse(settings.settingsFilePath))
Thread.Sleep(50);
File.WriteAllText(settings.settingsFilePath, JsonConvert.SerializeObject(settings));
logger?.WriteLine(this.GetType().ToString(), $"Exporting tasks to {settings.tasksFilePath}");
while(IsFileInUse(settings.tasksFilePath))

View File

@ -43,29 +43,6 @@ public class TrangaSettings
return settings;
}
public void ExportSettings()
{
if (File.Exists(settingsFilePath))
{
bool inUse = true;
while (inUse)
{
try
{
using FileStream stream = new (settingsFilePath, FileMode.Open, FileAccess.Read, FileShare.None);
stream.Close();
inUse = false;
}
catch (IOException)
{
inUse = true;
Thread.Sleep(50);
}
}
}
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(this));
}
public void UpdateSettings(UpdateField field, Logger? logger = null, params string[] values)
{
switch (field)
@ -104,7 +81,6 @@ public class TrangaSettings
newLunaSea.SendNotification("Success!", "LunaSea was added to Tranga!");
break;
}
ExportSettings();
}
public enum UpdateField { DownloadLocation, Komga, Kavita, Gotify, LunaSea}

View File

@ -142,7 +142,7 @@
<div>
<span class="title">LunaSea</span>
<div>Configured: <span id="lunaseaConfigured">✅❌</span></div>
<label for="lunaseaWebhook"></label><input placeholder="device/:id or user/:id" id="lunaseaWebhook" type="text">
<label for="lunaseaWebhook"></label><input placeholder="Webhook-Url" id="lunaseaWebhook" type="text">
</div>
<div>
<label for="libraryUpdateTime" style="margin-right: 5px;">Update Time</label><input id="libraryUpdateTime" type="time" value="00:01:00" step="10">