浏览代码

Use the url resolver to its full capabilities for vega.

Fixes #7047
Jason Grout 5 年之前
父节点
当前提交
5f7aef1d26
共有 2 个文件被更改,包括 10 次插入16 次删除
  1. 5 8
      packages/vega4-extension/src/index.ts
  2. 5 8
      packages/vega5-extension/src/index.ts

+ 5 - 8
packages/vega4-extension/src/index.ts

@@ -42,11 +42,6 @@ export const VEGA_MIME_TYPE = 'application/vnd.vega.v4+json';
  */
 export const VEGALITE_MIME_TYPE = 'application/vnd.vegalite.v2+json';
 
-/**
- * A regex to test for a protocol in a URI.
- */
-const protocolRegex = /^[A-Za-z]:/;
-
 /**
  * A widget for rendering Vega or Vega-Lite data, for usage with rendermime.
  */
@@ -97,9 +92,11 @@ export class RenderedVega extends Widget implements IRenderMime.IRenderer {
     });
 
     const sanitize = async (uri: string, options: any) => {
-      // If the uri is a path, get the download URI
-      if (!protocolRegex.test(uri)) {
-        uri = await this._resolver.getDownloadUrl(uri);
+      // Use the resolver for any URIs it wants to handle
+      const resolver = this._resolver;
+      if (resolver.isLocal(uri)) {
+        const absPath = await resolver.resolveUrl(uri);
+        uri = await resolver.getDownloadUrl(absPath);
       }
       return loader.sanitize(uri, options);
     };

+ 5 - 8
packages/vega5-extension/src/index.ts

@@ -42,11 +42,6 @@ export const VEGA_MIME_TYPE = 'application/vnd.vega.v5+json';
  */
 export const VEGALITE_MIME_TYPE = 'application/vnd.vegalite.v3+json';
 
-/**
- * A regex to test for a protocol in a URI.
- */
-const protocolRegex = /^[A-Za-z]:/;
-
 /**
  * A widget for rendering Vega or Vega-Lite data, for usage with rendermime.
  */
@@ -96,9 +91,11 @@ export class RenderedVega extends Widget implements IRenderMime.IRenderer {
       http: { credentials: 'same-origin' }
     });
     const sanitize = async (uri: string, options: any) => {
-      // If the uri is a path, get the download URI
-      if (!protocolRegex.test(uri)) {
-        uri = await this._resolver.getDownloadUrl(uri);
+      // Use the resolver for any URIs it wants to handle
+      const resolver = this._resolver;
+      if (resolver.isLocal(uri)) {
+        const absPath = await resolver.resolveUrl(uri);
+        uri = await resolver.getDownloadUrl(absPath);
       }
       return loader.sanitize(uri, options);
     };