mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Merge pull request #5301 from Bond-009/validinput
This commit is contained in:
commit
5860979500
@ -107,7 +107,7 @@ namespace Emby.Server.Implementations.Collections
|
|||||||
|
|
||||||
var name = _localizationManager.GetLocalizedString("Collections");
|
var name = _localizationManager.GetLocalizedString("Collections");
|
||||||
|
|
||||||
await _libraryManager.AddVirtualFolder(name, CollectionType.BoxSets, libraryOptions, true).ConfigureAwait(false);
|
await _libraryManager.AddVirtualFolder(name, CollectionTypeOptions.BoxSets, libraryOptions, true).ConfigureAwait(false);
|
||||||
|
|
||||||
return FindFolders(path).First();
|
return FindFolders(path).First();
|
||||||
}
|
}
|
||||||
|
@ -1240,11 +1240,20 @@ namespace Emby.Server.Implementations.Library
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetCollectionType(string path)
|
private CollectionTypeOptions? GetCollectionType(string path)
|
||||||
{
|
{
|
||||||
return _fileSystem.GetFilePaths(path, new[] { ".collection" }, true, false)
|
var files = _fileSystem.GetFilePaths(path, new[] { ".collection" }, true, false);
|
||||||
.Select(Path.GetFileNameWithoutExtension)
|
foreach (var file in files)
|
||||||
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
{
|
||||||
|
// TODO: @bond use a ReadOnlySpan<char> here when Enum.TryParse supports it
|
||||||
|
// https://github.com/dotnet/runtime/issues/20008
|
||||||
|
if (Enum.TryParse<CollectionTypeOptions>(Path.GetExtension(file), true, out var res))
|
||||||
|
{
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -2956,7 +2965,7 @@ namespace Emby.Server.Implementations.Library
|
|||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddVirtualFolder(string name, string collectionType, LibraryOptions options, bool refreshLibrary)
|
public async Task AddVirtualFolder(string name, CollectionTypeOptions? collectionType, LibraryOptions options, bool refreshLibrary)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(name))
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
{
|
{
|
||||||
@ -2990,9 +2999,9 @@ namespace Emby.Server.Implementations.Library
|
|||||||
{
|
{
|
||||||
Directory.CreateDirectory(virtualFolderPath);
|
Directory.CreateDirectory(virtualFolderPath);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(collectionType))
|
if (collectionType != null)
|
||||||
{
|
{
|
||||||
var path = Path.Combine(virtualFolderPath, collectionType + ".collection");
|
var path = Path.Combine(virtualFolderPath, collectionType.ToString() + ".collection");
|
||||||
|
|
||||||
File.WriteAllBytes(path, Array.Empty<byte>());
|
File.WriteAllBytes(path, Array.Empty<byte>());
|
||||||
}
|
}
|
||||||
|
@ -2604,7 +2604,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
|
|||||||
{
|
{
|
||||||
Locations = new string[] { customPath },
|
Locations = new string[] { customPath },
|
||||||
Name = "Recorded Movies",
|
Name = "Recorded Movies",
|
||||||
CollectionType = CollectionType.Movies
|
CollectionType = CollectionTypeOptions.Movies
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2615,7 +2615,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
|
|||||||
{
|
{
|
||||||
Locations = new string[] { customPath },
|
Locations = new string[] { customPath },
|
||||||
Name = "Recorded Shows",
|
Name = "Recorded Shows",
|
||||||
CollectionType = CollectionType.TvShows
|
CollectionType = CollectionTypeOptions.TvShows
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
public async Task<ActionResult> AddVirtualFolder(
|
public async Task<ActionResult> AddVirtualFolder(
|
||||||
[FromQuery] string? name,
|
[FromQuery] string? name,
|
||||||
[FromQuery] string? collectionType,
|
[FromQuery] CollectionTypeOptions? collectionType,
|
||||||
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] paths,
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] paths,
|
||||||
[FromBody] AddVirtualFolderDto? libraryOptionsDto,
|
[FromBody] AddVirtualFolderDto? libraryOptionsDto,
|
||||||
[FromQuery] bool refreshLibrary = false)
|
[FromQuery] bool refreshLibrary = false)
|
||||||
|
@ -542,7 +542,7 @@ namespace MediaBrowser.Controller.Library
|
|||||||
|
|
||||||
Guid GetMusicGenreId(string name);
|
Guid GetMusicGenreId(string name);
|
||||||
|
|
||||||
Task AddVirtualFolder(string name, string collectionType, LibraryOptions options, bool refreshLibrary);
|
Task AddVirtualFolder(string name, CollectionTypeOptions? collectionType, LibraryOptions options, bool refreshLibrary);
|
||||||
|
|
||||||
Task RemoveVirtualFolder(string name, bool refreshLibrary);
|
Task RemoveVirtualFolder(string name, bool refreshLibrary);
|
||||||
|
|
||||||
|
16
MediaBrowser.Model/Entities/CollectionTypeOptions.cs
Normal file
16
MediaBrowser.Model/Entities/CollectionTypeOptions.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
|
namespace MediaBrowser.Model.Entities
|
||||||
|
{
|
||||||
|
public enum CollectionTypeOptions
|
||||||
|
{
|
||||||
|
Movies = 0,
|
||||||
|
TvShows = 1,
|
||||||
|
Music = 2,
|
||||||
|
MusicVideos = 3,
|
||||||
|
HomeVideos = 4,
|
||||||
|
BoxSets = 5,
|
||||||
|
Books = 6,
|
||||||
|
Mixed = 7
|
||||||
|
}
|
||||||
|
}
|
@ -35,7 +35,7 @@ namespace MediaBrowser.Model.Entities
|
|||||||
/// Gets or sets the type of the collection.
|
/// Gets or sets the type of the collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The type of the collection.</value>
|
/// <value>The type of the collection.</value>
|
||||||
public string CollectionType { get; set; }
|
public CollectionTypeOptions? CollectionType { get; set; }
|
||||||
|
|
||||||
public LibraryOptions LibraryOptions { get; set; }
|
public LibraryOptions LibraryOptions { get; set; }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user