wasm 加密

This commit is contained in:
Jesse-Ma
2023-03-07 17:55:05 +08:00
parent 8242885c50
commit 25d9048506
5 changed files with 31 additions and 13 deletions

View File

@@ -21,8 +21,7 @@
"vue": "^2.7.14", "vue": "^2.7.14",
"vue-axios": "^3.5.2", "vue-axios": "^3.5.2",
"vue-i18n": "^8.28.2", "vue-i18n": "^8.28.2",
"vue-router": "^3.5.4", "vue-router": "^3.6.5"
"wasm-flate": "1.0.2-bundler"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.12.16", "@babel/core": "^7.12.16",

View File

@@ -26,7 +26,7 @@
</style> </style>
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.min.js" rel="stylesheet" <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.min.js" rel="stylesheet"
type="text/javascript"></script> type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-router@3.5.4/dist/vue-router.min.js" rel="stylesheet" <script src="https://cdn.jsdelivr.net/npm/vue-router@3.6.5/dist/vue-router.min.js" rel="stylesheet"
type="text/javascript"></script> type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/axios@0.27.2/dist/axios.min.js" rel="stylesheet" <script src="https://cdn.jsdelivr.net/npm/axios@0.27.2/dist/axios.min.js" rel="stylesheet"
type="text/javascript"></script> type="text/javascript"></script>
@@ -44,10 +44,19 @@
type="text/javascript"></script> type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.11/dist/clipboard.min.js" rel="stylesheet" <script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.11/dist/clipboard.min.js" rel="stylesheet"
type="text/javascript"></script> type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/wasm-flate@1.0.2-browser/wasm_flate.js" rel="stylesheet"
type="text/javascript"></script>
<script>
window.wasm_flate_bg_path = "https://cdn.jsdelivr.net/npm/wasm-flate@1.0.2-browser/wasm_flate_bg.wasm"
</script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/view-design@4.7.0/dist/styles/iview.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/view-design@4.7.0/dist/styles/iview.css">
<!--Global site tag(gtag.js)-Google Analytics--> <!--Global site tag(gtag.js)-Google Analytics-->
<!--
<script async src="https://www.googletagmanager.com/gtag/js?id=G-FPS9PD2DFF"></script> <script async src="https://www.googletagmanager.com/gtag/js?id=G-FPS9PD2DFF"></script>
<script>window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments) } gtag("js", new Date()); gtag("config", "G-FPS9PD2DFF");</script> <script>window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments) } gtag("js", new Date()); gtag("config", "G-FPS9PD2DFF");</script>
-->
</head> </head>
<body><noscript><strong>Please enable JavaScript to continue.</strong></noscript> <body><noscript><strong>Please enable JavaScript to continue.</strong></noscript>
@@ -58,6 +67,8 @@
if (!!window.ActiveXObject || "ActiveXObject" in window) { if (!!window.ActiveXObject || "ActiveXObject" in window) {
document.querySelector('#noie').style.display = 'block'; document.querySelector('#noie').style.display = 'block';
} }
</script> </script>
</body> </body>

View File

@@ -1,7 +1,8 @@
import CryptoJS from "crypto-js"; import CryptoJS from "crypto-js";
import pako from "pako"; import pako from "pako";
import {gzip_encode_raw,gzip_decode_raw} from 'wasm-flate'; //import {gzip_encode_raw,gzip_decode_raw} from 'wasm-flate';
const wasmFlate = window.wasm_bindgen;
/** /**
* @word 要加密的内容 * @word 要加密的内容
@@ -80,16 +81,18 @@ export function noteZip(text) {
} }
function zip(data){ function zip(data){
if(gzip_encode_raw){ if(wasmFlate.__wbindgen_wasm_module){
return gzip_encode_raw(data); return wasmFlate.gzip_encode_raw(data);
} }
return pako.gzip(data); return pako.gzip(data);
} }
function unzip(data){ function unzip(data){
if(gzip_decode_raw){ if(wasmFlate.__wbindgen_wasm_module){
return gzip_decode_raw(data); return wasmFlate.gzip_decode_raw(data);
} }
return pako.ungzip(data); return pako.ungzip(data);
} }

View File

@@ -295,6 +295,8 @@ export default {
this.bindCtrlAllEvent(); this.bindCtrlAllEvent();
this.bindToTopEvent(); this.bindToTopEvent();
window.wasm_bindgen(window.wasm_flate_bg_path);
}, },
mounted() { mounted() {
const myObserver = new ResizeObserver(entries => { const myObserver = new ResizeObserver(entries => {

View File

@@ -6,7 +6,10 @@ module.exports = defineConfig({
assetsDir: 'static', assetsDir: 'static',
productionSourceMap: false, productionSourceMap: false,
configureWebpack: (config) => { configureWebpack: (config) => {
config.experiments = { asyncWebAssembly: true,syncWebAssembly:true }
config.externals = { config.externals = {
'vue': 'Vue', 'vue': 'Vue',
@@ -20,8 +23,7 @@ module.exports = defineConfig({
"iview": 'ViewUI', "iview": 'ViewUI',
"file-saver": 'saveAs', "file-saver": 'saveAs',
"clipboard": "ClipboardJS", "clipboard": "ClipboardJS",
"vue-i18n": "VueI18n", "vue-i18n": "VueI18n"
}; };
// 为生产环境修改配置 // 为生产环境修改配置
@@ -44,7 +46,7 @@ module.exports = defineConfig({
new CompressionPlugin({ new CompressionPlugin({
algorithm: "gzip", // 使用gzip压缩 algorithm: "gzip", // 使用gzip压缩
test: /\.js$|\.html$|\.png$|\.jpg$|\.svg$|\.css$/, // 匹配文件名 test: /\.js$|\.html$|\.png$|\.jpg$|\.svg$|\.wasm$|\.css$/, // 匹配文件名
filename: "[path][base].gz[query]", // 压缩后的文件名(保持原文件名,后缀加.gz) filename: "[path][base].gz[query]", // 压缩后的文件名(保持原文件名,后缀加.gz)
minRatio: 1, // 压缩率小于1才会压缩 minRatio: 1, // 压缩率小于1才会压缩
threshold: 5120, // 对超过10k的数据压缩 threshold: 5120, // 对超过10k的数据压缩
@@ -63,7 +65,8 @@ module.exports = defineConfig({
devServer: { devServer: {
proxy: { proxy: {
"/note": { "/note": {
target: "http://127.0.0.1:10000/", // 后台接口域名 // target: "https://flagnote.com/", // 后台接口域名
target: "http://localhost:10000/", // 后台接口域名
secure: false, // 如果是https接口需要配置这个参数 secure: false, // 如果是https接口需要配置这个参数
changeOrigin: true, //是否跨域 changeOrigin: true, //是否跨域
pathRewrite: { pathRewrite: {