当前位置: 首页 > news >正文

网站单页站群如何做推广

网站单页站群,如何做推广,阴阳师网站怎么做,2018做网站的视频electronvue3写了一个小项目,实现了一个文件下载功能 存在的问题 打包后,应用下载文件崩溃代码 // 渲染进程window.electron.ipcRenderer.invoke(save-file, {path: r.filePath,fileurl: previewUrl,}).then(response > {console.log(response ----…

electron+vue3写了一个小项目,实现了一个文件下载功能

存在的问题

	打包后,应用下载文件崩溃

代码

// 渲染进程window.electron.ipcRenderer.invoke('save-file', {'path': r.filePath,'fileurl': previewUrl,}).then(response => {console.log('response --------------');console.log(response);})// 主进程
ipcMain.handle('save-file', (event, args) => {// process.crash()try {// 下载保存文件console.log('axios args.fileurl ------------');console.log(args.fileurl);return downloadFile(args.fileurl, args.path)} catch (error) {console.log('error ---------------------------')console.log(error)return 'save-file 出错了: \n' + error.toString()}
});// 工具文件
import axios from 'axios'
import fs from 'fs/promises'export function downloadFile(downloadUrl, downloadPath) {try {return axios.get(downloadUrl, {method: 'GET',headers: {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36","Referer": downloadUrl,},responseType: 'arraybuffer'}).then(res => {console.log('下载成功')return fs.writeFile(downloadPath, res.data, "binary").then(r => {console.log('保存成功')return fs.stat(downloadPath)});}).catch(e => {console.log('e ------------------')console.log(e)return e});} catch (error) {console.log('error ---------------------------')console.log(error)return 'downloadFile 出错了: \n' + error.toString()}
}

解决思路

首先,要复现,我测试了自己的笔记本电脑,双系统都没问题,没办法复现这个bug,但是测试那边两台电脑都能复现,测试是在外地!我只好又找了一台闲置电脑,还好复现出来了,否则只能回家试试自己的电脑了

第二,找到问题所在,打包后 console.log 就看不到了,我想办法记录日志,看了官方的crashReporter,还有不少人推荐,我正好全栈,就搞了个接口接收日志,但是没有任何报错。后来试了electron-log,记录在用户本地,真香,简单好用,以后有需要直接搞个接口上传log文件就好了!还是没报错!但是我锁定了有问题的那一行代码,就是 axios.get(downloadUrl, { 这里崩溃的!

第三,想办法换掉axios!试了第三方electron下载库,electron-download、electron-dl、都很难用,文档少,搜索结果更少,自己摸索半天也没跑起来,继续换electron-download-manage,但是这个东西调用很麻烦!换request下载,和axios比较像,还是不行!我觉得我的方向可能错了,灵机一动,把axios下载放在渲染进程里面,下载好的数据传递给主进程!好了!

代码

// 渲染进程axios.get(previewUrl, {method: 'GET',responseType: 'arraybuffer'}).then(res => {console.log('下载成功')console.log('下载成功')console.log('下载成功')console.log(typeof res.data)window.electron.ipcRenderer.invoke('save-file', {'data': res.data,'path': r.filePath,}).then(response => {console.log('response --------------');console.log(response);})// 主进程ipcMain.handle('save-file', (event, args) => {try {log.info('event, args ------------');log.info(event, args);// 保存文件return saveFile(args.data, args.path)} catch (error) {log.info('error ---------------------------')log.info(error)return 'save-file 出错了: \n' + error.toString()}
});// 工具js
import fs from 'fs/promises'
import log from 'electron-log'
import { Buffer } from 'buffer'export function saveFile(data, downloadPath) {log.info('saveFile ----------------------- 0')try {log.info('saveFile ----------------------- 1')return fs.writeFile(downloadPath, Buffer.from(data), "binary").then(r => {log.info('保存成功')return fs.stat(downloadPath)});} catch (error) {log.info('saveFile ----------------------- 3')log.info('error ---------------------------')log.info(error)throw new Error('saveFile出错了:' + error.toString()) // 将错误包装成新的Error对象并抛出,让调用者知道发生了错误}
}

中间还发生了一个小插曲

Error occurred in handler for 'save-file': 
TypeError [ERR_INVALID_ARG_TYPE]: 
The "data" argument must be of type string or an instance of 
Buffer, TypedArray, or DataView. Received an instance of ArrayBuffer

所以才有了Buffer.from(data)
感谢文心一言,感谢我自己!

http://www.khdw.cn/news/24572.html

相关文章:

  • 智能建站平台z搜索引擎网站推广如何优化
  • web网站开发基本流程网站免费推广
  • 手机可以做网站服务器吗兰州网络推广优化怎样
  • wordpress临时关闭站点怎样推广品牌
  • 网站动态与静态百度指数代表什么
  • 新网站 蜘蛛企业老板培训课程
  • 安徽专业网站建设大全推荐广州seo网站多少钱
  • 企业网站管理的含义seo系统培训
  • 个人如何建立公司网站免费企业黄页查询官网
  • 网站建设注意优秀网页设计
  • 淘宝客网站怎样做seo公众号seo排名软件
  • 学做网站看书会了吗vivo应用商店
  • 做图赚钱的网站有哪些品牌网络营销策划书
  • 灵宝超市建设管理局信访网站明天上海封控16个区
  • 网站空间服务器必应搜索引擎网站
  • wordpress安装网站源码独立站seo是什么意思
  • 什么网站可以做电影投资百度广告联盟官网
  • 用微信微博网站来做睡眠经济指数基金
  • 网站做APP麻烦吗如何制作一个属于自己的网站
  • 无限动力营销型网站建设谷歌推广怎么样
  • 建设网站网站设计全球搜索引擎网站
  • 北京疫情为什么突然又严重了淘宝关键词优化
  • 新网站如何做百度收录百度指数批量
  • 西乡移动网站建设网络推广公司是干什么
  • 做网页去哪些网站找素材较好宁波seo优化外包公司
  • 上海市官方网站免费网站模板
  • 百度地图疫情实时动态优化什么建立生育支持政策体系
  • 做算命网站犯法吗seo的优点有哪些
  • 怎么搭建自己的网站卖货百度一下官方网址
  • 瀑布流网站模板手机系统优化软件