From ebce488a0e4f1e250f17ea6b628dd0507b0d88f6 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Fri, 8 Apr 2022 21:08:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=BD=91=E9=A1=B5=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pnpm-lock.yaml | 23 ++++++++-- web/plugins/com.msgbyte.webview/package.json | 5 ++- .../src/group/GroupCustomWebPanelRender.tsx | 43 +++++++++++++++++++ .../src/group/GroupWebPanelRender.tsx | 19 ++++++++ web/plugins/com.msgbyte.webview/src/index.tsx | 31 ++++++------- .../com.msgbyte.webview/src/translate.ts | 8 ++++ web/src/components/Loadable.tsx | 43 ++++++++++++++++--- 7 files changed, 146 insertions(+), 26 deletions(-) create mode 100644 web/plugins/com.msgbyte.webview/src/group/GroupCustomWebPanelRender.tsx create mode 100644 web/plugins/com.msgbyte.webview/src/group/GroupWebPanelRender.tsx diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f02714ff..19e48dec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -379,7 +379,12 @@ importers: specifiers: {} web/plugins/com.msgbyte.webview: - specifiers: {} + specifiers: + js-base64: ^3.7.2 + xss: ^1.0.11 + dependencies: + js-base64: 3.7.2 + xss: 1.0.11 packages: @@ -3897,7 +3902,6 @@ packages: /commander/2.20.3: resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} - dev: true /commander/6.2.1: resolution: {integrity: sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npm.taobao.org/commander/download/commander-6.2.1.tgz} @@ -4134,6 +4138,10 @@ packages: engines: {node: '>= 6'} dev: true + /cssfilter/0.0.10: + resolution: {integrity: sha512-FAaLDaplstoRsDR8XGYH51znUN0UY7nMc6Z9/fvE8EXGwvJE9hu7W2vHwx1+bd6gCYnln9nLbzxFTrcO9YQDZw==} + dev: false + /cssnano-preset-default/4.0.8: resolution: {integrity: sha1-kgYisfwelaNOiDggPxOXpQTy0/8=, registry: https://registry.npm.taobao.org/, tarball: https://registry.npm.taobao.org/cssnano-preset-default/download/cssnano-preset-default-4.0.8.tgz} engines: {node: '>=6.9.0'} @@ -6102,7 +6110,7 @@ packages: engines: {node: '>=10'} /js-base64/3.7.2: - resolution: {integrity: sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ==, registry: https://registry.npm.taobao.org/, tarball: js-base64/download/js-base64-3.7.2.tgz} + resolution: {integrity: sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ==} dev: false /js-sha3/0.8.0: @@ -10166,6 +10174,15 @@ packages: engines: {node: '>=0.4.0'} dev: false + /xss/1.0.11: + resolution: {integrity: sha512-EimjrjThZeK2MO7WKR9mN5ZC1CSqivSl55wvUK5EtU6acf0rzEE1pN+9ZDrFXJ82BRp3JL38pPE6S4o/rpp1zQ==} + engines: {node: '>= 0.10.0'} + hasBin: true + dependencies: + commander: 2.20.3 + cssfilter: 0.0.10 + dev: false + /xtend/4.0.2: resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} engines: {node: '>=0.4'} diff --git a/web/plugins/com.msgbyte.webview/package.json b/web/plugins/com.msgbyte.webview/package.json index f8e54e87..b564ee35 100644 --- a/web/plugins/com.msgbyte.webview/package.json +++ b/web/plugins/com.msgbyte.webview/package.json @@ -3,5 +3,8 @@ "main": "src/index.tsx", "version": "0.0.0", "private": true, - "dependencies": {} + "dependencies": { + "js-base64": "^3.7.2", + "xss": "^1.0.11" + } } diff --git a/web/plugins/com.msgbyte.webview/src/group/GroupCustomWebPanelRender.tsx b/web/plugins/com.msgbyte.webview/src/group/GroupCustomWebPanelRender.tsx new file mode 100644 index 00000000..33b56ca3 --- /dev/null +++ b/web/plugins/com.msgbyte.webview/src/group/GroupCustomWebPanelRender.tsx @@ -0,0 +1,43 @@ +import React, { useMemo } from 'react'; +import { encode } from 'js-base64'; +import { isValidStr } from '@capital/common'; +import { Translate } from '../translate'; +import { FilterXSS, getDefaultWhiteList } from 'xss'; +import _mapValues from 'lodash/mapValues'; + +const xss = new FilterXSS({ + // 允许style存在 + whiteList: { + ..._mapValues(getDefaultWhiteList(), (v) => [...v, 'style']), + style: [], + }, + css: false, +}); + +const GroupCustomWebPanelRender: React.FC<{ panelInfo: any }> = (props) => { + const panelInfo = props.panelInfo; + + if (!panelInfo) { + return
{Translate.notfound}
; + } + + const html = panelInfo?.meta?.html; + const src = useMemo(() => { + if (isValidStr(html)) { + try { + return `data:text/html;charset=utf8;base64,${encode( + xss.process(html) + )}`; + } catch (e) { + return undefined; + } + } else { + return undefined; + } + }, [html]); + + return