Skip to content

Commit

Permalink
feat: 支持更新全部
Browse files Browse the repository at this point in the history
  • Loading branch information
cooderl committed Mar 26, 2024
1 parent a9421f4 commit 7058f69
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
14 changes: 11 additions & 3 deletions apps/server/src/trpc/trpc.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}),
});

Expand Down
9 changes: 9 additions & 0 deletions apps/server/src/trpc/trpc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
25 changes: 22 additions & 3 deletions apps/web/src/pages/feeds/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down Expand Up @@ -194,7 +194,7 @@ const Feeds = () => {
</div>
<Divider orientation="vertical" />
<Tooltip
content="频繁调用会导致一段时间内不可用!"
content="频繁调用可能会导致一段时间内不可用"
color="danger"
>
<Link
Expand All @@ -204,7 +204,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();
}}
Expand Down Expand Up @@ -269,6 +269,25 @@ const Feeds = () => {
</div>
) : (
<div className="flex gap-2">
<Tooltip
content="频繁调用可能会导致一段时间内不可用"
color="danger"
>
<Link
size="sm"
href="#"
isDisabled={isGetArticlesLoading}
onClick={async (ev) => {
ev.preventDefault();
ev.stopPropagation();
await refreshMpArticles({});
await refetchFeedList();
await queryUtils.article.list.reset();
}}
>
{isGetArticlesLoading ? '更新中...' : '更新全部'}
</Link>
</Tooltip>
<Link
href="#"
color="foreground"
Expand Down

0 comments on commit 7058f69

Please sign in to comment.