From b868ee66e6272b93ad281e8c8686ebd76815a8d6 Mon Sep 17 00:00:00 2001 From: Sergey Karmanov Date: Wed, 19 Nov 2025 16:48:19 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BE=D0=B1=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=82=D0=BE=D0=BA?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SfeduSchedule/Jobs/UpdateJWTJob.cs | 8 ++++++-- SfeduSchedule/Services/ModeusService.cs | 12 +++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/SfeduSchedule/Jobs/UpdateJWTJob.cs b/SfeduSchedule/Jobs/UpdateJWTJob.cs index 4064467..8bf15c6 100644 --- a/SfeduSchedule/Jobs/UpdateJWTJob.cs +++ b/SfeduSchedule/Jobs/UpdateJWTJob.cs @@ -1,12 +1,14 @@ using ModeusSchedule.Abstractions; using Quartz; +using SfeduSchedule.Services; namespace SfeduSchedule.Jobs; public class UpdateJwtJob( IConfiguration configuration, ILogger logger, - IHttpClientFactory httpClientFactory) : IJob + IHttpClientFactory httpClientFactory, + ModeusService modeusService) : IJob { private const int MaxAttempts = 5; // Максимальное число попыток private const int DelaySeconds = 20; // Задержка между попытками в секундах @@ -68,7 +70,9 @@ public class UpdateJwtJob( } configuration["TOKEN"] = body.Jwt; - await File.WriteAllTextAsync(GlobalConsts.JwtFilePath, body.Jwt + "\n" + DateTime.Now.ToString("O"), cts.Token); + modeusService.SetToken(body.Jwt); + await File.WriteAllTextAsync(GlobalConsts.JwtFilePath, + body.Jwt + "\n" + DateTime.Now.ToString("O"), cts.Token); logger.LogInformation("JWT успешно обновлён"); return; } diff --git a/SfeduSchedule/Services/ModeusService.cs b/SfeduSchedule/Services/ModeusService.cs index 532bdc8..036070b 100644 --- a/SfeduSchedule/Services/ModeusService.cs +++ b/SfeduSchedule/Services/ModeusService.cs @@ -22,7 +22,17 @@ public class ModeusService _logger = logger; _configuration = configuration; _httpClient.BaseAddress = new Uri("https://sfedu.modeus.org/"); - var token = _configuration["TOKEN"]; + SetToken(_configuration["TOKEN"]); + } + + public void SetToken(string? token) + { + if (string.IsNullOrWhiteSpace(token)) { + _logger.LogError("SetToken: Предоставленный токен пустой."); + return; + } + + _httpClient.DefaultRequestHeaders.Remove(HeaderNames.Authorization); _httpClient.DefaultRequestHeaders.Add(HeaderNames.Authorization, $"Bearer {token}"); }