2
0

ApiService.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using MediaBrowser.Controller;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Model.Connectivity;
  4. using ServiceStack.Common.Web;
  5. using System;
  6. using System.Net;
  7. using System.Threading.Tasks;
  8. namespace MediaBrowser.Api
  9. {
  10. /// <summary>
  11. /// Contains some helpers for the api
  12. /// </summary>
  13. public static class ApiService
  14. {
  15. /// <summary>
  16. /// Gets a User by Id
  17. /// </summary>
  18. /// <param name="id">The id of the user</param>
  19. /// <returns>User.</returns>
  20. /// <exception cref="System.ArgumentNullException">id</exception>
  21. public static User GetUserById(string id)
  22. {
  23. if (string.IsNullOrEmpty(id))
  24. {
  25. throw new ArgumentNullException("id");
  26. }
  27. var guid = new Guid(id);
  28. return Kernel.Instance.GetUserById(guid);
  29. }
  30. /// <summary>
  31. /// Determines whether [is API URL match] [the specified URL].
  32. /// </summary>
  33. /// <param name="url">The URL.</param>
  34. /// <param name="request">The request.</param>
  35. /// <returns><c>true</c> if [is API URL match] [the specified URL]; otherwise, <c>false</c>.</returns>
  36. public static bool IsApiUrlMatch(string url, HttpListenerRequest request)
  37. {
  38. url = "/api/" + url;
  39. return request.Url.LocalPath.EndsWith(url, StringComparison.OrdinalIgnoreCase);
  40. }
  41. ///// <summary>
  42. ///// Gets the current user.
  43. ///// </summary>
  44. ///// <param name="request">The request.</param>
  45. ///// <returns>Task{User}.</returns>
  46. //public static async Task<User> GetCurrentUser(AuthenticatedRequest request)
  47. //{
  48. // var user = GetUserById(request.UserId);
  49. // if (user == null)
  50. // {
  51. // throw HttpError.Unauthorized("Invalid user or password entered.");
  52. // }
  53. // var clientType = ClientType.Other;
  54. // if (!string.IsNullOrEmpty(request.Client))
  55. // {
  56. // ClientType type;
  57. // if (Enum.TryParse(request.Client, true, out type))
  58. // {
  59. // clientType = type;
  60. // }
  61. // }
  62. // await Kernel.Instance.UserManager.LogUserActivity(user, clientType, request.Device).ConfigureAwait(false);
  63. // return user;
  64. //}
  65. }
  66. }