From 7058f6986de6df66cd4aba31d1df38deddd194f4 Mon Sep 17 00:00:00 2001 From: cooder Date: Tue, 26 Mar 2024 12:43:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=85=A8=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/server/src/trpc/trpc.router.ts | 14 +++++++++++--- apps/server/src/trpc/trpc.service.ts | 9 +++++++++ apps/web/src/pages/feeds/index.tsx | 25 ++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/apps/server/src/trpc/trpc.router.ts b/apps/server/src/trpc/trpc.router.ts index 63dcf29..417b5fd 100644 --- a/apps/server/src/trpc/trpc.router.ts +++ b/apps/server/src/trpc/trpc.router.ts @@ -241,9 +241,17 @@ export class TrpcRouter { }), refreshArticles: this.trpcService.protectedProcedure - .input(z.string()) - .mutation(async ({ input: mpId }) => { - await this.trpcService.refreshMpArticlesAndUpdateFeed(mpId); + .input( + z.object({ + mpId: z.string().optional(), + }), + ) + .mutation(async ({ input: { mpId } }) => { + if (mpId) { + await this.trpcService.refreshMpArticlesAndUpdateFeed(mpId); + } else { + await this.trpcService.refreshAllMpArticlesAndUpdateFeed(); + } }), }); diff --git a/apps/server/src/trpc/trpc.service.ts b/apps/server/src/trpc/trpc.service.ts index 5ead608..e6fbaab 100644 --- a/apps/server/src/trpc/trpc.service.ts +++ b/apps/server/src/trpc/trpc.service.ts @@ -203,6 +203,15 @@ export class TrpcService { }); } + async refreshAllMpArticlesAndUpdateFeed() { + const mps = await this.prismaService.feed.findMany(); + + for (const { id } of mps) { + await this.refreshMpArticlesAndUpdateFeed(id); + await new Promise((resolve) => setTimeout(resolve, 10 * 1e3)); + } + } + async getMpInfo(url: string) { url = url.trim(); const account = await this.getAvailableAccount(); diff --git a/apps/web/src/pages/feeds/index.tsx b/apps/web/src/pages/feeds/index.tsx index f59d4d2..39f6c35 100644 --- a/apps/web/src/pages/feeds/index.tsx +++ b/apps/web/src/pages/feeds/index.tsx @@ -69,7 +69,7 @@ const Feeds = () => { updateTime: item.updateTime, status: 1, }); - await refreshMpArticles(item.id); + await refreshMpArticles({ mpId: item.id }); toast.success('添加成功', { description: `公众号 ${item.name}`, @@ -194,7 +194,7 @@ const Feeds = () => { { onClick={async (ev) => { ev.preventDefault(); ev.stopPropagation(); - await refreshMpArticles(currentMpInfo.id); + await refreshMpArticles({ mpId: currentMpInfo.id }); await refetchFeedList(); await queryUtils.article.list.reset(); }} @@ -269,6 +269,25 @@ const Feeds = () => { ) : (
+ + { + ev.preventDefault(); + ev.stopPropagation(); + await refreshMpArticles({}); + await refetchFeedList(); + await queryUtils.article.list.reset(); + }} + > + {isGetArticlesLoading ? '更新中...' : '更新全部'} + +