...
|
...
|
@@ -24,6 +24,7 @@ const indexModel = require('../models/index'); |
|
|
const index = async function(req, res, next) {
|
|
|
let {e_id, token = ''} = req.query;
|
|
|
let isApp = req.yoho.isApp;
|
|
|
|
|
|
let userAgent = req.get('User-Agent');
|
|
|
|
|
|
let isYohobuy = /yohobuy/i.test(userAgent);
|
...
|
...
|
@@ -76,7 +77,6 @@ const index = async function(req, res, next) { |
|
|
let code = magazineInfo.data.code;
|
|
|
|
|
|
// 4000:获取成功 4001: 未购买该电子刊 4002:未获取到电子刊 4003:电子刊已删除
|
|
|
|
|
|
if (code === 4000) {
|
|
|
let url = magazineInfo.data.link;
|
|
|
|
...
|
...
|
@@ -96,21 +96,35 @@ const index = async function(req, res, next) { |
|
|
|
|
|
// HYPE生成的html有其固定格式的div id,此处获取的也是这个hype创建时的名称,此名称对应插入的js
|
|
|
if (idMatch && idMatch.length >= 2) {
|
|
|
let name = idMatch[1];
|
|
|
let id = `${name}_hype_container`;
|
|
|
let script = $(`#${id}`).html();
|
|
|
let head = $('head').html();
|
|
|
|
|
|
head = head.replace(/href="(.*)"/g, function(match, p1) {
|
|
|
if (p1.indexOf('//') > -1) {
|
|
|
return p1;
|
|
|
}
|
|
|
const src = p1.indexOf('.') > -1 ? p1.slice(2) : p1;
|
|
|
|
|
|
return 'href=' + resourceUrl + src;
|
|
|
});
|
|
|
|
|
|
$('head').html(head);
|
|
|
|
|
|
let htmlString = $.html();
|
|
|
|
|
|
let scriptSrc = script.match(/src="(.*)"/);
|
|
|
let hasHypeScript = /_hype_generated_script/.test(htmlString);
|
|
|
|
|
|
// 获取到对应div里面的script的src,并替换成带有域名的地址,可以让所有图片地址指向js对应的域名
|
|
|
if (scriptSrc && scriptSrc.length >= 2) {
|
|
|
let src = scriptSrc[1];
|
|
|
let newScript = '<script type="text/javascript" charset="utf-8" src="' +
|
|
|
resourceUrl + src + '">';
|
|
|
if (hasHypeScript) {
|
|
|
htmlString = htmlString.replace(/src="(.*)"/g, function(match, p1) {
|
|
|
if (p1.indexOf('//') > -1) {
|
|
|
return p1;
|
|
|
}
|
|
|
const src = p1.indexOf('.') > -1 ? p1.slice(2) : p1;
|
|
|
|
|
|
$(`#${id}`).html(newScript);
|
|
|
return 'src=' + resourceUrl + src;
|
|
|
});
|
|
|
|
|
|
return res.send($.html()); // 输出修改过的html
|
|
|
return res.send(htmlString); // 输出修改过的html
|
|
|
} else {
|
|
|
return renderErroPage({msg: NO_HYPE_SCRIPT});
|
|
|
}
|
...
|
...
|
|