|
@@ -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
|
}
|