Authored by lzhy

Merge branch 'master' into feature/optimize20200528

* master:
  chore(*): npm version
  fix(电子刊): 电子刊资源解析
  fix(电子刊): 自定义购买数量bug修复
  fix(电子刊): 购买数量获取失败
  chore(*): npm verison
@@ -24,6 +24,7 @@ const indexModel = require('../models/index'); @@ -24,6 +24,7 @@ const indexModel = require('../models/index');
24 const index = async function(req, res, next) { 24 const index = async function(req, res, next) {
25 let {e_id, token = ''} = req.query; 25 let {e_id, token = ''} = req.query;
26 let isApp = req.yoho.isApp; 26 let isApp = req.yoho.isApp;
  27 +
27 let userAgent = req.get('User-Agent'); 28 let userAgent = req.get('User-Agent');
28 29
29 let isYohobuy = /yohobuy/i.test(userAgent); 30 let isYohobuy = /yohobuy/i.test(userAgent);
@@ -76,7 +77,6 @@ const index = async function(req, res, next) { @@ -76,7 +77,6 @@ const index = async function(req, res, next) {
76 let code = magazineInfo.data.code; 77 let code = magazineInfo.data.code;
77 78
78 // 4000:获取成功 4001: 未购买该电子刊 4002:未获取到电子刊 4003:电子刊已删除 79 // 4000:获取成功 4001: 未购买该电子刊 4002:未获取到电子刊 4003:电子刊已删除
79 -  
80 if (code === 4000) { 80 if (code === 4000) {
81 let url = magazineInfo.data.link; 81 let url = magazineInfo.data.link;
82 82
@@ -96,21 +96,35 @@ const index = async function(req, res, next) { @@ -96,21 +96,35 @@ const index = async function(req, res, next) {
96 96
97 // HYPE生成的html有其固定格式的div id,此处获取的也是这个hype创建时的名称,此名称对应插入的js 97 // HYPE生成的html有其固定格式的div id,此处获取的也是这个hype创建时的名称,此名称对应插入的js
98 if (idMatch && idMatch.length >= 2) { 98 if (idMatch && idMatch.length >= 2) {
99 - let name = idMatch[1];  
100 - let id = `${name}_hype_container`;  
101 - let script = $(`#${id}`).html(); 99 + let head = $('head').html();
  100 +
  101 + head = head.replace(/href="(.*)"/g, function(match, p1) {
  102 + if (p1.indexOf('//') > -1) {
  103 + return p1;
  104 + }
  105 + const src = p1.indexOf('.') > -1 ? p1.slice(2) : p1;
  106 +
  107 + return 'href=' + resourceUrl + src;
  108 + });
  109 +
  110 + $('head').html(head);
  111 +
  112 + let htmlString = $.html();
102 113
103 - let scriptSrc = script.match(/src="(.*)"/); 114 + let hasHypeScript = /_hype_generated_script/.test(htmlString);
104 115
105 // 获取到对应div里面的script的src,并替换成带有域名的地址,可以让所有图片地址指向js对应的域名 116 // 获取到对应div里面的script的src,并替换成带有域名的地址,可以让所有图片地址指向js对应的域名
106 - if (scriptSrc && scriptSrc.length >= 2) {  
107 - let src = scriptSrc[1];  
108 - let newScript = '<script type="text/javascript" charset="utf-8" src="' +  
109 - resourceUrl + src + '">'; 117 + if (hasHypeScript) {
  118 + htmlString = htmlString.replace(/src="(.*)"/g, function(match, p1) {
  119 + if (p1.indexOf('//') > -1) {
  120 + return p1;
  121 + }
  122 + const src = p1.indexOf('.') > -1 ? p1.slice(2) : p1;
110 123
111 - $(`#${id}`).html(newScript); 124 + return 'src=' + resourceUrl + src;
  125 + });
112 126
113 - return res.send($.html()); // 输出修改过的html 127 + return res.send(htmlString); // 输出修改过的html
114 } else { 128 } else {
115 return renderErroPage({msg: NO_HYPE_SCRIPT}); 129 return renderErroPage({msg: NO_HYPE_SCRIPT});
116 } 130 }
@@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
17 <p class="m-title">{{title}}</p> 17 <p class="m-title">{{title}}</p>
18 18
19 <div class="magazine-info"> 19 <div class="magazine-info">
20 - <div class="m-order to-download">如何订阅 20 + <div class="m-order to-download">如何阅读
21 <i class="iconfont">&#xe614;</i> 21 <i class="iconfont">&#xe614;</i>
22 </div> 22 </div>
23 {{#if subcribeCount }} 23 {{#if subcribeCount }}
1 { 1 {
2 "name": "yohobuywap-node", 2 "name": "yohobuywap-node",
3 - "version": "6.13.9", 3 + "version": "6.13.12",
4 "private": true, 4 "private": true,
5 "description": "A New Yohobuy Project With Express", 5 "description": "A New Yohobuy Project With Express",
6 "repository": { 6 "repository": {
@@ -24,7 +24,7 @@ $('.choose-list').on('click', '.choose-item', function(e) { @@ -24,7 +24,7 @@ $('.choose-list').on('click', '.choose-item', function(e) {
24 let data = $elm.data(); 24 let data = $elm.data();
25 25
26 $totalPrice.text(data.price); 26 $totalPrice.text(data.price);
27 - buyNumber = data.num; 27 + buyNumber = data.number;
28 } 28 }
29 29
30 $activeItem.length && $activeItem.removeClass('active'); 30 $activeItem.length && $activeItem.removeClass('active');
@@ -41,6 +41,7 @@ $customNumInput.on('input', function() { @@ -41,6 +41,7 @@ $customNumInput.on('input', function() {
41 if (val !== handelVal) { 41 if (val !== handelVal) {
42 $(this).val(handelVal); 42 $(this).val(handelVal);
43 } 43 }
  44 + buyNumber = +handelVal;
44 }).on('change', function() { 45 }).on('change', function() {
45 let val = $(this).val(); 46 let val = $(this).val();
46 47