standardize knowledge of supported image extensions
This commit is contained in:
parent
3387dac01d
commit
300c3b7fd6
|
@ -1,8 +1,10 @@
|
|||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using ServiceStack.ServiceHost;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Api.Images
|
||||
{
|
||||
|
@ -98,9 +100,11 @@ namespace MediaBrowser.Api.Images
|
|||
? "folder"
|
||||
: request.Type;
|
||||
|
||||
var file = Path.Combine(_appPaths.GeneralPath, request.Name, filename + ".jpg");
|
||||
var paths = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(_appPaths.GeneralPath, request.Name, filename + i)).ToList();
|
||||
|
||||
return ToStaticFileResult(File.Exists(file) ? file : Path.ChangeExtension(file, ".png"));
|
||||
var path = paths.FirstOrDefault(File.Exists) ?? paths.FirstOrDefault();
|
||||
|
||||
return ToStaticFileResult(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -114,18 +118,12 @@ namespace MediaBrowser.Api.Images
|
|||
|
||||
if (Directory.Exists(themeFolder))
|
||||
{
|
||||
var file = Path.Combine(themeFolder, request.Name + ".png");
|
||||
var path = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(themeFolder, request.Name + i))
|
||||
.FirstOrDefault(File.Exists);
|
||||
|
||||
if (File.Exists(file))
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
return ToStaticFileResult(file);
|
||||
}
|
||||
|
||||
file = Path.Combine(themeFolder, request.Name + ".jpg");
|
||||
|
||||
if (File.Exists(file))
|
||||
{
|
||||
return ToStaticFileResult(file);
|
||||
return ToStaticFileResult(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,18 +131,15 @@ namespace MediaBrowser.Api.Images
|
|||
|
||||
if (Directory.Exists(allFolder))
|
||||
{
|
||||
var file = Path.Combine(allFolder, request.Name + ".png");
|
||||
// Avoid implicitly captured closure
|
||||
var currentRequest = request;
|
||||
|
||||
if (File.Exists(file))
|
||||
var path = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(allFolder, currentRequest.Name + i))
|
||||
.FirstOrDefault(File.Exists);
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
return ToStaticFileResult(file);
|
||||
}
|
||||
|
||||
file = Path.Combine(allFolder, request.Name + ".jpg");
|
||||
|
||||
if (File.Exists(file))
|
||||
{
|
||||
return ToStaticFileResult(file);
|
||||
return ToStaticFileResult(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,18 +157,12 @@ namespace MediaBrowser.Api.Images
|
|||
|
||||
if (Directory.Exists(themeFolder))
|
||||
{
|
||||
var file = Path.Combine(themeFolder, request.Name + ".png");
|
||||
var path = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(themeFolder, request.Name + i))
|
||||
.FirstOrDefault(File.Exists);
|
||||
|
||||
if (File.Exists(file))
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
return ToStaticFileResult(file);
|
||||
}
|
||||
|
||||
file = Path.Combine(themeFolder, request.Name + ".jpg");
|
||||
|
||||
if (File.Exists(file))
|
||||
{
|
||||
return ToStaticFileResult(file);
|
||||
return ToStaticFileResult(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,18 +170,15 @@ namespace MediaBrowser.Api.Images
|
|||
|
||||
if (Directory.Exists(allFolder))
|
||||
{
|
||||
var file = Path.Combine(allFolder, request.Name + ".png");
|
||||
// Avoid implicitly captured closure
|
||||
var currentRequest = request;
|
||||
|
||||
if (File.Exists(file))
|
||||
var path = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(allFolder, currentRequest.Name + i))
|
||||
.FirstOrDefault(File.Exists);
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
return ToStaticFileResult(file);
|
||||
}
|
||||
|
||||
file = Path.Combine(allFolder, request.Name + ".jpg");
|
||||
|
||||
if (File.Exists(file))
|
||||
{
|
||||
return ToStaticFileResult(file);
|
||||
return ToStaticFileResult(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,9 +36,10 @@ namespace MediaBrowser.Controller.Dto
|
|||
dto.NowPlayingItem = DtoBuilder.GetBaseItemInfo(session.NowPlayingItem);
|
||||
}
|
||||
|
||||
if (session.UserId.HasValue)
|
||||
if (session.User != null)
|
||||
{
|
||||
dto.UserId = session.UserId.Value.ToString("N");
|
||||
dto.UserId = session.User.Id.ToString("N");
|
||||
dto.UserName = session.User.Name;
|
||||
}
|
||||
|
||||
return dto;
|
||||
|
|
|
@ -42,6 +42,11 @@ namespace MediaBrowser.Controller.Entities
|
|||
LocalTrailerIds = new List<Guid>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The supported image extensions
|
||||
/// </summary>
|
||||
public static readonly string[] SupportedImageExtensions = new[] { ".png", ".jpg", ".jpeg" };
|
||||
|
||||
/// <summary>
|
||||
/// The trailer folder name
|
||||
/// </summary>
|
||||
|
|
|
@ -146,8 +146,7 @@ namespace MediaBrowser.Controller.Providers
|
|||
/// <returns>FileSystemInfo.</returns>
|
||||
protected virtual FileSystemInfo GetImage(BaseItem item, string filenameWithoutExtension)
|
||||
{
|
||||
return item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.ResolveArgs.Path, filenameWithoutExtension + ".png"))
|
||||
?? item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.ResolveArgs.Path, filenameWithoutExtension + ".jpg"));
|
||||
return BaseItem.SupportedImageExtensions.Select(i => item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.ResolveArgs.Path, filenameWithoutExtension + i))).FirstOrDefault(i => i != null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace MediaBrowser.Controller.Session
|
|||
/// Gets or sets the user id.
|
||||
/// </summary>
|
||||
/// <value>The user id.</value>
|
||||
public Guid? UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the client.
|
||||
|
|
|
@ -17,6 +17,12 @@ namespace MediaBrowser.Model.Session
|
|||
/// <value>The user id.</value>
|
||||
public string UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the user.
|
||||
/// </summary>
|
||||
/// <value>The name of the user.</value>
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the client.
|
||||
/// </summary>
|
||||
|
|
|
@ -4,6 +4,7 @@ using MediaBrowser.Controller.Entities;
|
|||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -175,7 +176,13 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
|||
/// <returns>IEnumerable{System.String}.</returns>
|
||||
private IEnumerable<string> GetFiles(string path)
|
||||
{
|
||||
return Directory.EnumerateFiles(path, "*.jpg", SearchOption.AllDirectories).Concat(Directory.EnumerateFiles(path, "*.png", SearchOption.AllDirectories));
|
||||
return Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)
|
||||
.Where(i =>
|
||||
{
|
||||
var ext = Path.GetExtension(i);
|
||||
|
||||
return !string.IsNullOrEmpty(ext) && BaseItem.SupportedImageExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -185,7 +185,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
|
||||
connection.DeviceName = deviceName;
|
||||
|
||||
connection.UserId = user == null ? (Guid?)null : user.Id;
|
||||
connection.User = user;
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
|
|
@ -99,18 +99,18 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
{
|
||||
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||
|
||||
if (session != null && session.UserId.HasValue)
|
||||
if (session != null && session.User != null)
|
||||
{
|
||||
var item = DtoBuilder.GetItemByClientId(message.Data, _userManager, _libraryManager);
|
||||
|
||||
_sessionManager.OnPlaybackStart(_userManager.GetUserById(session.UserId.Value), item, session.Client, session.DeviceId, session.DeviceName);
|
||||
_sessionManager.OnPlaybackStart(_userManager.GetUserById(session.User.Id), item, session.Client, session.DeviceId, session.DeviceName);
|
||||
}
|
||||
}
|
||||
else if (string.Equals(message.MessageType, "PlaybackProgress", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||
|
||||
if (session != null && session.UserId.HasValue)
|
||||
if (session != null && session.User != null)
|
||||
{
|
||||
var vals = message.Data.Split('|');
|
||||
|
||||
|
@ -130,14 +130,14 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
|
||||
var isPaused = vals.Length > 2 && string.Equals(vals[2], "true", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
_sessionManager.OnPlaybackProgress(_userManager.GetUserById(session.UserId.Value), item, positionTicks, isPaused, session.Client, session.DeviceId, session.DeviceName);
|
||||
_sessionManager.OnPlaybackProgress(_userManager.GetUserById(session.User.Id), item, positionTicks, isPaused, session.Client, session.DeviceId, session.DeviceName);
|
||||
}
|
||||
}
|
||||
else if (string.Equals(message.MessageType, "PlaybackStopped", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||
|
||||
if (session != null && session.UserId.HasValue)
|
||||
if (session != null && session.User != null)
|
||||
{
|
||||
var vals = message.Data.Split('|');
|
||||
|
||||
|
@ -155,7 +155,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
}
|
||||
}
|
||||
|
||||
_sessionManager.OnPlaybackStopped(_userManager.GetUserById(session.UserId.Value), item, positionTicks, session.Client, session.DeviceId, session.DeviceName);
|
||||
_sessionManager.OnPlaybackStopped(_userManager.GetUserById(session.User.Id), item, positionTicks, session.Client, session.DeviceId, session.DeviceName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -190,12 +190,18 @@ namespace MediaBrowser.ServerApplication.EntryPoints
|
|||
{
|
||||
var currentSessions = _sessionManager.Sessions.ToList();
|
||||
|
||||
var users = currentSessions.Select(i => i.UserId ?? Guid.Empty).Where(i => i != Guid.Empty).Distinct().ToList();
|
||||
var users = currentSessions.Select(i => i.User)
|
||||
.Where(i => i != null)
|
||||
.Select(i => i.Id)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
foreach (var userId in users)
|
||||
{
|
||||
var id = userId;
|
||||
var webSockets = currentSessions.Where(u => u.UserId.HasValue && u.UserId.Value == id).SelectMany(i => i.WebSockets).ToList();
|
||||
var webSockets = currentSessions.Where(u => u.User != null && u.User.Id == id)
|
||||
.SelectMany(i => i.WebSockets)
|
||||
.ToList();
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -208,7 +208,7 @@ namespace MediaBrowser.WebDashboard.Api
|
|||
|
||||
var dtoBuilder = new UserDtoBuilder(logger);
|
||||
|
||||
var tasks = userManager.Users.Where(u => connections.Any(c => c.UserId.HasValue && c.UserId.Value == u.Id)).Select(dtoBuilder.GetUserDto);
|
||||
var tasks = userManager.Users.Where(u => connections.Any(c => c.User != null && c.User.Id == u.Id)).Select(dtoBuilder.GetUserDto);
|
||||
|
||||
var users = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user