Spaces:
No application file
No application file
Download Tawasol.API/Middleware/MaintenanceModeMiddleware.cs from MahmoudSaeedYousef/spaceM: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/MahmoudSaeedYousef/spaceM/resolve/main/Tawasol.API/Middleware/MaintenanceModeMiddleware.cs
- Command line
-
hf download hf://spaces/MahmoudSaeedYousef/spaceM/Tawasol.API/Middleware/MaintenanceModeMiddleware.cs
-
curl -L -o MaintenanceModeMiddleware.cs https://huggingface.co/spaces/MahmoudSaeedYousef/spaceM/resolve/main/Tawasol.API/Middleware/MaintenanceModeMiddleware.cs
1.21 kB
| using System.Net; | |
| using System.Text.Json; | |
| using Tawasol.Application.Common.Models; | |
| namespace Tawasol.API.Middleware; | |
| public class MaintenanceModeMiddleware | |
| { | |
| private readonly RequestDelegate _next; | |
| private readonly IConfiguration _configuration; | |
| public MaintenanceModeMiddleware(RequestDelegate next, IConfiguration configuration) | |
| { | |
| _next = next; | |
| _configuration = configuration; | |
| } | |
| public async Task InvokeAsync(HttpContext context) | |
| { | |
| var isMaintenance = _configuration.GetValue<bool>("MaintenanceMode:Enabled"); | |
| if (isMaintenance && !context.User.IsInRole("Hakim")) | |
| { | |
| context.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; | |
| context.Response.ContentType = "application/json"; | |
| var response = Result.Failure("The system is currently undergoing maintenance. Please try again later.", "Maintenance Mode"); | |
| var json = JsonSerializer.Serialize(response, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); | |
| await context.Response.WriteAsync(json); | |
| return; | |
| } | |
| await _next(context); | |
| } | |
| } | |