aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-07-17 18:21:35 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-07-17 18:21:35 -0400
commit06118307dd95b0834d67f3ae0604e3ffaf04af2a (patch)
tree499aca87a2a7a6cc7f435e426450688e0a12f92d /MediaBrowser.Server.Implementations
parent80eda34f9f18a890dcec79cb927323376d2cfdfa (diff)
disable chunked encoding for images
Diffstat (limited to 'MediaBrowser.Server.Implementations')
-rw-r--r--MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs98
-rw-r--r--MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs12
-rw-r--r--MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json3
-rw-r--r--MediaBrowser.Server.Implementations/Localization/Server/server.json9
-rw-r--r--MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj1
-rw-r--r--MediaBrowser.Server.Implementations/Sync/SyncManager.cs52
6 files changed, 92 insertions, 83 deletions
diff --git a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
index 86bd6b731..09071cbf9 100644
--- a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
+++ b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
@@ -118,14 +118,19 @@ namespace MediaBrowser.Server.Implementations.Drawing
public async Task ProcessImage(ImageProcessingOptions options, Stream toStream)
{
- if (options == null)
+ var file = await ProcessImage(options).ConfigureAwait(false);
+
+ using (var fileStream = _fileSystem.GetFileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read, true))
{
- throw new ArgumentNullException("options");
+ await fileStream.CopyToAsync(toStream).ConfigureAwait(false);
}
+ }
- if (toStream == null)
+ public async Task<string> ProcessImage(ImageProcessingOptions options)
+ {
+ if (options == null)
{
- throw new ArgumentNullException("toStream");
+ throw new ArgumentNullException("options");
}
var originalImagePath = options.Image.Path;
@@ -133,11 +138,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
if (options.HasDefaultOptions() && options.Enhancers.Count == 0 && !options.CropWhiteSpace)
{
// Just spit out the original file if all the options are default
- using (var fileStream = _fileSystem.GetFileStream(originalImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, true))
- {
- await fileStream.CopyToAsync(toStream).ConfigureAwait(false);
- return;
- }
+ return originalImagePath;
}
var dateModified = options.Image.DateModified;
@@ -166,30 +167,13 @@ namespace MediaBrowser.Server.Implementations.Drawing
if (options.HasDefaultOptionsWithoutSize() && newSize.Equals(originalImageSize) && options.Enhancers.Count == 0)
{
// Just spit out the original file if the new size equals the old
- using (var fileStream = _fileSystem.GetFileStream(originalImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, true))
- {
- await fileStream.CopyToAsync(toStream).ConfigureAwait(false);
- return;
- }
+ return originalImagePath;
}
var quality = options.Quality ?? 90;
var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, options.OutputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.BackgroundColor);
- try
- {
- using (var fileStream = _fileSystem.GetFileStream(cacheFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, true))
- {
- await fileStream.CopyToAsync(toStream).ConfigureAwait(false);
- return;
- }
- }
- catch (IOException)
- {
- // Cache file doesn't exist or is currently being written to
- }
-
var semaphore = GetLock(cacheFilePath);
await semaphore.WaitAsync().ConfigureAwait(false);
@@ -197,17 +181,12 @@ namespace MediaBrowser.Server.Implementations.Drawing
// Check again in case of lock contention
try
{
- using (var fileStream = _fileSystem.GetFileStream(cacheFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, true))
+ if (File.Exists(cacheFilePath))
{
- await fileStream.CopyToAsync(toStream).ConfigureAwait(false);
semaphore.Release();
- return;
+ return cacheFilePath;
}
}
- catch (IOException)
- {
- // Cache file doesn't exist or is currently being written to
- }
catch
{
semaphore.Release();
@@ -218,37 +197,6 @@ namespace MediaBrowser.Server.Implementations.Drawing
{
var hasPostProcessing = !string.IsNullOrEmpty(options.BackgroundColor) || options.UnplayedCount.HasValue || options.AddPlayedIndicator || options.PercentPlayed.HasValue;
- //if (!hasPostProcessing)
- //{
- // using (var outputStream = await _mediaEncoder.EncodeImage(new ImageEncodingOptions
- // {
- // InputPath = originalImagePath,
- // MaxHeight = options.MaxHeight,
- // MaxWidth = options.MaxWidth,
- // Height = options.Height,
- // Width = options.Width,
- // Quality = options.Quality,
- // Format = options.OutputFormat == ImageOutputFormat.Original ? Path.GetExtension(originalImagePath).TrimStart('.') : options.OutputFormat.ToString().ToLower()
-
- // }, CancellationToken.None).ConfigureAwait(false))
- // {
- // using (var outputMemoryStream = new MemoryStream())
- // {
- // // Save to the memory stream
- // await outputStream.CopyToAsync(outputMemoryStream).ConfigureAwait(false);
-
- // var bytes = outputMemoryStream.ToArray();
-
- // await toStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
-
- // // kick off a task to cache the result
- // await CacheResizedImage(cacheFilePath, bytes).ConfigureAwait(false);
- // }
-
- // return;
- // }
- //}
-
using (var fileStream = _fileSystem.GetFileStream(originalImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, true))
{
// Copy to memory stream to avoid Image locking file
@@ -289,18 +237,16 @@ namespace MediaBrowser.Server.Implementations.Drawing
var outputFormat = GetOutputFormat(originalImage, options.OutputFormat);
- using (var outputMemoryStream = new MemoryStream())
+ Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
+
+ // Save to the cache location
+ using (var cacheFileStream = _fileSystem.GetFileStream(cacheFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, false))
{
// Save to the memory stream
- thumbnail.Save(outputFormat, outputMemoryStream, quality);
-
- var bytes = outputMemoryStream.ToArray();
-
- await toStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
-
- // kick off a task to cache the result
- await CacheResizedImage(cacheFilePath, bytes).ConfigureAwait(false);
+ thumbnail.Save(outputFormat, cacheFileStream, quality);
}
+
+ return cacheFilePath;
}
}
@@ -324,9 +270,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
{
try
{
- var parentPath = Path.GetDirectoryName(cacheFilePath);
-
- Directory.CreateDirectory(parentPath);
+ Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
// Save to the cache location
using (var cacheFileStream = _fileSystem.GetFileStream(cacheFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs
index 8831d635c..6a60e5ea6 100644
--- a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs
+++ b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs
@@ -306,11 +306,15 @@ namespace MediaBrowser.Server.Implementations.HttpServer
throw new ArgumentNullException("path");
}
- return GetStaticFileResult(requestContext, path, MimeTypes.GetMimeType(path), fileShare, responseHeaders, isHeadRequest);
+ return GetStaticFileResult(requestContext, path, MimeTypes.GetMimeType(path), null, fileShare, responseHeaders, isHeadRequest);
}
- public object GetStaticFileResult(IRequest requestContext, string path, string contentType,
- FileShare fileShare = FileShare.Read, IDictionary<string, string> responseHeaders = null,
+ public object GetStaticFileResult(IRequest requestContext,
+ string path,
+ string contentType,
+ TimeSpan? cacheCuration = null,
+ FileShare fileShare = FileShare.Read,
+ IDictionary<string, string> responseHeaders = null,
bool isHeadRequest = false)
{
if (string.IsNullOrEmpty(path))
@@ -327,7 +331,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
var cacheKey = path + dateModified.Ticks;
- return GetStaticResult(requestContext, cacheKey.GetMD5(), dateModified, null, contentType, () => Task.FromResult(GetFileStream(path, fileShare)), responseHeaders, isHeadRequest);
+ return GetStaticResult(requestContext, cacheKey.GetMD5(), dateModified, cacheCuration, contentType, () => Task.FromResult(GetFileStream(path, fileShare)), responseHeaders, isHeadRequest);
}
/// <summary>
diff --git a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json
index d88e2d6ab..187bcb59f 100644
--- a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json
+++ b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json
@@ -319,5 +319,6 @@
"ButtonAudioTracks": "Audio Tracks",
"ButtonSubtitles": "Subtitles",
"ButtonScenes": "Scenes",
- "ButtonQuality": "Quality"
+ "ButtonQuality": "Quality",
+ "HeaderNotifications": "Notifications"
}
diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json
index e203a6d9d..741bc52ca 100644
--- a/MediaBrowser.Server.Implementations/Localization/Server/server.json
+++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json
@@ -882,5 +882,12 @@
"LabelAppName": "App name",
"LabelAppNameExample": "Example: Sickbeard, NzbDrone",
"HeaderNewApiKeyHelp": "Grant an application permission to communicate with Media Browser.",
- "ButtonEnterSupporterKey": "Enter supporter key"
+ "ButtonEnterSupporterKey": "Enter supporter key",
+ "HeaderHttpHeaders": "Http Headers",
+ "HeaderIdentificationHeader": "Identification Header",
+ "LabelValue": "Value:",
+ "LabelMatchType": "Match type:",
+ "OptionEquals": "Equals",
+ "OptionRegex": "Regex",
+ "OptionSubstring": "Substring"
} \ No newline at end of file
diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
index 376a95e04..1bb789484 100644
--- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
+++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
@@ -261,6 +261,7 @@
<Compile Include="Persistence\SqliteUserRepository.cs" />
<Compile Include="Sorting\StudioComparer.cs" />
<Compile Include="Sorting\VideoBitRateComparer.cs" />
+ <Compile Include="Sync\SyncManager.cs" />
<Compile Include="Themes\AppThemeManager.cs" />
<Compile Include="Udp\UdpMessageReceivedEventArgs.cs" />
<Compile Include="Udp\UdpServer.cs" />
diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs
new file mode 100644
index 000000000..373b30a41
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs
@@ -0,0 +1,52 @@
+using MediaBrowser.Controller.Sync;
+using MediaBrowser.Model.Querying;
+using MediaBrowser.Model.Sync;
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Server.Implementations.Sync
+{
+ public class SyncManager : ISyncManager
+ {
+ public Task<List<SyncJob>> CreateJob(SyncJobRequest request)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task<SyncSchedule> CreateSchedule(SyncScheduleRequest request)
+ {
+ throw new NotImplementedException();
+ }
+
+ public QueryResult<SyncJob> GetJobs(SyncJobQuery query)
+ {
+ throw new NotImplementedException();
+ }
+
+ public QueryResult<SyncSchedule> GetSchedules(SyncScheduleQuery query)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task CancelJob(string id)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task CancelSchedule(string id)
+ {
+ throw new NotImplementedException();
+ }
+
+ public SyncJob GetJob(string id)
+ {
+ throw new NotImplementedException();
+ }
+
+ public SyncSchedule GetSchedule(string id)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}