using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; using MediaBrowser.Server.Implementations.HttpServer; using ServiceStack.ServiceHost; using System; using System.IO; using System.Threading.Tasks; namespace MediaBrowser.Api.Javascript { /// /// Class GetJavascriptApiClient /// [Route("/JsApiClient.js", "GET")] [ServiceStack.ServiceHost.Api(("Gets an api wrapper written in Javascript"))] public class GetJavascriptApiClient { /// /// Version identifier for caching /// /// The v. public string V { get; set; } } /// /// Class JavascriptApiClientService /// public class JavascriptApiClientService : BaseRestService { /// /// Gets the specified request. /// /// The request. /// System.Object. public object Get(GetJavascriptApiClient request) { TimeSpan? cacheDuration = null; // If there's a version number in the query string we can cache this unconditionally if (!string.IsNullOrEmpty(request.V)) { cacheDuration = TimeSpan.FromDays(365); } var assembly = GetType().Assembly.GetName(); return ToStaticResult(assembly.Version.ToString().GetMD5(), null, cacheDuration, MimeTypes.GetMimeType("script.js"), GetStream); } /// /// Gets the stream. /// /// Stream. private Task GetStream() { return Task.FromResult(GetType().Assembly.GetManifestResourceStream("MediaBrowser.Api.Javascript.ApiClient.js")); } } }