CameraUploadsFolder.cs 2.4 KB

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