TimeSyncController.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Globalization;
  3. using MediaBrowser.Model.SyncPlay;
  4. using Microsoft.AspNetCore.Http;
  5. using Microsoft.AspNetCore.Mvc;
  6. namespace Jellyfin.Api.Controllers
  7. {
  8. /// <summary>
  9. /// The time sync controller.
  10. /// </summary>
  11. [Route("")]
  12. public class TimeSyncController : BaseJellyfinApiController
  13. {
  14. /// <summary>
  15. /// Gets the current utc time.
  16. /// </summary>
  17. /// <response code="200">Time returned.</response>
  18. /// <returns>An <see cref="UtcTimeResponse"/> to sync the client and server time.</returns>
  19. [HttpGet("GetUtcTime")]
  20. [ProducesResponseType(statusCode: StatusCodes.Status200OK)]
  21. public ActionResult<UtcTimeResponse> GetUtcTime()
  22. {
  23. // Important to keep the following line at the beginning
  24. var requestReceptionTime = DateTime.UtcNow.ToUniversalTime().ToString("o", DateTimeFormatInfo.InvariantInfo);
  25. var response = new UtcTimeResponse();
  26. response.RequestReceptionTime = requestReceptionTime;
  27. // Important to keep the following two lines at the end
  28. var responseTransmissionTime = DateTime.UtcNow.ToUniversalTime().ToString("o", DateTimeFormatInfo.InvariantInfo);
  29. response.ResponseTransmissionTime = responseTransmissionTime;
  30. // Implementing NTP on such a high level results in this useless
  31. // information being sent. On the other hand it enables future additions.
  32. return response;
  33. }
  34. }
  35. }