|
1 | 1 | const got = require('@/utils/got'); |
2 | 2 |
|
3 | | -function getContentByActivity(status) { |
| 3 | +function getContentByActivity(item, isRenderingRepost = false) { |
| 4 | + const { status, comments } = item; |
4 | 5 | let description = ''; |
5 | 6 | let title = ''; |
6 | | - switch (status.activity) { |
7 | | - case '说': |
8 | | - title = `${status.author.name} ${status.activity}:${status.text}`; |
9 | | - description = status.text; |
10 | | - status.images.forEach((image) => { |
11 | | - description += `<p><img src="${image.large.url}"/></p>`; |
12 | | - }); |
13 | | - break; |
14 | | - case '转发': |
15 | | - description = `${status.text}<br>`; |
16 | | - if (status.reshared_status.deleted) { |
17 | | - title = `${status.author.name} ${status.activity} 广播:原动态已被发布者删除`; |
18 | | - description += `原动态已被发布者删除`; |
19 | | - } else { |
20 | | - description += getContentByActivity(status.reshared_status).title; |
21 | | - title = `${status.author.name} ${status.activity} ${status.reshared_status.author.name} 的广播:${status.reshared_status.text}`; |
22 | | - status.reshared_status.images.forEach((image) => { |
23 | | - description += `<p><img src="${image.large.url}"/></p>`; |
24 | | - }); |
25 | | - } |
26 | | - |
27 | | - break; |
28 | | - default: |
29 | | - description = `${status.text ? `${status.text}<br><br>` : ''}`; |
30 | | - title = `${status.author.name}${status.activity}: ${description}`; |
31 | | - if (status.card) { |
32 | | - let image; |
33 | | - if (status.card.image && (status.card.image.large || status.card.image.normal)) { |
34 | | - image = (status.card.image.large || status.card.image.normal).url; |
35 | | - } |
36 | | - if (status.card.rating) { |
37 | | - description += `豆瓣评分:${status.card.rating}<br>${status.card.subtitle}${image ? `<br><img src="${image}">` : ''}<br><a href="${status.card.url}">《${status.card.title}》</a>`; |
38 | | - title = `${status.author.name}${status.activity}:《${status.card.title}》`; |
39 | | - } else { |
40 | | - description += `${status.card.subtitle}${image ? `<br><img src="${image}">` : ''}<br>${status.card.url ? `<a href="${status.card.url}">${status.card.title}</a>` : ''}`; |
41 | | - title = `${status.author.name} ${status.activity}:「${status.card.title}」${status.text}`; |
42 | | - } |
43 | | - } |
44 | | - if (status.video_card) { |
45 | | - const videoCover = status.video_card.video_info && status.video_card.video_info.cover_url; |
46 | | - const videoSrc = status.video_card.video_info && status.video_card.video_info.video_url; |
47 | | - description += `${videoSrc ? `<br><video src="${videoSrc}" ${videoCover ? `poster="${videoCover}"` : ''}></video>` : ''}<br><br>${ |
48 | | - status.video_card.title ? `<a href="${status.video_card.url}">${status.video_card.title}</a>` : '' |
49 | | - }`; |
50 | | - title = `${status.author.name}${status.activity}:《${status.video_card.title}》`; |
51 | | - } |
52 | | - break; |
| 7 | + |
| 8 | + let usernameAndAvatar = `<a href="${status.author.url}">`; |
| 9 | + if (!isRenderingRepost) { |
| 10 | + usernameAndAvatar += `<img align="left" width="48" src="${status.author.avatar}" hspace="8" vspace="8" />`; |
| 11 | + } |
| 12 | + usernameAndAvatar += `<strong>${status.author.name}</strong></a> `; |
| 13 | + |
| 14 | + title += `${status.author.name} ${status.activity}: `; |
| 15 | + description += usernameAndAvatar + `${status.activity}`; |
| 16 | + |
| 17 | + description += `<br><small>${status.create_time}</small><br>`; |
| 18 | + |
| 19 | + let text = status.text; |
| 20 | + let lastIndex = 0; |
| 21 | + const replacedTextSegements = []; |
| 22 | + for (const entity of status.entities) { |
| 23 | + replacedTextSegements.push(text.slice(lastIndex, entity.start)); |
| 24 | + 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>`); |
| 25 | + lastIndex = entity.end; |
| 26 | + } |
| 27 | + replacedTextSegements.push(text.slice(lastIndex)); |
| 28 | + text = replacedTextSegements.join(''); |
| 29 | + |
| 30 | + // text // images // video_info // parent status |
| 31 | + |
| 32 | + description += text; |
| 33 | + |
| 34 | + if (status.card) { |
| 35 | + if (status.card.rating) { |
| 36 | + title += `《${status.card.title}》`; |
| 37 | + } else { |
| 38 | + title += `「${status.card.title}」`; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + title += status.text.replace('\n', ''); |
| 43 | + |
| 44 | + if (status.images.length) { |
| 45 | + description += `<br clear="both" /><div style="clear: both"></div>`; |
| 46 | + status.images.forEach((image) => { |
| 47 | + description += '<a href="' + image.large.url + '"><img vspace="8" hspace="4" src="' + image.large.url + '"></a>'; |
| 48 | + }); |
| 49 | + } |
| 50 | + |
| 51 | + if (status.video_info) { |
| 52 | + description += `<br clear="both" /><div style="clear: both"></div>`; |
| 53 | + const videoCover = status.video_info.cover_url; |
| 54 | + const videoSrc = status.video_info.video_url; |
| 55 | + description += `${videoSrc ? `<video src="${videoSrc}" ${videoCover ? `poster="${videoCover}"` : ''}></video>` : ''}`; |
| 56 | + } |
| 57 | + |
| 58 | + if (status.parent_status) { |
| 59 | + description += ' 🔁 '; |
| 60 | + title += ' 🔁 '; |
| 61 | + |
| 62 | + let usernameAndAvatar = `<a href="${status.parent_status.author.url}">`; |
| 63 | + usernameAndAvatar += `<strong>${status.parent_status.author.name}</strong></a>: `; |
| 64 | + description += usernameAndAvatar + status.parent_status.text; |
| 65 | + title += usernameAndAvatar + status.parent_status.text; |
| 66 | + } |
| 67 | + |
| 68 | + // card |
| 69 | + if (status.card) { |
| 70 | + let image; |
| 71 | + if (status.card.image && (status.card.image.large || status.card.image.normal)) { |
| 72 | + image = status.card.image.large || status.card.image.normal; |
| 73 | + } |
| 74 | + |
| 75 | + description += `<br clear="both" /><div style="clear: both"></div><blockquote>`; |
| 76 | + if (image) { |
| 77 | + description += `<img height="${image.height}" src="${image.url}" vspace="8" hspace="4" align="left" />`; |
| 78 | + } |
| 79 | + description += `<a href="${status.card.url}" target="_blank" rel="noopener noreferrer"><strong>${status.card.title}</strong><br><small>${status.card.subtitle}</small>`; |
| 80 | + if (status.card.rating) { |
| 81 | + description += `<br><small>评分:${status.card.rating}</small>`; |
| 82 | + } |
| 83 | + description += `</a><br clear="both" /><div style="clear: both"></div></blockquote>`; |
| 84 | + } |
| 85 | + |
| 86 | + // video_card |
| 87 | + if (status.video_card) { |
| 88 | + description += `<br clear="both" /><div style="clear: both"></div><blockquote>`; |
| 89 | + const videoCover = status.video_card.video_info && status.video_card.video_info.cover_url; |
| 90 | + const videoSrc = status.video_card.video_info && status.video_card.video_info.video_url; |
| 91 | + 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>` : ''}`; |
| 92 | + description += `</blockquote>`; |
53 | 93 | } |
| 94 | + |
| 95 | + // reshared_status |
| 96 | + if (status.reshared_status) { |
| 97 | + description += `<br clear="both" /><div style="clear: both"></div><blockquote>`; |
| 98 | + |
| 99 | + if (status.reshared_status.deleted) { |
| 100 | + description += `原动态已被发布者删除`; |
| 101 | + title += ` | 原动态已被发布者删除`; |
| 102 | + } else { |
| 103 | + description += getContentByActivity({ status: status.reshared_status, comments: [] }, true).description; |
| 104 | + title += ' | ' + status.reshared_status.text; |
| 105 | + } |
| 106 | + |
| 107 | + const reshared_url = status.reshared_status.uri.replace('douban://douban.com', 'https://www.douban.com/doubanapp/dispatch?uri='); |
| 108 | + |
| 109 | + 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>`; |
| 110 | + } |
| 111 | + |
| 112 | + // comments |
| 113 | + if (!isRenderingRepost) { |
| 114 | + if (comments.length > 0) { |
| 115 | + description += '<hr>'; |
| 116 | + } |
| 117 | + for (const comment of comments) { |
| 118 | + description += `<br>${comment.text} - <a href="${comment.author.url}" target="_blank" rel="noopener noreferrer">${comment.author.name}</a>`; |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + description = description.trim().replace(/\n/g, '<br>'); |
54 | 123 | return { title, description }; |
55 | 124 | } |
56 | 125 |
|
@@ -78,7 +147,7 @@ module.exports = async (ctx) => { |
78 | 147 | items |
79 | 148 | .filter((item) => !item.deleted) |
80 | 149 | .map((item) => { |
81 | | - const r = getContentByActivity(item.status); |
| 150 | + const r = getContentByActivity(item); |
82 | 151 | return { |
83 | 152 | title: r.title, |
84 | 153 | link: item.status.sharing_url, |
|
0 commit comments