Skip to content

Commit

Permalink
feat: long weibo and fix layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Loo authored and Loo committed Nov 2, 2023
1 parent 67bc046 commit 039cb85
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
19 changes: 19 additions & 0 deletions app/scripts/utils/fetches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,22 @@ export const fetchToGetVideoBlobByXHR = async ({ videoUrl }: { videoUrl: string
}
return null
}

export const fetchToGetLongText = async ({ mblogId }: { mblogId?: string }) => {
if (!mblogId) return null
try {
const response = await baseFetch({
url: `//weibo.com/ajax/statuses/longtext?id=${mblogId}`,
method: 'GET',
})

const result = await response.json()
const { longTextContent } = result?.data || {}
// 防止请求过于密集
await sleep(3 * Math.random())
return longTextContent || null
} catch (e) {
console.log(`fetchToGetImageBlob`, e)
}
return null
}
18 changes: 15 additions & 3 deletions app/scripts/utils/tools.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import JSZip from 'jszip'
const FileSaver = require('file-saver')
import _ from 'lodash'
import { fetchToGetImageBlob, fetchToGetVideoBlobByXHR } from './fetches'
import { fetchToGetImageBlob, fetchToGetVideoBlobByXHR, fetchToGetLongText } from './fetches'

// watch Element by MutationObserver
export const watchElement = ({
Expand Down Expand Up @@ -151,6 +151,8 @@ const convertBlogList = async ({
mix_media_info,
title,
user,
mblogid,
isLongText,
} = blogItem || {}

if (!_.isEmpty(page_info?.media_info)) {
Expand Down Expand Up @@ -266,6 +268,11 @@ const convertBlogList = async ({
profile_image_url: retweeted_status.user?.profile_image_url,
screen_name: retweeted_status.user?.screen_name,
}

let retweetedTextRaw = retweeted_status.text_raw
if (retweeted_status.isLongText && retweeted_status.mblogid) {
retweetedTextRaw = (await fetchToGetLongText({ mblogId: retweeted_status.mblogid })) || retweetedTextRaw
}
retweetedBlog = {
reposts_count: retweeted_status.reposts_count,
user: retweetFromUser,
Expand All @@ -283,7 +290,7 @@ const convertBlogList = async ({
region_name: retweeted_status.region_name, // 发布于XX
source: retweeted_status.source, // 客户端
text: retweeted_status.text,
text_raw: retweeted_status.text_raw,
text_raw: retweetedTextRaw,
}
}

Expand Down Expand Up @@ -332,6 +339,11 @@ const convertBlogList = async ({
}
}

let textRaw = text_raw
if (isLongText && mblogid) {
textRaw = (await fetchToGetLongText({ mblogId: mblogid })) || textRaw
}

finalList.push({
reposts_count, // 转发数
created_at, // 创建时间
Expand All @@ -348,7 +360,7 @@ const convertBlogList = async ({
region_name, // 发布于XX
source, // 客户端
text,
text_raw,
text_raw: textRaw,
retweetedBlog,
mediaInfoList,
title: title?.text ? { text: title.text } : undefined,
Expand Down
2 changes: 1 addition & 1 deletion weiboSave/scripts/weibosave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const appendBlog = ({$container, blogItem, postClass}: Record<string, any>)=>{
$postInside.append($smallInfoDiv)

// 文字
let $text = $('<p>').text(text_raw || text);
let $text = $('<p>').html(text_raw.replace(/\n/g, "<br />") || text);
$text.addClass(textClass)
$postInside.append($text);

Expand Down

0 comments on commit 039cb85

Please sign in to comment.