Small community post fixes (#3401)

* Small community post fixes

* fix #3387

* Check if post is empty

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>

---------

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>
This commit is contained in:
ChunkyProgrammer 2023-04-12 04:58:35 -04:00 committed by GitHub
parent bc039cd1aa
commit 9612df70cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -159,7 +159,9 @@ export async function invidiousGetCommunityPosts(channelId) {
function parseInvidiousCommunityData(data) {
return {
postText: data.contentHtml,
// use #/ to support channel YT links.
// ex post: https://www.youtube.com/post/UgkxMpGt1SVlHwA1afwqDr2DZLn-hmJJQqKo
postText: data.contentHtml.replaceAll('href="/', 'href="#/'),
postId: data.commentId,
authorThumbnails: data.authorThumbnails.map(thumbnail => {
thumbnail.url = youtubeImageUrlToInvidious(thumbnail.url)
@ -179,6 +181,15 @@ function parseInvidiousCommunityAttachments(data) {
return null
}
// I've only seen this appear when a video was made private.
// This is not currently supported on local api.
if (data.error) {
return {
type: 'error',
message: data.error
}
}
if (data.type === 'image') {
return {
type: data.type,
@ -190,7 +201,7 @@ function parseInvidiousCommunityAttachments(data) {
}
if (data.type === 'video') {
data.videoThumbnails = data.videoThumbnails.map(thumbnail => {
data.videoThumbnails = data.videoThumbnails?.map(thumbnail => {
thumbnail.url = youtubeImageUrlToInvidious(thumbnail.url)
return thumbnail
})

View File

@ -679,13 +679,13 @@ export function parseLocalSubscriberCount(text) {
* @param {import('youtubei.js/dist/src/parser/classes/BackstagePost').default} post
*/
export function parseLocalCommunityPost(post) {
let replyCount = post.action_buttons.reply_button?.text ?? null
let replyCount = post.action_buttons?.reply_button?.text ?? null
if (replyCount !== null) {
replyCount = parseLocalSubscriberCount(post?.action_buttons.reply_button.text)
}
return {
postText: post.content.text === 'N/A' ? '' : post.content.text,
postText: post.content.isEmpty() ? '' : Autolinker.link(parseLocalTextRuns(post.content.runs, 16)),
postId: post.id,
authorThumbnails: post.author.thumbnails,
publishedText: post.published.text,