保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = getFilenameFromUrl;
 
var _path = _interopRequireDefault(require("path"));
 
var _url = require("url");
 
var _querystring = _interopRequireDefault(require("querystring"));
 
var _mem = _interopRequireDefault(require("mem"));
 
var _getPaths = _interopRequireDefault(require("./getPaths"));
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
const memoizedParse = (0, _mem.default)(_url.parse);
 
function getFilenameFromUrl(context, url) {
  const {
    options
  } = context;
  const paths = (0, _getPaths.default)(context);
  let foundFilename;
  let urlObject;
 
  try {
    // The `url` property of the `request` is contains only  `pathname`, `search` and `hash`
    urlObject = memoizedParse(url, false, true);
  } catch (_ignoreError) {
    return;
  }
 
  for (const {
    publicPath,
    outputPath
  } of paths) {
    let filename;
    let publicPathObject;
 
    try {
      publicPathObject = memoizedParse(publicPath !== "auto" && publicPath ? publicPath : "/", false, true);
    } catch (_ignoreError) {
      // eslint-disable-next-line no-continue
      continue;
    }
 
    if (urlObject.pathname && urlObject.pathname.startsWith(publicPathObject.pathname)) {
      filename = outputPath; // Strip the `pathname` property from the `publicPath` option from the start of requested url
      // `/complex/foo.js` => `foo.js`
 
      const pathname = urlObject.pathname.substr(publicPathObject.pathname.length);
 
      if (pathname) {
        filename = _path.default.join(outputPath, _querystring.default.unescape(pathname));
      }
 
      let fsStats;
 
      try {
        fsStats = context.outputFileSystem.statSync(filename);
      } catch (_ignoreError) {
        // eslint-disable-next-line no-continue
        continue;
      }
 
      if (fsStats.isFile()) {
        foundFilename = filename;
        break;
      } else if (fsStats.isDirectory() && (typeof options.index === "undefined" || options.index)) {
        const indexValue = typeof options.index === "undefined" || typeof options.index === "boolean" ? "index.html" : options.index;
        filename = _path.default.join(filename, indexValue);
 
        try {
          fsStats = context.outputFileSystem.statSync(filename);
        } catch (__ignoreError) {
          // eslint-disable-next-line no-continue
          continue;
        }
 
        if (fsStats.isFile()) {
          foundFilename = filename;
          break;
        }
      }
    }
  } // eslint-disable-next-line consistent-return
 
 
  return foundFilename;
}