blob: 5ea6f3ebe9100f9ea463ca3fcd33cd5bf316c607 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
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
{
/// <summary>
/// Class GetJavascriptApiClient
/// </summary>
[Route("/JsApiClient.js", "GET")]
[ServiceStack.ServiceHost.Api(("Gets an api wrapper written in Javascript"))]
public class GetJavascriptApiClient
{
/// <summary>
/// Version identifier for caching
/// </summary>
/// <value>The v.</value>
public string V { get; set; }
}
/// <summary>
/// Class JavascriptApiClientService
/// </summary>
public class JavascriptApiClientService : BaseRestService
{
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
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);
}
/// <summary>
/// Gets the stream.
/// </summary>
/// <returns>Stream.</returns>
private Task<Stream> GetStream()
{
return Task.FromResult(GetType().Assembly.GetManifestResourceStream("MediaBrowser.Api.Javascript.ApiClient.js"));
}
}
}
|