diff --git a/routes/twitter/user.js b/routes/twitter/user.js
index 60e1113b5..3a9e7f12c 100644
--- a/routes/twitter/user.js
+++ b/routes/twitter/user.js
@@ -7,7 +7,6 @@ const T = new Twit(config.twitter);
module.exports = async (ctx) => {
const id = ctx.params.id;
- const formatText = (text) => text.replace(/https:\/\/t\.co(.*)/g, '');
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
@@ -31,11 +30,43 @@ module.exports = async (ctx) => {
return url;
}
};
+
+ const formatText = (text) => text.replace(/https:\/\/t\.co(.*)/g, '');
+ const formatVideo = (media) => {
+ let content = '';
+ const video = media.video_info.variants.reduce((video, item) => {
+ if ((item.bitrate || 0) > (video.bitrate || 0)) {
+ video = item;
+ }
+ return video;
+ }, {});
+
+ if (video.url) {
+ content = `
`;
+ }
+
+ return content;
+ };
+
const formatMedia = (item) => {
let img = '';
item.extended_entities &&
item.extended_entities.media.forEach((item) => {
- img += `
${item.type === 'video' ? 'Video: ' : ''}
`;
+ // https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/extended-entities-object
+ let content = '';
+ switch (item.type) {
+ case 'animated_gif':
+ case 'video':
+ content = formatVideo(item);
+ break;
+
+ case 'photo':
+ default:
+ content = `
`;
+ break;
+ }
+
+ img += content;
});
return img;