Browse Source

fix: support paths relative to local server

Gerald 7 years ago
parent
commit
4e04a9ac29
1 changed files with 10 additions and 10 deletions
  1. 10 10
      src/background/utils/db.js

+ 10 - 10
src/background/utils/db.js

@@ -507,7 +507,7 @@ export function parseScript(data) {
     if (isRemote(data.url)) script.custom.lastInstallURL = data.url;
     const position = +data.position;
     if (position) objectSet(script, 'props.position', position);
-    buildPathMap(script);
+    buildPathMap(script, data.url);
     return saveScript(script, code).then(() => script);
   })
   .then(script => {
@@ -519,20 +519,20 @@ export function parseScript(data) {
   });
 }
 
-function buildPathMap(script) {
+function buildPathMap(script, base) {
   const { meta } = script;
-  const base = script.custom.lastInstallURL;
-  const pathMap = {};
-  [
+  const baseUrl = base || script.custom.lastInstallURL;
+  const pathMap = baseUrl ? [
     ...meta.require,
     ...Object.values(meta.resources),
-    isRemote(meta.icon) && meta.icon,
-  ].forEach(key => {
+    meta.icon,
+  ].reduce((map, key) => {
     if (key) {
-      const fullUrl = getFullUrl(key, base);
-      if (fullUrl !== key) pathMap[key] = fullUrl;
+      const fullUrl = getFullUrl(key, baseUrl);
+      if (fullUrl !== key) map[key] = fullUrl;
     }
-  });
+    return map;
+  }, {}) : {};
   script.custom.pathMap = pathMap;
   return pathMap;
 }