From bf0ac860dab879037597cc594f7e041bbccb1d5c Mon Sep 17 00:00:00 2001 From: Surmon Date: Wed, 2 Oct 2024 09:43:58 +0700 Subject: [PATCH] feat: Use `Threads` instead of `ZhiHu` --- .vscode/settings.json | 3 +- CHANGELOG.md | 7 ++ package.json | 2 +- src/bff.ts | 47 +++++---- src/config/app.config.ts | 4 +- src/config/bff.yargs.ts | 1 - src/constants/tunnel.ts | 2 +- src/pages/index/threads.vue | 2 +- src/pages/snippets/card.vue | 95 ------------------ src/pages/snippets/desktop/index.vue | 67 +++++-------- src/pages/snippets/desktop/masonry.vue | 19 ++-- src/pages/snippets/detail.vue | 101 ------------------- src/pages/snippets/mobile/index.vue | 74 +++++--------- src/pages/snippets/shared.ts | 45 --------- src/pages/snippets/threads/card.vue | 130 +++++++++++++++++++++++++ src/pages/snippets/threads/detail.vue | 28 ++++++ src/pages/snippets/threads/shared.ts | 44 +++++++++ src/server/getters/threads/index.ts | 2 +- src/server/getters/threads/post.ts | 24 ++++- src/server/getters/zhihu.ts | 114 ---------------------- src/stores/_hook.ts | 2 - src/stores/media.ts | 12 --- src/transforms/media.ts | 4 - 23 files changed, 319 insertions(+), 510 deletions(-) delete mode 100644 src/pages/snippets/card.vue delete mode 100644 src/pages/snippets/detail.vue create mode 100644 src/pages/snippets/threads/card.vue create mode 100644 src/pages/snippets/threads/detail.vue create mode 100644 src/pages/snippets/threads/shared.ts delete mode 100644 src/server/getters/zhihu.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 6ac5e03f..2defe781 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "typescript.tsdk": "node_modules/typescript/lib", "editor.defaultFormatter": "esbenp.prettier-vscode", - "editor.formatOnSave": true + "editor.formatOnSave": true, + "files.autoSave": "off" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ab7b9f3..3509abb5 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +### v4.49.0 (2024-10-02) + +**Feature** + +- Use `Threads` instead of `ZhiHu`. +- Use `snippets` page instead of `answers` page. + ### v4.46.0 (2024-09-27) **Feature** diff --git a/package.json b/package.json index 675f54df..2d28e908 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "surmon.me", - "version": "4.48.0", + "version": "4.49.0", "description": "Surmon.me blog", "author": "Surmon", "license": "MIT", diff --git a/src/bff.ts b/src/bff.ts index 141d2c5d..096ddea1 100644 --- a/src/bff.ts +++ b/src/bff.ts @@ -15,7 +15,12 @@ import { getSitemapXml } from './server/getters/sitemap' import { getGTagScript } from './server/getters/gtag' import { getAllWallpapers } from './server/getters/wallpaper' import { getMyGoogleMap } from './server/getters/my-google-map' -import { getThreadsProfile, getThreadsMedias, getThreadsMediaChildren } from './server/getters/threads' +import { + getThreadsProfile, + getThreadsMedias, + getThreadsMediaChildren, + getThreadsMediaConversation +} from './server/getters/threads' import { getInstagramProfile, getInstagramMedias, @@ -26,7 +31,6 @@ import { getYouTubeChannelPlayLists, getYouTubeVideoListByPlayerListId } from '. import { getGitHubStatistic, getGitHubSponsors, getGitHubContributions } from './server/getters/github' import { getNPMStatistic } from './server/getters/npm' import { getDoubanMovies } from './server/getters/douban' -import { getZhihuAnswers } from './server/getters/zhihu' import { getSongList } from './server/getters/netease-music' import { getWebFont, WebFontContentType } from './server/getters/webfont' import { enableDevRenderer } from './server/renderer/dev' @@ -109,28 +113,6 @@ createExpressApp().then(async ({ app, server, cache }) => { responser(() => get163MusicCache()) ) - // Zhihu first page cache - const getZhihuFirstPageCache = cacher.interval(cache, { - key: 'zhihu_answers_offset_0', - ttl: hours(12), - interval: hours(3), - retry: minutes(10), - getter: getZhihuAnswers - }) - - // Zhihu answer route - app.get(`${TUN}/${TunnelModule.ZhihuAnswers}`, (request, response, next) => { - const offset = request.query.offset - if (!!offset && !Number.isInteger(Number(offset))) { - errorer(response, { code: BAD_REQUEST, message: 'Invalid params' }) - return - } - - responser(() => { - return offset ? getZhihuAnswers(Number(offset)) : getZhihuFirstPageCache() - })(request, response, next) - }) - // Threads profile const getThreadsProfileCache = cacher.interval(cache, { key: TunnelModule.ThreadsProfile, @@ -190,6 +172,23 @@ createExpressApp().then(async ({ app, server, cache }) => { })(request, response, next) }) + // Threads media conversation + app.get(`${TUN}/${TunnelModule.ThreadsMediaConversation}`, (request, response, next) => { + const mediaId = request.query.id + if (!mediaId || typeof mediaId !== 'string') { + errorer(response, { code: BAD_REQUEST, message: 'Invalid params' }) + return + } + + responser(() => { + return cacher.passive(cache, { + key: `threads_media_conversation_${mediaId}`, + ttl: days(7), + getter: () => getThreadsMediaConversation(mediaId) + }) + })(request, response, next) + }) + // Instagram profile app.get( `${TUN}/${TunnelModule.InstagramProfile}`, diff --git a/src/config/app.config.ts b/src/config/app.config.ts index a11e2b03..bdb14f20 100755 --- a/src/config/app.config.ts +++ b/src/config/app.config.ts @@ -44,7 +44,6 @@ export const IDENTITIES = Object.freeze({ YOUTUBE_CHANNEL_SHORT_ID: '@surmon_v', MUSIC_163_BGM_ALBUM_ID: '638949385', DOUBAN_USER_ID: '56647958', - ZHIHU_USER_NAME: 'surmon', GITHUB_USER_NAME: 'surmon-china', INSTAGRAM_USERNAME: 'surmon666', THREADS_USER_NAME: 'surmon666', @@ -73,8 +72,7 @@ export const VALUABLE_LINKS = Object.freeze({ YOUTUBE_CHANNEL: `https://www.youtube.com/${IDENTITIES.YOUTUBE_CHANNEL_SHORT_ID}`, TELEGRAM: 'https://t.me/surmon', OPENSEA: 'https://opensea.io/Surmon', - ZHIHU: `https://www.zhihu.com/people/${IDENTITIES.ZHIHU_USER_NAME}/answers`, - QUORA: `https://www.quora.com/profile/Surmon/answers`, + ZHIHU: `https://www.zhihu.com/people/surmon/answers`, DOUBAN: 'https://www.douban.com/people/nocower', DOUBAN_MOVIE: `https://movie.douban.com/people/nocower/collect`, LINKEDIN: 'https://www.linkedin.com/in/surmon', diff --git a/src/config/bff.yargs.ts b/src/config/bff.yargs.ts index b1c72706..91770f32 100644 --- a/src/config/bff.yargs.ts +++ b/src/config/bff.yargs.ts @@ -10,4 +10,3 @@ const argv = yargs(process.argv.slice(2)).argv export const YOUTUBE_API_KEY = argv.youtube_token export const INSTAGRAM_TOKEN = argv.instagram_token export const THREADS_TOKEN = argv.threads_token -export const ZHIHU_COOKIE = argv.zhihu_cookie diff --git a/src/constants/tunnel.ts b/src/constants/tunnel.ts index 232ea6db..aab866c3 100644 --- a/src/constants/tunnel.ts +++ b/src/constants/tunnel.ts @@ -12,6 +12,7 @@ export enum TunnelModule { ThreadsProfile = 'threads_profile', ThreadsMedias = 'threads_medias', ThreadsMediaChildren = 'threads_media_children', + ThreadsMediaConversation = 'threads_media_conversation', InstagramProfile = 'instagram_profile', InstagramMedias = 'instagram_medias', InstagramMediaChildren = 'instagram_media_children', @@ -19,7 +20,6 @@ export enum TunnelModule { BingWallpaper = 'bing_wallpaper', NetEaseMusic = 'netease_music', DoubanMovies = 'douban_movies', - ZhihuAnswers = 'zhihu_answers', GitHubSponsors = 'github_sponsors', GitHubContributions = 'github_contributions', StatisticGitHubJson = 'statistic_github_json', diff --git a/src/pages/index/threads.vue b/src/pages/index/threads.vue index 0936428e..840a31fd 100755 --- a/src/pages/index/threads.vue +++ b/src/pages/index/threads.vue @@ -59,7 +59,7 @@

- +

diff --git a/src/pages/snippets/card.vue b/src/pages/snippets/card.vue deleted file mode 100644 index d796196f..00000000 --- a/src/pages/snippets/card.vue +++ /dev/null @@ -1,95 +0,0 @@ - - - - - diff --git a/src/pages/snippets/desktop/index.vue b/src/pages/snippets/desktop/index.vue index c547758a..1ab0efba 100644 --- a/src/pages/snippets/desktop/index.vue +++ b/src/pages/snippets/desktop/index.vue @@ -1,61 +1,45 @@