mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-03 12:52:56 +01:00
made some improvements to the base http handler
This commit is contained in:
parent
19e202d5e1
commit
d8c01ded6e
@@ -90,14 +90,15 @@ namespace MediaBrowser.Api.HttpHandlers
|
||||
}
|
||||
}
|
||||
|
||||
public override Task<string> GetContentType()
|
||||
protected override Task<ResponseInfo> GetResponseInfo()
|
||||
{
|
||||
return Task.FromResult(MimeTypes.GetMimeType("." + GetConversionOutputFormat()));
|
||||
}
|
||||
ResponseInfo info = new ResponseInfo
|
||||
{
|
||||
ContentType = MimeTypes.GetMimeType("." + GetConversionOutputFormat()),
|
||||
CompressResponse = false
|
||||
};
|
||||
|
||||
public override bool ShouldCompressResponse(string contentType)
|
||||
{
|
||||
return false;
|
||||
return Task.FromResult<ResponseInfo>(info);
|
||||
}
|
||||
|
||||
public override Task ProcessRequest(HttpListenerContext ctx)
|
||||
|
||||
@@ -7,7 +7,6 @@ using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -82,76 +81,32 @@ namespace MediaBrowser.Api.HttpHandlers
|
||||
return ImageProcessor.GetImagePath(entity, ImageType, ImageIndex);
|
||||
}
|
||||
|
||||
public override async Task<string> GetContentType()
|
||||
{
|
||||
if (Kernel.Instance.ImageProcessors.Any(i => i.RequiresTransparency))
|
||||
{
|
||||
return MimeTypes.GetMimeType(".png");
|
||||
}
|
||||
|
||||
return MimeTypes.GetMimeType(await GetImagePath().ConfigureAwait(false));
|
||||
}
|
||||
|
||||
public override TimeSpan CacheDuration
|
||||
{
|
||||
get { return TimeSpan.FromDays(365); }
|
||||
}
|
||||
|
||||
protected override async Task<DateTime?> GetLastDateModified()
|
||||
protected async override Task<ResponseInfo> GetResponseInfo()
|
||||
{
|
||||
string path = await GetImagePath().ConfigureAwait(false);
|
||||
|
||||
DateTime date = File.GetLastWriteTimeUtc(path);
|
||||
ResponseInfo info = new ResponseInfo
|
||||
{
|
||||
CacheDuration = TimeSpan.FromDays(365),
|
||||
ContentType = MimeTypes.GetMimeType(path)
|
||||
};
|
||||
|
||||
DateTime? date = File.GetLastWriteTimeUtc(path);
|
||||
|
||||
// If the file does not exist it will return jan 1, 1601
|
||||
// http://msdn.microsoft.com/en-us/library/system.io.file.getlastwritetimeutc.aspx
|
||||
if (date.Year == 1601)
|
||||
if (date.Value.Year == 1601)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
StatusCode = 404;
|
||||
return null;
|
||||
info.StatusCode = 404;
|
||||
date = null;
|
||||
}
|
||||
}
|
||||
|
||||
return await GetMostRecentDateModified(date);
|
||||
}
|
||||
info.DateLastModified = date;
|
||||
|
||||
private async Task<DateTime> GetMostRecentDateModified(DateTime imageFileLastDateModified)
|
||||
{
|
||||
var date = imageFileLastDateModified;
|
||||
|
||||
var entity = await GetSourceEntity().ConfigureAwait(false);
|
||||
|
||||
foreach (var processor in Kernel.Instance.ImageProcessors)
|
||||
{
|
||||
if (processor.IsConfiguredToProcess(entity, ImageType, ImageIndex))
|
||||
{
|
||||
if (processor.ProcessingConfigurationDateLastModifiedUtc > date)
|
||||
{
|
||||
date = processor.ProcessingConfigurationDateLastModifiedUtc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
protected override async Task<string> GetETag()
|
||||
{
|
||||
string tag = string.Empty;
|
||||
|
||||
var entity = await GetSourceEntity().ConfigureAwait(false);
|
||||
|
||||
foreach (var processor in Kernel.Instance.ImageProcessors)
|
||||
{
|
||||
if (processor.IsConfiguredToProcess(entity, ImageType, ImageIndex))
|
||||
{
|
||||
tag += processor.ProcessingConfigurationDateLastModifiedUtc.Ticks.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return tag;
|
||||
return info;
|
||||
}
|
||||
|
||||
private int ImageIndex
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
return ApiService.IsApiUrlMatch("pluginassembly", request);
|
||||
}
|
||||
|
||||
public override Task<string> GetContentType()
|
||||
|
||||
protected override Task<ResponseInfo> GetResponseInfo()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
return ApiService.IsApiUrlMatch("pluginconfiguration", request);
|
||||
}
|
||||
|
||||
|
||||
private BasePlugin _plugin;
|
||||
private BasePlugin Plugin
|
||||
{
|
||||
@@ -39,18 +39,15 @@ namespace MediaBrowser.Api.HttpHandlers
|
||||
return Task.FromResult(Plugin.Configuration);
|
||||
}
|
||||
|
||||
public override TimeSpan CacheDuration
|
||||
protected override async Task<ResponseInfo> GetResponseInfo()
|
||||
{
|
||||
get
|
||||
{
|
||||
return TimeSpan.FromDays(7);
|
||||
}
|
||||
}
|
||||
var info = await base.GetResponseInfo().ConfigureAwait(false);
|
||||
|
||||
protected override Task<DateTime?> GetLastDateModified()
|
||||
{
|
||||
return Task.FromResult<DateTime?>(Plugin.ConfigurationDateLastModified);
|
||||
}
|
||||
info.DateLastModified = Plugin.ConfigurationDateLastModified;
|
||||
|
||||
info.CacheDuration = TimeSpan.FromDays(7);
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,23 +16,22 @@ namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
return ApiService.IsApiUrlMatch("serverconfiguration", request);
|
||||
}
|
||||
|
||||
|
||||
protected override Task<ServerConfiguration> GetObjectToSerialize()
|
||||
{
|
||||
return Task.FromResult(Kernel.Instance.Configuration);
|
||||
}
|
||||
|
||||
public override TimeSpan CacheDuration
|
||||
protected override async Task<ResponseInfo> GetResponseInfo()
|
||||
{
|
||||
get
|
||||
{
|
||||
return TimeSpan.FromDays(7);
|
||||
}
|
||||
}
|
||||
var info = await base.GetResponseInfo().ConfigureAwait(false);
|
||||
|
||||
protected override Task<DateTime?> GetLastDateModified()
|
||||
{
|
||||
return Task.FromResult<DateTime?>(File.GetLastWriteTimeUtc(Kernel.Instance.ApplicationPaths.SystemConfigurationFilePath));
|
||||
info.DateLastModified =
|
||||
File.GetLastWriteTimeUtc(Kernel.Instance.ApplicationPaths.SystemConfigurationFilePath);
|
||||
|
||||
info.CacheDuration = TimeSpan.FromDays(7);
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
return ApiService.IsApiUrlMatch("weather", request);
|
||||
}
|
||||
|
||||
|
||||
protected override Task<WeatherInfo> GetObjectToSerialize()
|
||||
{
|
||||
// If a specific zip code was requested on the query string, use that. Otherwise use the value from configuration
|
||||
@@ -31,15 +31,13 @@ namespace MediaBrowser.Api.HttpHandlers
|
||||
return Kernel.Instance.WeatherProviders.First().GetWeatherInfoAsync(zipCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tell the client to cache the weather info for 15 minutes
|
||||
/// </summary>
|
||||
public override TimeSpan CacheDuration
|
||||
protected override async Task<ResponseInfo> GetResponseInfo()
|
||||
{
|
||||
get
|
||||
{
|
||||
return TimeSpan.FromMinutes(15);
|
||||
}
|
||||
var info = await base.GetResponseInfo().ConfigureAwait(false);
|
||||
|
||||
info.CacheDuration = TimeSpan.FromMinutes(15);
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user