From 767cdc1f6f6a63ce997fc9476911e2c361f9d402 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Wed, 20 Feb 2013 20:33:05 -0500 Subject: Pushing missing changes --- .../JavascriptApiClientService.cs | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 MediaBrowser.ApiInteraction.Javascript/JavascriptApiClientService.cs (limited to 'MediaBrowser.ApiInteraction.Javascript/JavascriptApiClientService.cs') diff --git a/MediaBrowser.ApiInteraction.Javascript/JavascriptApiClientService.cs b/MediaBrowser.ApiInteraction.Javascript/JavascriptApiClientService.cs new file mode 100644 index 000000000..b94b8e071 --- /dev/null +++ b/MediaBrowser.ApiInteraction.Javascript/JavascriptApiClientService.cs @@ -0,0 +1,60 @@ +using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Net; +using ServiceStack.ServiceHost; +using System; +using System.ComponentModel.Composition; +using System.IO; +using System.Threading.Tasks; + +namespace MediaBrowser.ApiInteraction.Javascript +{ + /// + /// Class GetJavascriptApiClient + /// + [Route("/JsApiClient.js", "GET")] + [Api(("Gets an api wrapper in Javascript"))] + public class GetJavascriptApiClient + { + /// + /// Version identifier for caching + /// + /// The v. + public string V { get; set; } + } + + /// + /// Class JavascriptApiClientService + /// + [Export(typeof(IRestfulService))] + 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.ApiInteraction.Javascript.ApiClient.js")); + } + } +} -- cgit v1.2.3