CoreFileSystemHandle.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CoreFileSystemHandle = void 0;
  4. const CorePermissionStatus_1 = require("./CorePermissionStatus");
  5. /**
  6. * Represents a File System Access API file handle `FileSystemHandle` object,
  7. * which was created from a core `Superblock`.
  8. *
  9. * @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle)
  10. */
  11. class CoreFileSystemHandle {
  12. constructor(kind, name, ctx) {
  13. this.kind = kind;
  14. this.name = name;
  15. this.ctx = ctx;
  16. }
  17. /**
  18. * Compares two handles to see if the associated entries (either a file or directory) match.
  19. *
  20. * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/isSameEntry
  21. */
  22. isSameEntry(fileSystemHandle) {
  23. return (this.constructor === fileSystemHandle.constructor && this.__path === fileSystemHandle.__path);
  24. }
  25. /**
  26. * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/queryPermission
  27. */
  28. queryPermission(fileSystemHandlePermissionDescriptor) {
  29. // Check if the requested mode is compatible with the context mode
  30. const requestedMode = fileSystemHandlePermissionDescriptor.mode;
  31. const contextMode = this.ctx.mode;
  32. // If requesting readwrite but context only allows read, deny
  33. if (requestedMode === 'readwrite' && contextMode === 'read') {
  34. return new CorePermissionStatus_1.CorePermissionStatus('denied', requestedMode);
  35. }
  36. // Otherwise grant the permission
  37. return new CorePermissionStatus_1.CorePermissionStatus('granted', requestedMode);
  38. }
  39. /**
  40. * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/remove
  41. */
  42. async remove({ recursive } = { recursive: false }) {
  43. throw new Error('Not implemented');
  44. }
  45. /**
  46. * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/requestPermission
  47. */
  48. requestPermission(fileSystemHandlePermissionDescriptor) {
  49. throw new Error('Not implemented');
  50. }
  51. }
  52. exports.CoreFileSystemHandle = CoreFileSystemHandle;
  53. //# sourceMappingURL=CoreFileSystemHandle.js.map