refactor (route/mastodon): quick fix on empty reposted toots (#9700)
This commit is contained in:
parent
4432bb0f19
commit
a37cf18153
|
|
@ -1,7 +1,13 @@
|
|||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const parseStatuses = (data) =>
|
||||
data.map((item) => {
|
||||
// docs on: https://docs.joinmastodon.org/entities/status/
|
||||
|
||||
const accountRepostedBy = item.reblog ? item.account : null;
|
||||
item = item.reblog ? item.reblog : item;
|
||||
|
||||
const content = item.content ? item.content.replace(/<span.*?>|<\/span.*?>/gm, '') : '';
|
||||
const contentRemovedHtml = content.replace(/<(?:.|\n)*?>/gm, '\n');
|
||||
|
||||
|
|
@ -26,25 +32,19 @@ const parseStatuses = (data) =>
|
|||
})
|
||||
.join('');
|
||||
|
||||
let author, link, titleAuthor, media;
|
||||
if (item.reblog !== null) {
|
||||
author = `${item.reblog.account.display_name} (@${item.reblog.account.acct})`;
|
||||
link = item.reblog.url;
|
||||
titleAuthor = `Re @${item.reblog.account.username}`;
|
||||
media = mediaParse(item.reblog.media_attachments);
|
||||
} else {
|
||||
author = `${item.account.display_name} (@${item.account.acct})`;
|
||||
link = item.url;
|
||||
titleAuthor = `@${item.account.username}`;
|
||||
media = mediaParse(item.media_attachments);
|
||||
}
|
||||
const author = `${item.account.display_name} (@${item.account.acct})`;
|
||||
const link = item.url;
|
||||
const media = mediaParse(item.media_attachments);
|
||||
|
||||
const titleAuthor = accountRepostedBy ? `Re @${accountRepostedBy.username}` : `@${item.account.username}`;
|
||||
const titleText = item.sensitive === true ? `(CW) ${item.spoiler_text}` : contentRemovedHtml;
|
||||
const title = `${titleAuthor}: "${titleText}"`;
|
||||
|
||||
return {
|
||||
title: `${titleAuthor}: "${titleText}"`,
|
||||
title,
|
||||
author,
|
||||
description: item.spoiler_text + '<hr />' + content + media,
|
||||
pubDate: new Date(item.created_at).toUTCString(),
|
||||
pubDate: parseDate(item.created_at),
|
||||
link,
|
||||
guid: item.uri,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue