CameraUploadsFolder.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. public override string CollectionType
  28. {
  29. get { return Model.Entities.CollectionType.Photos; }
  30. }
  31. public override string GetClientTypeName()
  32. {
  33. return typeof(CollectionFolder).Name;
  34. }
  35. private bool? _hasChildren;
  36. private bool HasChildren()
  37. {
  38. if (!_hasChildren.HasValue)
  39. {
  40. _hasChildren = LibraryManager.GetItemIds(new InternalItemsQuery { ParentId = Id }).Count > 0;
  41. }
  42. return _hasChildren.Value;
  43. }
  44. protected override Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService)
  45. {
  46. _hasChildren = null;
  47. return base.ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService);
  48. }
  49. [IgnoreDataMember]
  50. public bool EnableUserSpecificView
  51. {
  52. get { return true; }
  53. }
  54. }
  55. public class CameraUploadsDynamicFolder : IVirtualFolderCreator
  56. {
  57. private readonly IApplicationPaths _appPaths;
  58. private readonly IFileSystem _fileSystem;
  59. public CameraUploadsDynamicFolder(IApplicationPaths appPaths, IFileSystem fileSystem)
  60. {
  61. _appPaths = appPaths;
  62. _fileSystem = fileSystem;
  63. }
  64. public BasePluginFolder GetFolder()
  65. {
  66. var path = Path.Combine(_appPaths.DataPath, "camerauploads");
  67. _fileSystem.CreateDirectory(path);
  68. return new CameraUploadsFolder
  69. {
  70. Path = path
  71. };
  72. }
  73. }
  74. }