This reverts commit 5a2e252eb3.
This commit is contained in:
parent
475c729d71
commit
56dc1d2a85
|
|
@ -1,125 +1,56 @@
|
|||
const got = require('@/utils/got');
|
||||
|
||||
function getContentByActivity(item, isRenderingRepost = false) {
|
||||
const { status, comments } = item;
|
||||
function getContentByActivity(status) {
|
||||
let description = '';
|
||||
let title = '';
|
||||
switch (status.activity) {
|
||||
case '说':
|
||||
title = `${status.author.name} ${status.activity}:${status.text}`;
|
||||
description = status.text;
|
||||
status.images.forEach((image) => {
|
||||
description += `<p><img src="${image.large.url}"/></p>`;
|
||||
});
|
||||
break;
|
||||
case '转发':
|
||||
description = `${status.text}<br>`;
|
||||
if (status.reshared_status.deleted) {
|
||||
title = `${status.author.name} ${status.activity} 广播:原动态已被发布者删除`;
|
||||
description += `原动态已被发布者删除`;
|
||||
} else {
|
||||
description += getContentByActivity(status.reshared_status).title;
|
||||
title = `${status.author.name} ${status.activity} ${status.reshared_status.author.name} 的广播:${status.reshared_status.text}`;
|
||||
status.reshared_status.images.forEach((image) => {
|
||||
description += `<p><img src="${image.large.url}"/></p>`;
|
||||
});
|
||||
}
|
||||
|
||||
let usernameAndAvatar = `<a href="${status.author.url}">`;
|
||||
if (!isRenderingRepost) {
|
||||
usernameAndAvatar += `<img align="left" width="48" src="${status.author.avatar}" hspace="8" vspace="8" />`;
|
||||
break;
|
||||
default:
|
||||
description = `${status.text ? `${status.text}<br><br>` : ''}`;
|
||||
title = `${status.author.name}${status.activity}: ${description}`;
|
||||
if (status.card) {
|
||||
let image;
|
||||
if (status.card.image && (status.card.image.large || status.card.image.normal)) {
|
||||
image = (status.card.image.large || status.card.image.normal).url;
|
||||
}
|
||||
if (status.card.rating) {
|
||||
description += `豆瓣评分:${status.card.rating}<br>${status.card.subtitle}${image ? `<br><img src="${image}">` : ''}<br><a href="${status.card.url}">《${status.card.title}》</a>`;
|
||||
title = `${status.author.name}${status.activity}:《${status.card.title}》`;
|
||||
} else {
|
||||
description += `${status.card.subtitle}${image ? `<br><img src="${image}">` : ''}<br>${status.card.url ? `<a href="${status.card.url}">${status.card.title}</a>` : ''}`;
|
||||
title = `${status.author.name} ${status.activity}:「${status.card.title}」${status.text}`;
|
||||
}
|
||||
}
|
||||
if (status.video_card) {
|
||||
const videoCover = status.video_card.video_info && status.video_card.video_info.cover_url;
|
||||
const videoSrc = status.video_card.video_info && status.video_card.video_info.video_url;
|
||||
description += `${videoSrc ? `<br><video src="${videoSrc}" ${videoCover ? `poster="${videoCover}"` : ''}></video>` : ''}<br><br>${
|
||||
status.video_card.title ? `<a href="${status.video_card.url}">${status.video_card.title}</a>` : ''
|
||||
}`;
|
||||
title = `${status.author.name}${status.activity}:《${status.video_card.title}》`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
usernameAndAvatar += `<strong>${status.author.name}</strong></a> `;
|
||||
|
||||
title += `${status.author.name} ${status.activity}: `;
|
||||
description += usernameAndAvatar + `${status.activity}`;
|
||||
|
||||
description += `<br><small>${status.create_time}</small><br>`;
|
||||
|
||||
let text = status.text;
|
||||
let lastIndex = 0;
|
||||
const replacedTextSegements = [];
|
||||
for (const entity of status.entities) {
|
||||
replacedTextSegements.push(text.slice(lastIndex, entity.start));
|
||||
replacedTextSegements.push(`<a href="${entity.uri.replace('douban://douban.com', 'https://www.douban.com/doubanapp/dispatch?uri=')}" target="_blank" rel="noopener noreferrer">${entity.title}</a>`);
|
||||
lastIndex = entity.end;
|
||||
}
|
||||
replacedTextSegements.push(text.slice(lastIndex));
|
||||
text = replacedTextSegements.join('');
|
||||
|
||||
// text // images // video_info // parent status
|
||||
|
||||
description += text;
|
||||
|
||||
if (status.card) {
|
||||
if (status.card.rating) {
|
||||
title += `《${status.card.title}》`;
|
||||
} else {
|
||||
title += `「${status.card.title}」`;
|
||||
}
|
||||
}
|
||||
|
||||
title += status.text.replace('\n', '');
|
||||
|
||||
if (status.images.length) {
|
||||
description += `<br clear="both" /><div style="clear: both"></div>`;
|
||||
status.images.forEach((image) => {
|
||||
description += '<a href="' + image.large.url + '"><img vspace="8" hspace="4" src="' + image.large.url + '"></a>';
|
||||
});
|
||||
}
|
||||
|
||||
if (status.video_info) {
|
||||
description += `<br clear="both" /><div style="clear: both"></div>`;
|
||||
const videoCover = status.video_info.cover_url;
|
||||
const videoSrc = status.video_info.video_url;
|
||||
description += `${videoSrc ? `<video src="${videoSrc}" ${videoCover ? `poster="${videoCover}"` : ''}></video>` : ''}`;
|
||||
}
|
||||
|
||||
if (status.parent_status) {
|
||||
description += ' 🔁 ';
|
||||
title += ' 🔁 ';
|
||||
|
||||
let usernameAndAvatar = `<a href="${status.parent_status.author.url}">`;
|
||||
usernameAndAvatar += `<strong>${status.parent_status.author.name}</strong></a>: `;
|
||||
description += usernameAndAvatar + status.parent_status.text;
|
||||
title += usernameAndAvatar + status.parent_status.text;
|
||||
}
|
||||
|
||||
// card
|
||||
if (status.card) {
|
||||
let image;
|
||||
if (status.card.image && (status.card.image.large || status.card.image.normal)) {
|
||||
image = status.card.image.large || status.card.image.normal;
|
||||
}
|
||||
|
||||
description += `<br clear="both" /><div style="clear: both"></div><blockquote>`;
|
||||
if (image) {
|
||||
description += `<img height="${image.height}" src="${image.url}" vspace="8" hspace="4" align="left" />`;
|
||||
}
|
||||
description += `<a href="${status.card.url}" target="_blank" rel="noopener noreferrer"><strong>${status.card.title}</strong><br><small>${status.card.subtitle}</small>`;
|
||||
if (status.card.rating) {
|
||||
description += `<br><small>评分:${status.card.rating}</small>`;
|
||||
}
|
||||
description += `</a><br clear="both" /><div style="clear: both"></div></blockquote>`;
|
||||
}
|
||||
|
||||
// video_card
|
||||
if (status.video_card) {
|
||||
description += `<br clear="both" /><div style="clear: both"></div><blockquote>`;
|
||||
const videoCover = status.video_card.video_info && status.video_card.video_info.cover_url;
|
||||
const videoSrc = status.video_card.video_info && status.video_card.video_info.video_url;
|
||||
description += `${videoSrc ? `<video src="${videoSrc}" ${videoCover ? `poster="${videoCover}"` : ''}></video>` : ''}<br>${status.video_card.title ? `<a href="${status.video_card.url}">${status.video_card.title}</a>` : ''}`;
|
||||
description += `</blockquote>`;
|
||||
}
|
||||
|
||||
// reshared_status
|
||||
if (status.reshared_status) {
|
||||
description += `<br clear="both" /><div style="clear: both"></div><blockquote>`;
|
||||
|
||||
if (status.reshared_status.deleted) {
|
||||
description += `原动态已被发布者删除`;
|
||||
title += ` | 原动态已被发布者删除`;
|
||||
} else {
|
||||
description += getContentByActivity({ status: status.reshared_status, comments: [] }, true).description;
|
||||
title += ' | ' + status.reshared_status.text;
|
||||
}
|
||||
|
||||
const reshared_url = status.reshared_status.uri.replace('douban://douban.com', 'https://www.douban.com/doubanapp/dispatch?uri=');
|
||||
|
||||
description += `<br><small>原动态:<a href="${reshared_url}" target="_blank" rel="noopener noreferrer">${reshared_url}</a></small><br clear="both" /><div style="clear: both"></div></blockquote>`;
|
||||
}
|
||||
|
||||
// comments
|
||||
if (!isRenderingRepost) {
|
||||
if (comments.length > 0) {
|
||||
description += '<hr>';
|
||||
}
|
||||
for (const comment of comments) {
|
||||
description += `<br>${comment.text} - <a href="${comment.author.url}" target="_blank" rel="noopener noreferrer">${comment.author.name}</a>`;
|
||||
}
|
||||
}
|
||||
|
||||
description = description.trim().replace(/\n/g, '<br>');
|
||||
return { title, description };
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +78,7 @@ module.exports = async (ctx) => {
|
|||
items
|
||||
.filter((item) => !item.deleted)
|
||||
.map((item) => {
|
||||
const r = getContentByActivity(item);
|
||||
const r = getContentByActivity(item.status);
|
||||
return {
|
||||
title: r.title,
|
||||
link: item.status.sharing_url,
|
||||
|
|
|
|||
|
|
@ -37,11 +37,8 @@ module.exports = async (ctx) => {
|
|||
link: `https://twitter.com/${id}/`,
|
||||
image: profileImageUrl,
|
||||
description: userInfo.description,
|
||||
item: utils.ProcessFeed(
|
||||
{
|
||||
data,
|
||||
},
|
||||
true
|
||||
),
|
||||
item: utils.ProcessFeed({
|
||||
data,
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const URL = require('url');
|
|||
const config = require('@/config').value;
|
||||
const Twit = require('twit');
|
||||
|
||||
const ProcessFeed = ({ data = [] }, showAuthor = false, showAuthorInTitle = false) => {
|
||||
const ProcessFeed = ({ data = [] }, showAuthor = false) => {
|
||||
const getQueryParams = (url) => URL.parse(url, true).query;
|
||||
const getOrigionImg = (url) => {
|
||||
// https://greasyfork.org/zh-CN/scripts/2312-resize-image-on-open-image-in-new-tab/code#n150
|
||||
|
|
@ -28,12 +28,7 @@ const ProcessFeed = ({ data = [] }, showAuthor = false, showAuthorInTitle = fals
|
|||
};
|
||||
|
||||
const replaceBreak = (text) => text.replace(/<br><br>|<br>/g, ' ');
|
||||
const formatText = (text) =>
|
||||
text
|
||||
.replace(/https:\/\/t\.co(.*)/g, '')
|
||||
.trim()
|
||||
.replace(/\n/g, '<br>');
|
||||
const formatTextToPlain = (text) => text.replace(/https:\/\/t\.co(.*)/g, '').trim();
|
||||
const formatText = (text) => text.replace(/https:\/\/t\.co(.*)/g, '').replace(/\n/g, '<br>');
|
||||
const formatVideo = (media) => {
|
||||
let content = '';
|
||||
const video = media.video_info.variants.reduce((video, item) => {
|
||||
|
|
@ -45,7 +40,7 @@ const ProcessFeed = ({ data = [] }, showAuthor = false, showAuthorInTitle = fals
|
|||
|
||||
if (video.url) {
|
||||
const gifAutoPlayAttr = media.type === 'animated_gif' ? `autoplay loop muted webkit-playsinline playsinline` : '';
|
||||
content = `<video src="${video.url}" ${gifAutoPlayAttr} controls="controls" poster="${getOrigionImg(media.media_url_https)}" style="width: 100%"></video>`;
|
||||
content = `<br><video src="${video.url}" ${gifAutoPlayAttr} controls="controls" poster="${getOrigionImg(media.media_url_https)}" style="width: 100%"></video>`;
|
||||
}
|
||||
|
||||
return content;
|
||||
|
|
@ -57,7 +52,6 @@ const ProcessFeed = ({ data = [] }, showAuthor = false, showAuthorInTitle = fals
|
|||
item.extended_entities.media.forEach((item) => {
|
||||
// https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/extended-entities-object
|
||||
let content = '';
|
||||
let originImg;
|
||||
switch (item.type) {
|
||||
case 'animated_gif':
|
||||
case 'video':
|
||||
|
|
@ -66,51 +60,39 @@ const ProcessFeed = ({ data = [] }, showAuthor = false, showAuthorInTitle = fals
|
|||
|
||||
case 'photo':
|
||||
default:
|
||||
originImg = getOrigionImg(item.media_url_https);
|
||||
content = `<a href="${originImg}"><img hspace="4" vspace="8" src="${originImg}"></a>`;
|
||||
content = `<br><img src="${getOrigionImg(item.media_url_https)}">`;
|
||||
break;
|
||||
}
|
||||
|
||||
img += content;
|
||||
});
|
||||
|
||||
if (img) {
|
||||
img = `<br clear="both" /><div style="clear: both"></div>` + img;
|
||||
}
|
||||
return img;
|
||||
};
|
||||
const formatUrl = (item) => {
|
||||
let url = '';
|
||||
item.entities.urls.forEach((u) => {
|
||||
url += `<br><a href="${u.expanded_url}" target="_blank" rel="noopener noreferrer">${u.expanded_url}</a>`;
|
||||
url += `<a href="${u.expanded_url}" target="_blank" rel="noopener noreferrer">${u.expanded_url}</a>`;
|
||||
});
|
||||
|
||||
return url;
|
||||
};
|
||||
|
||||
return data.map((item) => {
|
||||
const originalItem = item;
|
||||
item = item.retweeted_status || item;
|
||||
item.full_text = formatText(item.full_text);
|
||||
const img = formatMedia(item);
|
||||
let url = '';
|
||||
let quote = '';
|
||||
let quoteOnTitle = '';
|
||||
|
||||
if (item.is_quote_status) {
|
||||
const quoteData = item.quoted_status;
|
||||
|
||||
if (quoteData) {
|
||||
const author = quoteData.user;
|
||||
quote += `<br clear="both" /><div style="clear: both"></div><blockquote><a href="https://twitter.com/${author.screen_name}"><img align="left" src="${author.profile_image_url_https}" hspace="8" vspace="8"><strong>${author.name}</strong></a>: `;
|
||||
quote += `${formatText(quoteData.full_text)}`;
|
||||
quote += `<br><br>${author.name}: ${formatText(quoteData.full_text)}<br>`;
|
||||
quote += formatMedia(quoteData);
|
||||
quote += formatUrl(quoteData);
|
||||
quoteOnTitle += `| ${author.name}: ${formatTextToPlain(quoteData.full_text)}`;
|
||||
|
||||
quote += `<br><small>Source: <a href="https://twitter.com/${author.screen_name}/status/${quoteData.id_str}" target="_blank" rel="noopener noreferrer">https://twitter.com/${author.screen_name}/status/${quoteData.id_str}</a></small>`;
|
||||
quote += '<br><small>' + new Date(quoteData.created_at).toLocaleString();
|
||||
quote += `</small><br clear="both" /><div style="clear: both"></div></blockquote>`;
|
||||
} else {
|
||||
url = formatUrl(item);
|
||||
}
|
||||
|
|
@ -119,13 +101,11 @@ const ProcessFeed = ({ data = [] }, showAuthor = false, showAuthorInTitle = fals
|
|||
}
|
||||
|
||||
return {
|
||||
title:
|
||||
originalItem.user.name +
|
||||
`: ${originalItem === item ? '' : '🔁 '}${showAuthorInTitle || originalItem !== item ? item.user.name + ': ' : ''}${item.in_reply_to_screen_name ? '↩️ ' : ''}${replaceBreak(item.full_text)}${quoteOnTitle}`,
|
||||
author: originalItem.user.name,
|
||||
description: `${
|
||||
showAuthor ? `<a href="https://twitter.com/${item.user.screen_name}"><img align="left" src="${item.user.profile_image_url_https}" hspace="8" vspace="8"><strong>${item.user.name}</strong></a>: ` : ''
|
||||
}${item.in_reply_to_screen_name ? '🔁 ' : ''}${item.full_text}${url}${img}${quote}<hr><small>${new Date(item.created_at).toLocaleString()}</small>`,
|
||||
title: `${showAuthor ? item.user.name + ': ' : ''}${item.in_reply_to_screen_name ? 'Re ' : ''}${replaceBreak(item.full_text)}`,
|
||||
author: item.user.name,
|
||||
description: `${showAuthor ? `<img width="15px" src="${item.user.profile_image_url_https}"><strong>${item.user.name}:</strong><br><br>` : ''}${item.in_reply_to_screen_name ? 'Re ' : ''}${
|
||||
item.full_text
|
||||
}${url}${img}${quote}`,
|
||||
pubDate: new Date(item.created_at).toUTCString(),
|
||||
link: `https://twitter.com/${item.user.screen_name}/status/${item.id_str}`,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -49,10 +49,6 @@ module.exports = async (ctx) => {
|
|||
const isDataOK = data !== undefined && data.text;
|
||||
if (isDataOK) {
|
||||
item.mblog.text = data.text;
|
||||
item.mblog.created_at = data.created_at;
|
||||
if (item.mblog.retweeted_status && data.retweeted_status) {
|
||||
item.mblog.retweeted_status.created_at = data.retweeted_status.created_at;
|
||||
}
|
||||
}
|
||||
// 转发的长微博处理
|
||||
const retweet = item.mblog.retweeted_status;
|
||||
|
|
@ -64,10 +60,8 @@ module.exports = async (ctx) => {
|
|||
}
|
||||
|
||||
const link = `https://weibo.com/${uid}/${item.mblog.bid}`;
|
||||
const formatWithRetweet = weiboUtils.formatWithRetweet(item.mblog);
|
||||
let description = formatWithRetweet.description;
|
||||
const retweetedOrOriginal = formatWithRetweet.retweetedOrOriginal;
|
||||
const title = item.mblog.user.screen_name + ': ' + retweetedOrOriginal.replace(/<img[\s\S]*?>/g, '[图片]').replace(/<.*?>/g, '');
|
||||
let description = weiboUtils.format(item.mblog);
|
||||
const title = description.replace(/<img[\s\S]*?>/g, '[图片]').replace(/<.*?>/g, '');
|
||||
const pubDate = isDataOK ? new Date(data.created_at).toUTCString() : date(item.mblog.created_at, 8);
|
||||
|
||||
// 视频的处理
|
||||
|
|
@ -80,7 +74,6 @@ module.exports = async (ctx) => {
|
|||
description: description,
|
||||
link: link,
|
||||
pubDate: pubDate,
|
||||
author: item.mblog.user.screen_name,
|
||||
};
|
||||
return Promise.resolve(it);
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
const got = require('@/utils/got');
|
||||
|
||||
const weiboUtils = {
|
||||
format: (status) => weiboUtils.formatWithRetweet(status).description,
|
||||
formatWithRetweet: (status, showAuthorAvatar = true) => {
|
||||
let retweetedOrOriginal = '';
|
||||
format: (status) => {
|
||||
// 长文章的处理
|
||||
let temp = (status.longText && status.longText.longTextContent) || status.text || '';
|
||||
let temp = (status.longText && status.longText.longTextContent.replace(/\n/g, '<br>')) || status.text || '';
|
||||
// 表情图标转换为文字
|
||||
temp = temp.replace(/<span class="url-icon"><img.*?alt="?(.*?)"? [\s\S]*?\/><\/span>/g, '$1');
|
||||
// 去掉外部链接的图标
|
||||
|
|
@ -21,43 +19,24 @@ const weiboUtils = {
|
|||
return decodeURIComponent(p1);
|
||||
});
|
||||
|
||||
let originalText = temp;
|
||||
temp = temp.replace(/\n/g, '<br>');
|
||||
|
||||
// 添加用户名和头像
|
||||
let usernameAndAvatar = `<a href="https://weibo.com/${status.user.id}">`;
|
||||
if (showAuthorAvatar) {
|
||||
usernameAndAvatar += `<img align="left" width="48" src="${status.user.profile_image_url}" hspace="8" vspace="8" />`;
|
||||
}
|
||||
usernameAndAvatar += `<strong>${status.user.screen_name}</strong></a>: `;
|
||||
temp = usernameAndAvatar + temp;
|
||||
|
||||
// 处理转发的微博
|
||||
if (status.retweeted_status) {
|
||||
temp += `<br clear="both" /><div style="clear: both"></div><blockquote>`;
|
||||
if (!status.retweeted_status.user) {
|
||||
// 当转发的微博被删除时user为null
|
||||
status.retweeted_status.user = '微博已删除';
|
||||
// 当转发的微博被删除时user为null
|
||||
if (status.retweeted_status.user) {
|
||||
temp += `<br><blockquote> - 转发 <a href="https://weibo.com/${status.retweeted_status.user.id}" target="_blank">@${status.retweeted_status.user.screen_name}</a>: `;
|
||||
}
|
||||
// 插入转发的微博
|
||||
retweetedOrOriginal += weiboUtils.formatWithRetweet(status.retweeted_status, false).description;
|
||||
temp +=
|
||||
retweetedOrOriginal +
|
||||
`<br><small>原博:<a href="https://weibo.com/${status.retweeted_status.user.id}/${status.retweeted_status.bid}" target="_blank" rel="noopener noreferrer">https://weibo.com/${status.retweeted_status.user.id}/${status.retweeted_status.bid}</a></small><br><small>` +
|
||||
new Date(status.retweeted_status.created_at).toLocaleString() +
|
||||
'</small><br clear="both" /><div style="clear: both"></div></blockquote>';
|
||||
temp += weiboUtils.format(status.retweeted_status);
|
||||
temp += '</blockquote>';
|
||||
}
|
||||
|
||||
// 添加微博配图
|
||||
if (status.pics) {
|
||||
temp += '<br clear="both" /><div style="clear: both"></div>';
|
||||
status.pics.forEach(function (item) {
|
||||
temp += '<a href="' + item.large.url + '"><img vspace="8" hspace="4" src="' + item.large.url + '"></a>';
|
||||
originalText += '<img src="">';
|
||||
temp += '<img src="' + item.large.url + '"><br><br>';
|
||||
});
|
||||
}
|
||||
|
||||
return { description: temp, retweetedOrOriginal: status.retweeted_status ? '🔁 ' + retweetedOrOriginal : originalText.replace('\n', '') };
|
||||
return temp;
|
||||
},
|
||||
getShowData: async (uid, bid) => {
|
||||
const link = `https://m.weibo.cn/statuses/show?id=${bid}`;
|
||||
|
|
@ -79,7 +58,7 @@ const weiboUtils = {
|
|||
const posterUrl = pagePic ? pagePic.url : '';
|
||||
const videoUrl = mediaInfo ? mediaInfo.stream_url_hd || mediaInfo.stream_url || mediaInfo.mp4_hd_url || mediaInfo.mp4_sd_url || mediaInfo.mp4_720p_mp4 : '';
|
||||
if (videoUrl) {
|
||||
const video = `<br clear="both" /><div style="clear: both"></div><video src="${videoUrl}" controls="controls" poster="${posterUrl}" style="width: 100%"></video>`;
|
||||
const video = `<br><video src="${videoUrl}" controls="controls" poster="${posterUrl}" style="width: 100%"></video>`;
|
||||
itemDesc += video;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue