From e208774d710eedcb46d215734a46e5b1808da694 Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 22 Feb 2023 04:25:07 -0400 Subject: [PATCH] feat(route): gettr (#11937) --- docs/en/social-media.md | 6 ++++ docs/social-media.md | 6 ++++ lib/v2/gettr/maintainer.js | 3 ++ lib/v2/gettr/radar.js | 13 ++++++++ lib/v2/gettr/router.js | 3 ++ lib/v2/gettr/templates/post.art | 13 ++++++++ lib/v2/gettr/user.js | 56 +++++++++++++++++++++++++++++++++ 7 files changed, 100 insertions(+) create mode 100644 lib/v2/gettr/maintainer.js create mode 100644 lib/v2/gettr/radar.js create mode 100644 lib/v2/gettr/router.js create mode 100644 lib/v2/gettr/templates/post.art create mode 100644 lib/v2/gettr/user.js diff --git a/docs/en/social-media.md b/docs/en/social-media.md index 8a8032145..a5fd65114 100644 --- a/docs/en/social-media.md +++ b/docs/en/social-media.md @@ -138,6 +138,12 @@ Type +## GETTR + +### User timeline + + + ## Instagram ::: warning diff --git a/docs/social-media.md b/docs/social-media.md index 1cbf1a976..82cf1d811 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -472,6 +472,12 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性 +## GETTR + +### 个人时间线 + + + ## iCity ### 用户动态 diff --git a/lib/v2/gettr/maintainer.js b/lib/v2/gettr/maintainer.js new file mode 100644 index 000000000..625e52ce6 --- /dev/null +++ b/lib/v2/gettr/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/user/:id': ['TonyRL'], +}; diff --git a/lib/v2/gettr/radar.js b/lib/v2/gettr/radar.js new file mode 100644 index 000000000..92aa8506d --- /dev/null +++ b/lib/v2/gettr/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'gettr.com': { + _name: 'GETTR', + '.': [ + { + title: '个人时间线', + docs: 'https://docs.rsshub.app/social-media.html#gettr', + source: ['/user/:id'], + target: '/gettr/user/:id', + }, + ], + }, +}; diff --git a/lib/v2/gettr/router.js b/lib/v2/gettr/router.js new file mode 100644 index 000000000..a3bdfa517 --- /dev/null +++ b/lib/v2/gettr/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/user/:id', require('./user')); +}; diff --git a/lib/v2/gettr/templates/post.art b/lib/v2/gettr/templates/post.art new file mode 100644 index 000000000..c5fe082f3 --- /dev/null +++ b/lib/v2/gettr/templates/post.art @@ -0,0 +1,13 @@ +{{ if post.txt }}{{@ post.txt.replace(/\n/g, '
') }}
{{ /if }} + +{{ if post.previmg }}
{{ /if }} + +{{ if post.ttl && post.prevsrc }}{{ post.ttl }}
{{ /if }} + +{{ if post.dsc && post.prevsrc }}{{ post.dsc }}
{{ /if }} + +{{ if post.imgs }} + {{ each post.imgs i }} + + {{ /each }} +{{ /if }} diff --git a/lib/v2/gettr/user.js b/lib/v2/gettr/user.js new file mode 100644 index 000000000..caf89b909 --- /dev/null +++ b/lib/v2/gettr/user.js @@ -0,0 +1,56 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +const actionMap = { + pub_pst: 'Published a post: ', + shares_cm: 'Shared a comment: ', + shares_pst: 'Shared a post: ', +}; + +module.exports = async (ctx) => { + const baseUrl = 'https://gettr.com'; + const apiHost = 'https://api.gettr.com'; + const mediaHost = 'https://media.gettr.com'; + const { id } = ctx.params; + + const { data: posts } = await got(`${apiHost}/u/user/${id}/posts`, { + // headers: { + // version: '2.7.0', + // 'x-app-auth': '{"user": null, "token": null}', + // }, + searchParams: { + offset: 0, + max: 20, + dir: 'fwd', + incl: 'posts|stats|userinfo|shared|liked|pvotes', + fp: 'f_uo', + }, + }); + const userInfo = posts.result.aux.uinf[id]; + + const items = posts.result.data.list.map((post) => { + const title = posts.result.aux.post[post.activity.pstid].txt; + const description = art(path.join(__dirname, 'templates/post.art'), { + post: posts.result.aux.post[post.activity.pstid], + mediaHost, + }); + return { + title: `${actionMap[post.action]} ${title}`, + description, + pubDate: parseDate(post.cdate), + updated: parseDate(post.udate), + link: `${baseUrl}/post/${post.activity.pstid}`, + }; + }); + + ctx.state.data = { + title: `${userInfo.nickname} on Gettr`, + description: userInfo.dsc, + link: `${baseUrl}/user/${id}`, + image: `${mediaHost}/${userInfo.ico}`, + language: 'en', + item: items, + }; +};