2
0

Implemented GET /v2/LogFile

This commit is contained in:
Glax 2024-04-22 03:19:56 +02:00
parent cce4901a5d
commit 64482931a3
3 changed files with 17 additions and 2 deletions

View File

@ -217,7 +217,7 @@ public partial class Server : GlobalBase, IDisposable
case "jpeg":
response.ContentType = "image/jpeg";
break;
case "log":
default:
response.ContentType = "text/plain";
break;
}

View File

@ -7,7 +7,18 @@ public partial class Server
{
private ValueTuple<HttpStatusCode, object?> GetV2LogFile(GroupCollection groups, Dictionary<string, string> requestParameters)
{
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "Not Implemented");
if (logger is null || !File.Exists(logger?.logFilePath))
{
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, "Missing Logfile");
}
FileStream logFile = new (logger.logFilePath, FileMode.Open, FileAccess.Read);
FileStream content = new(Path.GetTempFileName(), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, 0, FileOptions.DeleteOnClose);
logFile.Position = 0;
logFile.CopyTo(content);
content.Position = 0;
logFile.Dispose();
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, content);
}
private ValueTuple<HttpStatusCode, object?> GetV2Ping(GroupCollection groups, Dictionary<string, string> requestParameters)

View File

@ -878,6 +878,10 @@ Returns the current log-file.
<summary>Returns</summary>
The Logfile as Stream.
| StatusCode | Meaning |
|------------|------------|
| 404 | No Logfile |
</details>
### <sub>![GET](https://img.shields.io/badge/GET-0f0)</sub> `/v2/Ping`