CameraUploadsFolder.cs 2.6 KB

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