1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
import { z } from "zod";
import { FeedQueue } from "@karakeep/shared-server";
import {
zFeedSchema,
zNewFeedSchema,
zUpdateFeedSchema,
} from "@karakeep/shared/types/feeds";
import { authedProcedure, router } from "../index";
import { Feed } from "../models/feeds";
export const feedsAppRouter = router({
create: authedProcedure
.input(zNewFeedSchema)
.output(zFeedSchema)
.mutation(async ({ input, ctx }) => {
const feed = await Feed.create(ctx, input);
return feed.asPublicFeed();
}),
update: authedProcedure
.input(zUpdateFeedSchema)
.output(zFeedSchema)
.mutation(async ({ input, ctx }) => {
const feed = await Feed.fromId(ctx, input.feedId);
await feed.update(input);
return feed.asPublicFeed();
}),
get: authedProcedure
.input(
z.object({
feedId: z.string(),
}),
)
.output(zFeedSchema)
.query(async ({ ctx, input }) => {
const feed = await Feed.fromId(ctx, input.feedId);
return feed.asPublicFeed();
}),
list: authedProcedure
.output(z.object({ feeds: z.array(zFeedSchema) }))
.query(async ({ ctx }) => {
const feeds = await Feed.getAll(ctx);
return { feeds: feeds.map((f) => f.asPublicFeed()) };
}),
delete: authedProcedure
.input(
z.object({
feedId: z.string(),
}),
)
.mutation(async ({ input, ctx }) => {
const feed = await Feed.fromId(ctx, input.feedId);
await feed.delete();
}),
fetchNow: authedProcedure
.input(z.object({ feedId: z.string() }))
.mutation(async ({ input, ctx }) => {
await Feed.fromId(ctx, input.feedId);
await FeedQueue.enqueue({
feedId: input.feedId,
});
}),
});
|