Skip to content

Commit 7058f69

Browse files
committed
feat: 支持更新全部
1 parent a9421f4 commit 7058f69

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

apps/server/src/trpc/trpc.router.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,17 @@ export class TrpcRouter {
241241
}),
242242

243243
refreshArticles: this.trpcService.protectedProcedure
244-
.input(z.string())
245-
.mutation(async ({ input: mpId }) => {
246-
await this.trpcService.refreshMpArticlesAndUpdateFeed(mpId);
244+
.input(
245+
z.object({
246+
mpId: z.string().optional(),
247+
}),
248+
)
249+
.mutation(async ({ input: { mpId } }) => {
250+
if (mpId) {
251+
await this.trpcService.refreshMpArticlesAndUpdateFeed(mpId);
252+
} else {
253+
await this.trpcService.refreshAllMpArticlesAndUpdateFeed();
254+
}
247255
}),
248256
});
249257

apps/server/src/trpc/trpc.service.ts

+9
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ export class TrpcService {
203203
});
204204
}
205205

206+
async refreshAllMpArticlesAndUpdateFeed() {
207+
const mps = await this.prismaService.feed.findMany();
208+
209+
for (const { id } of mps) {
210+
await this.refreshMpArticlesAndUpdateFeed(id);
211+
await new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
212+
}
213+
}
214+
206215
async getMpInfo(url: string) {
207216
url = url.trim();
208217
const account = await this.getAvailableAccount();

apps/web/src/pages/feeds/index.tsx

+22-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const Feeds = () => {
6969
updateTime: item.updateTime,
7070
status: 1,
7171
});
72-
await refreshMpArticles(item.id);
72+
await refreshMpArticles({ mpId: item.id });
7373

7474
toast.success('添加成功', {
7575
description: `公众号 ${item.name}`,
@@ -194,7 +194,7 @@ const Feeds = () => {
194194
</div>
195195
<Divider orientation="vertical" />
196196
<Tooltip
197-
content="频繁调用会导致一段时间内不可用!"
197+
content="频繁调用可能会导致一段时间内不可用"
198198
color="danger"
199199
>
200200
<Link
@@ -204,7 +204,7 @@ const Feeds = () => {
204204
onClick={async (ev) => {
205205
ev.preventDefault();
206206
ev.stopPropagation();
207-
await refreshMpArticles(currentMpInfo.id);
207+
await refreshMpArticles({ mpId: currentMpInfo.id });
208208
await refetchFeedList();
209209
await queryUtils.article.list.reset();
210210
}}
@@ -269,6 +269,25 @@ const Feeds = () => {
269269
</div>
270270
) : (
271271
<div className="flex gap-2">
272+
<Tooltip
273+
content="频繁调用可能会导致一段时间内不可用"
274+
color="danger"
275+
>
276+
<Link
277+
size="sm"
278+
href="#"
279+
isDisabled={isGetArticlesLoading}
280+
onClick={async (ev) => {
281+
ev.preventDefault();
282+
ev.stopPropagation();
283+
await refreshMpArticles({});
284+
await refetchFeedList();
285+
await queryUtils.article.list.reset();
286+
}}
287+
>
288+
{isGetArticlesLoading ? '更新中...' : '更新全部'}
289+
</Link>
290+
</Tooltip>
272291
<Link
273292
href="#"
274293
color="foreground"

0 commit comments

Comments
 (0)