Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
node_modules
dist
dist
.env
.wrangler
.github
.vscode
.idea
.DS_Store
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ RSSWorker 是一个轻量级的 RSS 订阅工具,可以部署在 Cloudflare Wo
> 网页端:用户页面 > 链接中的用户ID
> 格式:https://www.xiaohongshu.com/user/profile/5d2aec020000000012037401

> 微博更新后需要加上Cookie
> 获取方法(参考 https://docs.rsshub.app/zh/deploy/config#%E5%BE%AE%E5%8D%9A ) :
> 1. 打开并登录微博
> 2. 从个人微博主页的网址中获取uid,在`https://m.weibo.cn/api/container/getIndex?type=uid&value=`后追加uid,访问该链接
> 2. 按下F12打开控制台,切换至Network(网络)面板
> 3. 在该网页切换至任意关注分组,并在面板打开最先捕获到的请求 (该情形下捕获到的请求路径应包含/feed/group)
> 4. 查看该请求的Headers(请求头), 找到Cookie字段并复制内容
> 5. 命令行中输入`wrangler secret put WEIBO_COOKIE`,按下回车后再将第4步中复制的Cookie字段粘贴,后按下回车

## 部署

[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/yllhwa/RSSWorker)
Expand Down
14 changes: 11 additions & 3 deletions src/lib/weibo/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ let deal = async (ctx) => {
const containerData = await fetch(`https://m.weibo.cn/api/container/getIndex?type=uid&value=${uid}`, {
headers: {
Referer: `https://m.weibo.cn/u/${uid}`,
Cookie: ctx.env.WEIBO_COOKIE || '',
Accept: 'application/json, text/plain, */*',
'User-Agent':
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
'MWeibo-Pwa': 1,
'X-Requested-With': 'XMLHttpRequest',
},
Expand All @@ -24,6 +28,10 @@ let deal = async (ctx) => {
const cards = await fetch(`https://m.weibo.cn/api/container/getIndex?type=uid&value=${uid}&containerid=${containerId}`, {
headers: {
Referer: `https://m.weibo.cn/u/${uid}`,
Cookie: ctx.env.WEIBO_COOKIE || '',
Accept: 'application/json, text/plain, */*',
'User-Agent':
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
'MWeibo-Pwa': 1,
'X-Requested-With': 'XMLHttpRequest',
},
Expand All @@ -40,7 +48,7 @@ let deal = async (ctx) => {
// TODO: getShowData() on demand? The API seems to return most things we need since 2022/05/21.
// Need more investigation, pending for now since the current version works fine.
// const data = await ctx.cache.tryGet(key, () => weiboUtils.getShowData(uid, item.mblog.bid));
const data = await weiboUtils.getShowData(uid, item.mblog.bid);
const data = await weiboUtils.getShowData(ctx, uid, item.mblog.bid);

if (data && data.text) {
item.mblog.text = data.text;
Expand All @@ -60,7 +68,7 @@ let deal = async (ctx) => {
// const retweetData = await ctx.cache.tryGet(`weibo:retweeted:${retweet.user.id}:${retweet.bid}`, () =>
// weiboUtils.getShowData(retweet.user.id, retweet.bid)
// );
const retweetData = await weiboUtils.getShowData(retweet.user.id, retweet.bid);
const retweetData = await weiboUtils.getShowData(ctx, retweet.user.id, retweet.bid);
if (retweetData !== undefined && retweetData.text) {
item.mblog.retweeted_status.text = retweetData.text;
}
Expand Down Expand Up @@ -99,7 +107,7 @@ let deal = async (ctx) => {
description,
isPinned: item.profile_type_id?.startsWith('proweibotop'),
};
})
}),
);

// remove pinned weibo if they are too old (older than all the rest weibo)
Expand Down
15 changes: 9 additions & 6 deletions src/lib/weibo/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ const weiboUtils = {
if (!showEmojiInDescription) {
htmlNewLineUnreplaced = htmlNewLineUnreplaced.replace(
/<span class=["']?url-icon["']?><img\s[^>]*?alt=["']?([^>]+?)["']?\s[^>]*?\/><\/span>/g,
'$1'
'$1',
);
}
// 去掉链接的图标,保留 a 标签链接
if (!showLinkIconInDescription) {
htmlNewLineUnreplaced = htmlNewLineUnreplaced.replace(
/(<a\s[^>]*>)<span class=["']?url-icon["']?><img\s[^>]*><\/span>[^<>]*?<span class=["']?surl-text["']?>([^<>]*?)<\/span><\/a>/g,
'$1$2</a>'
'$1$2</a>',
);
}
// 去掉乱七八糟的图标 // 不需要,上述的替换应该已经把所有的图标都替换掉了,且这条 regex 会破坏上述替换不发生时的输出
Expand All @@ -80,7 +80,7 @@ const weiboUtils = {

// 处理外部链接
htmlNewLineUnreplaced = htmlNewLineUnreplaced.replace(/https:\/\/weibo\.cn\/sinaurl\/.*?&u=(http.*?")/g, (match, p1) =>
decodeURIComponent(p1)
decodeURIComponent(p1),
);

let html = htmlNewLineUnreplaced.replace(/\n/g, '<br>');
Expand Down Expand Up @@ -130,7 +130,7 @@ const weiboUtils = {

// drop live photo
const livePhotoCount = status.pics ? status.pics.filter((pic) => pic.type === 'livephotos').length : 0;
const pics = status.pics && status.pics.filter((pic) => (pic.type !== 'livephotos') && (pic.type !== 'livephoto'));
const pics = status.pics && status.pics.filter((pic) => pic.type !== 'livephotos' && pic.type !== 'livephoto');

// 添加微博配图
if (pics) {
Expand Down Expand Up @@ -246,13 +246,14 @@ const weiboUtils = {

return { description: html, title, link, guid, author, pubDate };
},
getShowData: async (uid, bid) => {
getShowData: async (ctx, uid, bid) => {
const link = `https://m.weibo.cn/statuses/show?id=${bid}`;
const itemResponse = await fetch(link, {
headers: {
Referer: `https://m.weibo.cn/u/${uid}`,
'MWeibo-Pwa': 1,
'X-Requested-With': 'XMLHttpRequest',
Cookie: ctx.env.WEIBO_COOKIE || '',
'User-Agent':
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
},
Expand Down Expand Up @@ -325,6 +326,7 @@ const weiboUtils = {
const response = await fetch(link, {
headers: {
Referer: `https://card.weibo.com/article/m/show/id/${articleId}`,
Cookie: ctx.env.WEIBO_COOKIE || '',
'MWeibo-Pwa': 1,
'X-Requested-With': 'XMLHttpRequest',
'User-Agent':
Expand Down Expand Up @@ -383,7 +385,7 @@ const weiboUtils = {
element: (elem) => {
elem.setAttribute(
'style',
'display: table;text-align: center;margin-left: auto;margin-right: auto;clear: both;min-width: 50px;'
'display: table;text-align: center;margin-left: auto;margin-right: auto;clear: both;min-width: 50px;',
);
},
})
Expand All @@ -409,6 +411,7 @@ const weiboUtils = {
const response = await fetch(link, {
headers: {
Referer: `https://m.weibo.cn/detail/${id}`,
Cookie: ctx.env.WEIBO_COOKIE || '',
'MWeibo-Pwa': 1,
'X-Requested-With': 'XMLHttpRequest',
'User-Agent':
Expand Down
4 changes: 2 additions & 2 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "rss-worker"
main = "src/worker.js"
node_compat = true
compatibility_date = "2023-09-22"
compatibility_date = "2024-09-23"
compatibility_flags = ["nodejs_compat"]

# [build]
# command = "npm run build"
Expand Down