file.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.toFileWithPath = exports.COMMON_MIME_TYPES = void 0;
  4. exports.COMMON_MIME_TYPES = new Map([
  5. // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
  6. ['aac', 'audio/aac'],
  7. ['abw', 'application/x-abiword'],
  8. ['arc', 'application/x-freearc'],
  9. ['avif', 'image/avif'],
  10. ['avi', 'video/x-msvideo'],
  11. ['azw', 'application/vnd.amazon.ebook'],
  12. ['bin', 'application/octet-stream'],
  13. ['bmp', 'image/bmp'],
  14. ['bz', 'application/x-bzip'],
  15. ['bz2', 'application/x-bzip2'],
  16. ['cda', 'application/x-cdf'],
  17. ['csh', 'application/x-csh'],
  18. ['css', 'text/css'],
  19. ['csv', 'text/csv'],
  20. ['doc', 'application/msword'],
  21. ['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
  22. ['eot', 'application/vnd.ms-fontobject'],
  23. ['epub', 'application/epub+zip'],
  24. ['gz', 'application/gzip'],
  25. ['gif', 'image/gif'],
  26. ['heic', 'image/heic'],
  27. ['heif', 'image/heif'],
  28. ['htm', 'text/html'],
  29. ['html', 'text/html'],
  30. ['ico', 'image/vnd.microsoft.icon'],
  31. ['ics', 'text/calendar'],
  32. ['jar', 'application/java-archive'],
  33. ['jpeg', 'image/jpeg'],
  34. ['jpg', 'image/jpeg'],
  35. ['js', 'text/javascript'],
  36. ['json', 'application/json'],
  37. ['jsonld', 'application/ld+json'],
  38. ['mid', 'audio/midi'],
  39. ['midi', 'audio/midi'],
  40. ['mjs', 'text/javascript'],
  41. ['mp3', 'audio/mpeg'],
  42. ['mp4', 'video/mp4'],
  43. ['mpeg', 'video/mpeg'],
  44. ['mpkg', 'application/vnd.apple.installer+xml'],
  45. ['odp', 'application/vnd.oasis.opendocument.presentation'],
  46. ['ods', 'application/vnd.oasis.opendocument.spreadsheet'],
  47. ['odt', 'application/vnd.oasis.opendocument.text'],
  48. ['oga', 'audio/ogg'],
  49. ['ogv', 'video/ogg'],
  50. ['ogx', 'application/ogg'],
  51. ['opus', 'audio/opus'],
  52. ['otf', 'font/otf'],
  53. ['png', 'image/png'],
  54. ['pdf', 'application/pdf'],
  55. ['php', 'application/x-httpd-php'],
  56. ['ppt', 'application/vnd.ms-powerpoint'],
  57. ['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
  58. ['rar', 'application/vnd.rar'],
  59. ['rtf', 'application/rtf'],
  60. ['sh', 'application/x-sh'],
  61. ['svg', 'image/svg+xml'],
  62. ['swf', 'application/x-shockwave-flash'],
  63. ['tar', 'application/x-tar'],
  64. ['tif', 'image/tiff'],
  65. ['tiff', 'image/tiff'],
  66. ['ts', 'video/mp2t'],
  67. ['ttf', 'font/ttf'],
  68. ['txt', 'text/plain'],
  69. ['vsd', 'application/vnd.visio'],
  70. ['wav', 'audio/wav'],
  71. ['weba', 'audio/webm'],
  72. ['webm', 'video/webm'],
  73. ['webp', 'image/webp'],
  74. ['woff', 'font/woff'],
  75. ['woff2', 'font/woff2'],
  76. ['xhtml', 'application/xhtml+xml'],
  77. ['xls', 'application/vnd.ms-excel'],
  78. ['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
  79. ['xml', 'application/xml'],
  80. ['xul', 'application/vnd.mozilla.xul+xml'],
  81. ['zip', 'application/zip'],
  82. ['7z', 'application/x-7z-compressed'],
  83. // Others
  84. ['mkv', 'video/x-matroska'],
  85. ['mov', 'video/quicktime'],
  86. ['msg', 'application/vnd.ms-outlook']
  87. ]);
  88. function toFileWithPath(file, path) {
  89. var f = withMimeType(file);
  90. if (typeof f.path !== 'string') { // on electron, path is already set to the absolute path
  91. var webkitRelativePath = file.webkitRelativePath;
  92. Object.defineProperty(f, 'path', {
  93. value: typeof path === 'string'
  94. ? path
  95. // If <input webkitdirectory> is set,
  96. // the File will have a {webkitRelativePath} property
  97. // https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory
  98. : typeof webkitRelativePath === 'string' && webkitRelativePath.length > 0
  99. ? webkitRelativePath
  100. : file.name,
  101. writable: false,
  102. configurable: false,
  103. enumerable: true
  104. });
  105. }
  106. return f;
  107. }
  108. exports.toFileWithPath = toFileWithPath;
  109. function withMimeType(file) {
  110. var name = file.name;
  111. var hasExtension = name && name.lastIndexOf('.') !== -1;
  112. if (hasExtension && !file.type) {
  113. var ext = name.split('.')
  114. .pop().toLowerCase();
  115. var type = exports.COMMON_MIME_TYPES.get(ext);
  116. if (type) {
  117. Object.defineProperty(file, 'type', {
  118. value: type,
  119. writable: false,
  120. configurable: false,
  121. enumerable: true
  122. });
  123. }
  124. }
  125. return file;
  126. }
  127. //# sourceMappingURL=file.js.map