TimeSyncController.cs 1.1 KB

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