1 | const findData = await Assets.findOne({ |
为 Electron 编译安装 Sqlite3
sqlite3 就不必多介绍了,讲一下今天踩的几个坑和解决方案
https://github.com/TryGhost/node-sqlite3
Electron 中使用 sqlite3
最小安装用例,package.json
1 | { |
直接运行 npm i
或者 yarn
安装依赖
非常好用的自己命令行编译的方法
方法一:官方的安装方法
--target=18.1.0
中 18.1.0
改成自己的 Electron
版本号
1 | npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=18.1.0 --dist-url=https://electronjs.org/headers |
方法二,先下载,后编译
1 | npm install node-gyp -g |
之所以加上 --ignore-scripts
,是因为 sqlite3
模块在 package.json
文件中写了下载时自动执行编译的脚本,如下:
1 | "scripts": { |
方法三,参数更全,自己配置 node-gyp
执行脚本路径等,具体参数需要看 node-gyp
的文档
1 | "/opt/homebrew/Cellar/node/17.5.0/bin/node" "/Users/username/Documents/Temp/sqlite3/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/username/Documents/Temp/sqlite3/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/Users/username/Documents/Temp/sqlite3/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=6" "--node_napi_label=napi-v6" |
踩坑及解决方案
NodeJS 17 版本问题
头铁使用最新版本 NodeJS v17.x 时,sqlite3 安装失败,报错:
1 | gyp: name 'openssl_fips' is not defined while evaluating condition 'openssl_fips != ""' in binding.gyp while trying to load binding.gyp |
见 https://github.com/nodejs/node-gyp/issues/2534
官方说法是 Nodejs 17 版本对 openssl_fips 不太支持,或者说有复写操作。
https://github.com/nodejs/node-gyp/issues/2534#issuecomment-976089582
解决方法如下
https://github.com/nodejs/node-gyp/issues/2543#issuecomment-1072104626
node-gyp
在本地安装最新的:
1 | npm install -d node-gyp@latest |
在 binding.gyp
中,添加(在顶部):
1 | { |
但是我认为最好的办法是降回正式 16.x
版本
Homebrew 问题
如果你用 Homebrew
安装了 Nodejs
,那么编译的时候参数会有所变化,多出一些参数
1 | "/opt/homebrew/Cellar/node/17.5.0/bin/node" "/opt/homebrew/bin/npm" "install" "sqlite3" "--build-from-source" "--sqlite_libname=sqlcipher" "--sqlite=/opt/homebrew" "--runtime=electron" "--target=18.1.0" "--dist-url=https://electronjs.org/headers" |
会多出一个 "--sqlite=/opt/homebrew"
的参数,而你电脑上没装 sqlite3
就会产生报错导致编译失败。
解决方案,Homebrew
或者 brew
卸载 Nodejs
,用官方的 Nodejs
安装包重新安装
其他
Mac 卸载 Nodejs
编译 Electron sqlite3
- https://juejin.cn/post/7074571022770372639
- https://stackoverflow.com/questions/38716594/electron-app-cant-find-sqlite3-module
Mac 卸载 Python
NestJS 调试
Js 判断是否Url的正则
1 | function isValidHttpUrl(string) { |
1 | function validURL(str) { |
JS 判断字符串是否为 HTML
Js 反转义实现与研究
问题
后端对提交的数据进行了一些转义操作,比如 <p><b>123&456</b></p>
这样的,会被转义成 <p><b>123&456</b></p>
然后前端请求数据时,这些数据需要反转义一下
解决
这是我目前用到的,不必担心性能问题,见后面的研究部分。
1 | // 反转义 bug@& 这样的字符 |
NestJS 上传文件
问题
NestJS 接收单个文件的上传和批量多个文件上传,及上传文件添加额外参数
解决
1 | import { |
参考文章
- https://docs.nestjs.com/techniques/file-upload
- https://www.joshmorony.com/handling-multiple-file-uploads-with-nest-js/
- https://notiz.dev/blog/type-safe-file-uploads
- https://eliteionic.com/tutorials/uploading-files-to-a-nest-js-backend/
- https://gabrieltanner.org/blog/nestjs-file-uploading-using-multer
Tensorflow 使用笔记
想做一个对象检测,和自己训练模型,目前处于查资料状态,还未开始。
- https://www.wenyanet.com/opensource/zh/5ff05254cb52772b182b278b.html
- https://www.tensorflow.org/js/tutorials
- https://www.tensorflow.org/js/tutorials/setup
- https://www.tensorflow.org/js/guide/train_models
- https://www.analyticsvidhya.com/blog/2021/12/custom-object-detection-on-the-browser-using-tensorflow-js/
- https://www.tensorflow.org/js/tutorials/conversion/import_saved_model
JS 视频播放事件
JS 获取视频和图片加载状态
问题
搜集所有的图片及视频的加载状态
解决
1 | let imageList = document.querySelectorAll('#q-editor img'); |
参考文章
图片状态
- https://stackoverflow.com/questions/14218607/javascript-loading-progress-of-an-image
- https://stackoverflow.com/questions/14218607/javascript-loading-progress-of-an-image/22593907#22593907
- https://segmentfault.com/q/1010000011223160
- http://www.frontopen.com/2614.html
- https://stackoverflow.com/questions/11071314/javascript-execute-after-all-images-have-loaded
- https://stackoverflow.com/questions/4494437/determine-when-image-finished-loading-with-javascript-or-jquery
- https://stackoverflow.com/questions/263359/how-can-i-determine-if-an-image-has-loaded-using-javascript-jquery
视频状态