TimeSyncController.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  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();
  25. // Important to keep the following line at the end
  26. var responseTransmissionTime = DateTime.UtcNow.ToUniversalTime();
  27. // Implementing NTP on such a high level results in this useless
  28. // information being sent. On the other hand it enables future additions.
  29. return new UtcTimeResponse(requestReceptionTime, responseTransmissionTime);
  30. }
  31. }
  32. }