@lvce-editor/file-search-worker 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -924,15 +924,66 @@ class FileNotFoundError extends Error {
924
924
  }
925
925
  }
926
926
 
927
- const getContentType = uri => {
928
- if (uri.endsWith('.png')) {
929
- return 'image/png';
927
+ const ApplicationJson = 'application/json';
928
+ const AudioMpeg = 'audio/mpeg';
929
+ const FontTtf = 'font/ttf';
930
+ const ImagePng = 'image/png';
931
+ const ImageSvgXml = 'image/svg+xml';
932
+ const TextCss = 'text/css';
933
+ const TextHtml = 'text/html';
934
+ const TextJavaScript = 'text/javascript';
935
+ const TextPlain = 'text/plain';
936
+ const VideoWebm = 'video/webm';
937
+
938
+ const getMimeType = fileExtension => {
939
+ switch (fileExtension) {
940
+ case '.html':
941
+ return TextHtml;
942
+ case '.css':
943
+ return TextCss;
944
+ case '.ttf':
945
+ return FontTtf;
946
+ case '.js':
947
+ case '.mjs':
948
+ case '.ts':
949
+ return TextJavaScript;
950
+ case '.svg':
951
+ return ImageSvgXml;
952
+ case '.png':
953
+ return ImagePng;
954
+ case '.json':
955
+ case '.map':
956
+ return ApplicationJson;
957
+ case '.mp3':
958
+ return AudioMpeg;
959
+ case '.webm':
960
+ return VideoWebm;
961
+ case '.txt':
962
+ return TextPlain;
963
+ default:
964
+ return '';
930
965
  }
931
- if (uri.endsWith('.svg')) {
932
- return 'image/svg+xml';
966
+ };
967
+
968
+ const dirname = (pathSeparator, path) => {
969
+ const index = path.lastIndexOf(pathSeparator);
970
+ if (index === -1) {
971
+ return path;
933
972
  }
934
- // TODO support more
935
- return '';
973
+ return path.slice(0, index);
974
+ };
975
+ const extname = path => {
976
+ const index = path.lastIndexOf('.');
977
+ if (index === -1) {
978
+ return '';
979
+ }
980
+ return path.slice(index);
981
+ };
982
+
983
+ const getContentType = uri => {
984
+ const extension = extname(uri);
985
+ const mime = getMimeType(extension);
986
+ return mime;
936
987
  };
937
988
 
938
989
  // TODO move this to an extension?
@@ -1125,14 +1176,6 @@ const getChildHandles = async handle => {
1125
1176
  return handles;
1126
1177
  };
1127
1178
 
1128
- const dirname = (pathSeparator, path) => {
1129
- const index = path.lastIndexOf(pathSeparator);
1130
- if (index === -1) {
1131
- return path;
1132
- }
1133
- return path.slice(0, index);
1134
- };
1135
-
1136
1179
  const instanceOfAny = (object, constructors) => constructors.some(c => object instanceof c);
1137
1180
  let idbProxyableTypes;
1138
1181
  let cursorAdvanceMethods;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-search-worker",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "main": "dist/fileSearchWorkerMain.js",
6
6
  "type": "module",