CameraUploadsFolder.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using MediaBrowser.Common.Configuration;
  2. using MediaBrowser.Controller.Entities;
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Runtime.Serialization;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using MediaBrowser.Common.IO;
  10. using MediaBrowser.Controller.IO;
  11. using MediaBrowser.Model.IO;
  12. using MediaBrowser.Controller.Providers;
  13. namespace MediaBrowser.Server.Implementations.Devices
  14. {
  15. public class CameraUploadsFolder : BasePluginFolder, ISupportsUserSpecificView
  16. {
  17. public CameraUploadsFolder()
  18. {
  19. Name = "Camera Uploads";
  20. }
  21. public override bool IsVisible(User user)
  22. {
  23. if (!user.Policy.EnableAllFolders && !user.Policy.EnabledFolders.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
  24. {
  25. return false;
  26. }
  27. return base.IsVisible(user) && HasChildren();
  28. }
  29. [IgnoreDataMember]
  30. public override string CollectionType
  31. {
  32. get { return Model.Entities.CollectionType.Photos; }
  33. }
  34. public override string GetClientTypeName()
  35. {
  36. return typeof(CollectionFolder).Name;
  37. }
  38. private bool? _hasChildren;
  39. private bool HasChildren()
  40. {
  41. if (!_hasChildren.HasValue)
  42. {
  43. _hasChildren = LibraryManager.GetItemIds(new InternalItemsQuery { ParentId = Id }).Count > 0;
  44. }
  45. return _hasChildren.Value;
  46. }
  47. protected override Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService)
  48. {
  49. _hasChildren = null;
  50. return base.ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService);
  51. }
  52. [IgnoreDataMember]
  53. public bool EnableUserSpecificView
  54. {
  55. get { return true; }
  56. }
  57. }
  58. public class CameraUploadsDynamicFolder : IVirtualFolderCreator
  59. {
  60. private readonly IApplicationPaths _appPaths;
  61. private readonly IFileSystem _fileSystem;
  62. public CameraUploadsDynamicFolder(IApplicationPaths appPaths, IFileSystem fileSystem)
  63. {
  64. _appPaths = appPaths;
  65. _fileSystem = fileSystem;
  66. }
  67. public BasePluginFolder GetFolder()
  68. {
  69. var path = Path.Combine(_appPaths.DataPath, "camerauploads");
  70. _fileSystem.CreateDirectory(path);
  71. return new CameraUploadsFolder
  72. {
  73. Path = path
  74. };
  75. }
  76. }
  77. }