CameraUploadsFolder.cs 2.7 KB

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