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
|
import { z } from "zod";
import {
zCreateImportSessionRequestSchema,
zDeleteImportSessionRequestSchema,
zGetImportSessionStatsRequestSchema,
zImportSessionWithStatsSchema,
zListImportSessionsRequestSchema,
zListImportSessionsResponseSchema,
} from "@karakeep/shared/types/importSessions";
import { authedProcedure, router } from "../index";
import { ImportSession } from "../models/importSessions";
export const importSessionsRouter = router({
createImportSession: authedProcedure
.input(zCreateImportSessionRequestSchema)
.output(z.object({ id: z.string() }))
.mutation(async ({ input, ctx }) => {
const session = await ImportSession.create(ctx, input);
return { id: session.session.id };
}),
getImportSessionStats: authedProcedure
.input(zGetImportSessionStatsRequestSchema)
.output(zImportSessionWithStatsSchema)
.query(async ({ input, ctx }) => {
const session = await ImportSession.fromId(ctx, input.importSessionId);
return await session.getWithStats();
}),
listImportSessions: authedProcedure
.input(zListImportSessionsRequestSchema)
.output(zListImportSessionsResponseSchema)
.query(async ({ ctx }) => {
const sessions = await ImportSession.getAllWithStats(ctx);
return { sessions };
}),
deleteImportSession: authedProcedure
.input(zDeleteImportSessionRequestSchema)
.output(z.object({ success: z.boolean() }))
.mutation(async ({ input, ctx }) => {
const session = await ImportSession.fromId(ctx, input.importSessionId);
await session.delete();
return { success: true };
}),
});
|