فهرست منبع

feat: 移除crypto依赖

zhangjie 1 سال پیش
والد
کامیت
09b963ef9a
5فایلهای تغییر یافته به همراه168 افزوده شده و 145 حذف شده
  1. 131 129
      README.md
  2. 4 4
      package.json
  3. 5 7
      src/plugins/imageUpload.js
  4. 23 0
      src/plugins/md5.js
  5. 5 5
      yarn.lock

+ 131 - 129
README.md

@@ -1,129 +1,131 @@
-# paper-library-client 试卷电子化采集端系统
-
-## 项目操作
-
-#### 项目安装
-
-```
-yarn install
-```
-
-#### 开发模式
-
-```
-yarn start
-```
-
-#### 项目打包
-
-```
-yarn run electron:build
-```
-
-#### lint 项目文件,并修正格式
-
-```
-yarn run lint
-```
-
-### 自定义配置
-
-- See [Configuration Reference](https://cli.vuejs.org/config/).
-- See [Vue CLI Plugin Electron Builder](https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/guide.html).
-- See [electron-builder Common Configuration](https://www.electron.build/configuration/configuration).
-
-## 系统开发目录说明
-
-- 开发目录:`当前代码目录`
-- 开发运行环境目录:`${开发目录}/node_modules/electron/dist/`
-- 正式运行环境目录:
-  - window: `C:~\AppData\Local\Programs\{系统名称}\`
-
-## 关于使用第三方工具的处理办法
-
-**所有第三方工具统一存放在根目录`extra`文件夹中**
-
-- 设置文件`vue.config.js`
-
-> [配置 api](https://www.electron.build/configuration/contents#extrafiles)
-
-```js
-// config中新增如下配置
-pluginOptions: {
-  electronBuilder: {
-    builderOptions: {
-      extraFiles: ["extra/**"]
-    }
-  }
-},
-```
-
-- 设置`plugins/env.js`
-
-```js
-// 运行系统的根目录
-const homePath = path.dirname(process.execPath);
-// 开放环境中,使用开发代码的根目录;正式包中,使用运行系统的根目录。
-const extraPath =
-  process.env.NODE_ENV === "production"
-    ? path.join(homePath, "extra")
-    : path.join(__static, "../extra");
-```
-
-## 配置打包参数(可选)
-
-```json
-{
-  "pluginOptions": {
-    "electronBuilder": {
-      "builderOptions": {
-        "appId": "com.example.app",
-        "productName": "aDemo", // 项目名,也是生成的安装文件名,即aDemo.exe
-        "copyright": "Copyright © 2020", //版权信息
-        "directories": {
-          "output": "./dist" //输出文件路径
-        },
-        "win": {
-          // win相关配置
-          "icon": "./shanqis.ico", // 图标,当前图标在根目录下,注意这里有两个坑
-          "target": [
-            {
-              "target": "nsis", // 利用nsis制作安装程序
-              "arch": [
-                "x64" // 64位
-              ]
-            }
-          ]
-        },
-        "nsis": {
-          "oneClick": false, // 是否一键安装
-          "allowElevation": true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。
-          "allowToChangeInstallationDirectory": true, // 允许修改安装目录
-          "installerIcon": "./shanqis.ico", // 安装图标
-          "uninstallerIcon": "./shanqis.ico", //卸载图标
-          "installerHeaderIcon": "./shanqis.ico", // 安装时头部图标
-          "createDesktopShortcut": true, // 创建桌面图标
-          "createStartMenuShortcut": true, // 创建开始菜单图标
-          "shortcutName": "demo" // 图标名称
-        }
-      }
-    }
-  }
-}
-```
-
-## config.json 配置说明
-
-- 根目录下会有一个`config.sample.json`文件,当需要设置配置参数时,可以复制一份,保存为`config.json`文件。
-- 系统内部预设了一组 config 参数,当根目录`config.json`文件中的参数有缺失时,默认使用预设 config 参数。
-- `input`默认为`/stores/in/`
-
-## postinstall
-
-- 32/64 切换,`"postinstall": "electron-builder install-app-deps --arch=ia32"`
-
-- npm config set registry "https://registry.npm.taobao.org/"
-- npm config set ELECTRON_MIRROR "https://npmmirror.com/mirrors/electron/"
-- npm config set ELECTRON_CUSTOM_DIR "v{{ version }}"
-
-* ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ yarn install
+# paper-library-client 试卷电子化采集端系统
+
+## 项目操作
+
+#### 项目安装
+
+```
+yarn install
+```
+
+#### 开发模式
+
+```
+yarn start
+```
+
+#### 项目打包
+
+```
+yarn run electron:build
+```
+
+#### lint 项目文件,并修正格式
+
+```
+yarn run lint
+```
+
+### 自定义配置
+
+- See [Configuration Reference](https://cli.vuejs.org/config/).
+- See [Vue CLI Plugin Electron Builder](https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/guide.html).
+- See [electron-builder Common Configuration](https://www.electron.build/configuration/configuration).
+
+## 系统开发目录说明
+
+- 开发目录:`当前代码目录`
+- 开发运行环境目录:`${开发目录}/node_modules/electron/dist/`
+- 正式运行环境目录:
+  - window: `C:~\AppData\Local\Programs\{系统名称}\`
+
+## 关于使用第三方工具的处理办法
+
+**所有第三方工具统一存放在根目录`extra`文件夹中**
+
+- 设置文件`vue.config.js`
+
+> [配置 api](https://www.electron.build/configuration/contents#extrafiles)
+
+```js
+// config中新增如下配置
+pluginOptions: {
+  electronBuilder: {
+    builderOptions: {
+      extraFiles: ["extra/**"]
+    }
+  }
+},
+```
+
+- 设置`plugins/env.js`
+
+```js
+// 运行系统的根目录
+const homePath = path.dirname(process.execPath);
+// 开放环境中,使用开发代码的根目录;正式包中,使用运行系统的根目录。
+const extraPath =
+  process.env.NODE_ENV === "production"
+    ? path.join(homePath, "extra")
+    : path.join(__static, "../extra");
+```
+
+## 配置打包参数(可选)
+
+```json
+{
+  "pluginOptions": {
+    "electronBuilder": {
+      "builderOptions": {
+        "appId": "com.example.app",
+        "productName": "aDemo", // 项目名,也是生成的安装文件名,即aDemo.exe
+        "copyright": "Copyright © 2020", //版权信息
+        "directories": {
+          "output": "./dist" //输出文件路径
+        },
+        "win": {
+          // win相关配置
+          "icon": "./shanqis.ico", // 图标,当前图标在根目录下,注意这里有两个坑
+          "target": [
+            {
+              "target": "nsis", // 利用nsis制作安装程序
+              "arch": [
+                "x64" // 64位
+              ]
+            }
+          ]
+        },
+        "nsis": {
+          "oneClick": false, // 是否一键安装
+          "allowElevation": true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。
+          "allowToChangeInstallationDirectory": true, // 允许修改安装目录
+          "installerIcon": "./shanqis.ico", // 安装图标
+          "uninstallerIcon": "./shanqis.ico", //卸载图标
+          "installerHeaderIcon": "./shanqis.ico", // 安装时头部图标
+          "createDesktopShortcut": true, // 创建桌面图标
+          "createStartMenuShortcut": true, // 创建开始菜单图标
+          "shortcutName": "demo" // 图标名称
+        }
+      }
+    }
+  }
+}
+```
+
+## config.json 配置说明
+
+- 根目录下会有一个`config.sample.json`文件,当需要设置配置参数时,可以复制一份,保存为`config.json`文件。
+- 系统内部预设了一组 config 参数,当根目录`config.json`文件中的参数有缺失时,默认使用预设 config 参数。
+- `input`默认为`/stores/in/`
+
+## postinstall
+
+- 32/64 切换,`"postinstall": "electron-builder install-app-deps --arch=ia32"`
+
+- npm config set registry "https://registry.npm.taobao.org/"
+- npm config set ELECTRON_MIRROR "https://npmmirror.com/mirrors/electron/"
+- npm config set ELECTRON_CUSTOM_DIR "v{{ version }}"
+
+* ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ yarn install
+
+- 临时禁用 post install: `--ingore-scripts`

+ 4 - 4
package.json

@@ -18,12 +18,12 @@
     "axios": "^0.19.2",
     "core-js": "^3.6.4",
     "cropperjs": "^1.5.1",
-    "crypto": "^1.0.1",
     "crypto-js": "^4.0.0",
     "deepmerge": "^4.2.2",
     "element-ui": "^2.14.1",
     "gm": "^1.23.1",
     "imagemagick": "^0.1.3",
+    "js-md5": "^0.8.3",
     "log4js": "^6.3.0",
     "sqlite3": "^5.0.0",
     "vue": "^2.6.11",
@@ -48,8 +48,8 @@
     "prettier": "^2.4.1",
     "sass": "^1.32.7",
     "sass-loader": "^12.0.0",
-    "vue-template-compiler": "^2.6.14",
-    "vue-cli-plugin-electron-builder": "~2.1.1"
+    "vue-cli-plugin-electron-builder": "~2.1.1",
+    "vue-template-compiler": "^2.6.14"
   },
   "gitHooks": {
     "pre-commit": "lint-staged"
@@ -60,4 +60,4 @@
       "git add"
     ]
   }
-}
+}

+ 5 - 7
src/plugins/imageUpload.js

@@ -1,8 +1,8 @@
 const fs = window.nodeRequire("fs");
 const path = window.nodeRequire("path");
-const crypto = window.require("crypto");
 import { uploadImage } from "../modules/client/api";
 import { Message } from "element-ui";
+import { MD5 } from "./md5";
 
 /**
  * 文件上传
@@ -12,12 +12,12 @@ function toUploadImg(options) {
   const formData = new FormData();
   // frontFile,frontMd5,versoFile,vers5,taskId
 
-  const { file: frontFile, md5: frontMd5 } = getFileAdnMd5(
+  const { file: frontFile, md5: frontMd5 } = getFileAndMd5(
     options.frontOriginImgPath
   );
   formData.append("frontMd5", frontMd5);
   formData.append("frontFile", frontFile);
-  const { file: versoFile, md5: versoMd5 } = getFileAdnMd5(
+  const { file: versoFile, md5: versoMd5 } = getFileAndMd5(
     options.versoOriginImgPath
   );
   formData.append("versoMd5", versoMd5);
@@ -36,11 +36,9 @@ function toUploadImg(options) {
   return uploadImage(options.isFormal, formData);
 }
 
-function getFileAdnMd5(filepath) {
+function getFileAndMd5(filepath) {
   const buffer = fs.readFileSync(filepath);
-  let fsHash = crypto.createHash("md5");
-  fsHash.update(buffer);
-  const md5 = fsHash.digest("hex");
+  const md5 = MD5(buffer);
   const file = new File([buffer], path.basename(filepath));
   return { file, md5 };
 }

+ 23 - 0
src/plugins/md5.js

@@ -0,0 +1,23 @@
+const md5 = require("js-md5");
+
+/**
+ *
+ * @param {any} str 字符串
+ */
+export const MD5 = (content) => {
+  return md5(content);
+};
+
+export const fileMD5 = (file) => {
+  return new Promise((resolve, reject) => {
+    const reader = new FileReader();
+    reader.onloadend = function () {
+      const arrayBuffer = reader.result;
+      resolve(md5(arrayBuffer));
+    };
+    reader.onerror = function (err) {
+      reject(err);
+    };
+    reader.readAsArrayBuffer(file);
+  });
+};

+ 5 - 5
yarn.lock

@@ -3728,11 +3728,6 @@ crypto-random-string@^2.0.0:
   resolved "https://registry.npmmirror.com/crypto-random-string/-/crypto-random-string-2.0.0.tgz#ef2a7a966ec11083388369baa02ebead229b30d5"
   integrity sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA==
 
-crypto@^1.0.1:
-  version "1.0.1"
-  resolved "https://registry.npmmirror.com/crypto/-/crypto-1.0.1.tgz#2af1b7cad8175d24c8a1b0778255794a21803037"
-  integrity sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==
-
 css-declaration-sorter@^6.3.1:
   version "6.4.0"
   resolved "https://registry.npmmirror.com/css-declaration-sorter/-/css-declaration-sorter-6.4.0.tgz#630618adc21724484b3e9505bce812def44000ad"
@@ -6175,6 +6170,11 @@ joi@^17.4.0:
     "@sideway/formula" "^3.0.1"
     "@sideway/pinpoint" "^2.0.0"
 
+js-md5@^0.8.3:
+  version "0.8.3"
+  resolved "https://registry.npmmirror.com/js-md5/-/js-md5-0.8.3.tgz#921bab7efa95bfc9d62b87ee08a57f8fe4305b69"
+  integrity sha512-qR0HB5uP6wCuRMrWPTrkMaev7MJZwJuuw4fnwAzRgP4J4/F8RwtodOKpGp4XpqsLBFzzgqIO42efFAyz2Et6KQ==
+
 js-message@1.0.7:
   version "1.0.7"
   resolved "https://registry.npmmirror.com/js-message/-/js-message-1.0.7.tgz#fbddd053c7a47021871bb8b2c95397cc17c20e47"