You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by wa...@apache.org on 2022/08/04 01:42:06 UTC

[echarts-examples] branch gh-pages updated: feat(editor): support uncompressed base64-encoded code

This is an automated email from the ASF dual-hosted git repository.

wangzx pushed a commit to branch gh-pages
in repository https://gitbox.apache.org/repos/asf/echarts-examples.git


The following commit(s) were added to refs/heads/gh-pages by this push:
     new a7e386ba feat(editor): support uncompressed base64-encoded code
a7e386ba is described below

commit a7e386bada35821e0c9e91fffccac10f63c5cbb8
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Thu Aug 4 09:40:51 2022 +0800

    feat(editor): support uncompressed base64-encoded code
---
 src/common/helper.js |  4 ++++
 src/common/store.js  | 16 ++++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/common/helper.js b/src/common/helper.js
index 7d43fb86..8b5a142b 100644
--- a/src/common/helper.js
+++ b/src/common/helper.js
@@ -120,3 +120,7 @@ export function isTrustedOpener() {
     );
   } catch {}
 }
+
+export function decodeBase64(str) {
+  return decodeURIComponent(escape(window.atob(str)));
+}
diff --git a/src/common/store.js b/src/common/store.js
index d9ce3c64..346e39aa 100644
--- a/src/common/store.js
+++ b/src/common/store.js
@@ -2,7 +2,12 @@
 import { URL_PARAMS } from '../common/config';
 import CHART_LIST from '../data/chart-list-data';
 import CHART_LIST_GL from '../data/chart-list-data-gl';
-import { compressStr, decompressStr, isTrustedOpener } from './helper';
+import {
+  compressStr,
+  decompressStr,
+  decodeBase64,
+  isTrustedOpener
+} from './helper';
 import { customAlphabet } from 'nanoid';
 
 const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 10);
@@ -109,11 +114,14 @@ export function loadExampleCode() {
   }
   return new Promise((resolve, reject) => {
     // ignore c if code is provided
-    // TODO support uncompressed base64 code like `code=xxxx&enc=base64`
-    if (URL_PARAMS.code) {
+    let code = URL_PARAMS.code;
+    if (code) {
       try {
         // PENDING fallback to `c` if the decompressed code is not available?
-        const code = decompressStr(URL_PARAMS.code);
+        code =
+          URL_PARAMS.enc === 'base64'
+            ? decodeBase64(code)
+            : decompressStr(code);
         // not considered as shared code if it's opened by echarts website like echarts-doc
         store.isSharedCode = !isTrustedOpener() && !!code;
         // clear the opener


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org