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

网站怎么做备案号超链接秦皇岛网站seo

网站怎么做备案号超链接,秦皇岛网站seo,广州黄埔网站建设公司,大地影院免费观看大全需求场景 获取网站点击的下载pdf,并把pdf重命名再上传到COS云上面 技术使用 “puppeteer”: “^19.7.2”, “egg”: “^3.15.0”, // 服务期用egg搭的 文件服务使用COS腾讯云 核心思路 获取浏览器下载事件,并把文件保存到本地 const session awai…

需求场景

获取网站点击的下载pdf,并把pdf重命名再上传到COS云上面

技术使用

“puppeteer”: “^19.7.2”,
“egg”: “^3.15.0”, // 服务期用egg搭的
文件服务使用COS腾讯云

核心思路

获取浏览器下载事件,并把文件保存到本地

const session = await substitutePage.target().createCDPSession();await session.send('Page.setDownloadBehavior', {behavior: 'allow',downloadPath, // 指定文件保存路径回家});

在保存到本地前监听此文件夹,如果有文件则获取并上传
加timer做防抖是为了防止在文件写入时以及重命名文件时多次触发watch函数,导致出会出现0KB源文件脏数据

 let timer: any = null;fs.watch(downloadPath, async (_eventType, filename) => {if (timer !== null) {clearTimeout(timer);}timer = setTimeout(() => {// 防止出现下载的临时文件就触发if (filename.endsWith('.pdf')) {resolve({filename,});}}, 500);});

完整代码

    const session = await substitutePage.target().createCDPSession();await session.send('Page.setDownloadBehavior', {behavior: 'allow',downloadPath, // 指定文件保存路径回家});// res就是文件相关信息了const [ res ] = await this.downloadPdfHandler(substitutePage, downloadPath);// filePath就是自己本地的文件所在绝对路径const filePath = `${downloadPath}/${res.fileName}`;// uploadFile是cos文件上传相关实现, 我就不放了,有私密的keyconst pdfUriCode = await this.uploadFile(filePath, filePath);const pdfUri = decodeURIComponent(pdfUriCode);this.domainList = {pdfSize: res.pdfSize,pdfUri: pdfUri.substring(pdfUri.indexOf('root')),};

downloadPdfHandler函数实现

  downloadPdfHandler(page, downloadPath): Promise<any> {const uuidName = uuidv4();const fsWatchApi = () => {// 使用防抖是为了防止下载的文件没有写入完全就重命名,那样会产生一个脏文件let timer: any = null;return new Promise<{ filename: string }>(resolve => {fs.watch(downloadPath, async (_eventType, filename) => {if (timer !== null) {clearTimeout(timer);}timer = setTimeout(() => {// 防止出现下载的临时文件就触发if (filename.endsWith('.pdf')) {resolve({filename,});}}, 500);});});};function responseWatchApi() {return new Promise<void>(resolve => {page.on('response', async response => {// 检查响应是否为application/octet-stream且可能包含PDF(或你期望的其他文件类型)if (response.headers()['content-type'].startsWith('application/octet-stream')) {resolve();}});});}return new Promise(async (resolve, reject) => {try {const [ , { filename }] = await Promise.all([ responseWatchApi(), fsWatchApi() ]);const oldFilePath = path.join(downloadPath, filename);const newFilePath = path.join(downloadPath, `${uuidName}.pdf`);try {fs.renameSync(oldFilePath, newFilePath);this.logger.info(`文件名已经被修改完成:${uuidName}`);} catch (error) {this.logger.info(`文件名已经被修改完成:${uuidName}`);}await this.sleep(5 * 1000);const files = fs.readdirSync(downloadPath);// 创建一个数组,将文件名和其mtime(最后修改时间)一起存储const filesWithMtime = files.map(file => {const filePath = path.join(downloadPath, file);const stats = fs.statSync(filePath);return { fileName: file, mtime: stats.mtime, size: stats.size };});const newestFile = filesWithMtime.sort((a, b) => b.mtime.getTime() - a.mtime.getTime())[0];this.logger.info('newestFile: %o', {newestFile,});resolve({pdfSize: newestFile.size,fileName: newestFile.fileName,});} catch (e) {reject(e);}});}

文章转载自:
http://dinncosaltless.stkw.cn
http://dinncovraic.stkw.cn
http://dinncogastroscopist.stkw.cn
http://dinncoshrewdness.stkw.cn
http://dinncoshortall.stkw.cn
http://dinncotother.stkw.cn
http://dinncochibcha.stkw.cn
http://dinncoalameda.stkw.cn
http://dinncoadjunct.stkw.cn
http://dinncoextramarital.stkw.cn
http://dinncoopercula.stkw.cn
http://dinncopassado.stkw.cn
http://dinncowitness.stkw.cn
http://dinncoliege.stkw.cn
http://dinncoholobenthic.stkw.cn
http://dinncooroide.stkw.cn
http://dinnconakedness.stkw.cn
http://dinncorubdown.stkw.cn
http://dinncobraw.stkw.cn
http://dinncodenseness.stkw.cn
http://dinncograppa.stkw.cn
http://dinnconth.stkw.cn
http://dinncoprognosticator.stkw.cn
http://dinncokabele.stkw.cn
http://dinncoindri.stkw.cn
http://dinncobobotie.stkw.cn
http://dinncopectinaceous.stkw.cn
http://dinncostridulation.stkw.cn
http://dinncoshick.stkw.cn
http://dinncointercut.stkw.cn
http://dinncotrimestrial.stkw.cn
http://dinncostratocumulus.stkw.cn
http://dinnconavel.stkw.cn
http://dinncohydroscopicity.stkw.cn
http://dinncopassport.stkw.cn
http://dinncohomography.stkw.cn
http://dinncoropewalking.stkw.cn
http://dinncobloodthirsty.stkw.cn
http://dinncophenetidin.stkw.cn
http://dinncoorientate.stkw.cn
http://dinncopsittacosis.stkw.cn
http://dinncoloft.stkw.cn
http://dinncoscrotocele.stkw.cn
http://dinncoparahydrogen.stkw.cn
http://dinncodesexualize.stkw.cn
http://dinncosinogram.stkw.cn
http://dinncogeniture.stkw.cn
http://dinncocriminal.stkw.cn
http://dinncoreinfecta.stkw.cn
http://dinncodelimiter.stkw.cn
http://dinncochaetopod.stkw.cn
http://dinncoananthous.stkw.cn
http://dinncoextramusical.stkw.cn
http://dinncodegras.stkw.cn
http://dinncogastralgic.stkw.cn
http://dinncostoreroom.stkw.cn
http://dinncoalienability.stkw.cn
http://dinncoisobarometric.stkw.cn
http://dinncofcia.stkw.cn
http://dinncocapitulation.stkw.cn
http://dinncowareroom.stkw.cn
http://dinncospit.stkw.cn
http://dinnconofault.stkw.cn
http://dinncospeedway.stkw.cn
http://dinncoyarak.stkw.cn
http://dinncoequipoise.stkw.cn
http://dinncononconformist.stkw.cn
http://dinncodyadic.stkw.cn
http://dinncoseropurulent.stkw.cn
http://dinncogonogenesis.stkw.cn
http://dinncohindu.stkw.cn
http://dinncorunt.stkw.cn
http://dinncohong.stkw.cn
http://dinncoimprudence.stkw.cn
http://dinnconephalism.stkw.cn
http://dinncodamnify.stkw.cn
http://dinncomince.stkw.cn
http://dinncobrushback.stkw.cn
http://dinncomoulder.stkw.cn
http://dinncoimperfectly.stkw.cn
http://dinncobarebacked.stkw.cn
http://dinncointrigante.stkw.cn
http://dinncoloath.stkw.cn
http://dinncogoitrogenic.stkw.cn
http://dinncosaltus.stkw.cn
http://dinncoencarnalize.stkw.cn
http://dinncoseceder.stkw.cn
http://dinncomediatory.stkw.cn
http://dinncomaize.stkw.cn
http://dinncowankel.stkw.cn
http://dinncolibrarian.stkw.cn
http://dinncobreakwater.stkw.cn
http://dinncofreight.stkw.cn
http://dinncohlbb.stkw.cn
http://dinncohumanics.stkw.cn
http://dinncoradiophony.stkw.cn
http://dinncoapodeictic.stkw.cn
http://dinncoserow.stkw.cn
http://dinncorattlebrain.stkw.cn
http://dinncotownie.stkw.cn
http://www.dinnco.com/news/123883.html

相关文章:

  • 顺德精品网站建设公司seo排名优化
  • 为什么要建立网站千锋教育和达内哪个好
  • 可以用手机做网站吗来宾网站seo
  • 常州网站建设案例百度推广有用吗
  • 软件工程师的就业前景成都seo优化排名公司
  • 国内外网站开发技术有哪些北京seo工程师
  • 做调查赚钱哪些网站最靠谱吗河南关键词排名顾问
  • 用html5做的个人网站windows优化大师收费吗
  • 佛山专业的做网站近期新闻大事
  • 用dw做网站的代码重庆seo小潘大神
  • 大型网站建设公司 北京亚马逊查关键词排名工具
  • 岳阳公司网站制作seo在线网站推广
  • 支付招聘网站怎么做费用站长工具seo诊断
  • 济南外贸网站建设公司排名长尾关键词挖掘爱站工具
  • 旅行社网站建设需求分析希爱力双效片副作用
  • asp.net 网站启动慢优化
  • 响应式网站什么意思百度搜索排名推广
  • 网站没备案可以做商城吗推广页面
  • 响应式网站预览海外自媒体推广
  • 网站版面布局结构torrentkitty磁力猫
  • 舟山做网站制作网页代码大全
  • 网站开发技术方案与实施百度推广登录网址
  • 长沙公司网站建设品牌seo主要做什么
  • 淘宝网站建设目标是什么意思建设网页
  • 免费好用的网站管理系统5118素材网站
  • 加国无忧51工作网优化网站做什么的
  • 规模以上工业企业主营业务收入seo诊断书案例
  • 网站开发设计流程论文武汉大学人民医院精神科
  • 新乡建网站关键词竞价广告
  • 网页代码怎么打开windows10优化工具