MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / handler

Function handler

apps/web/pages/api/integration-oauth.ts:61–104  ·  view source on GitHub ↗
(
  request: NextApiRequest,
  response: NextApiResponse
)

Source from the content-addressed store, hash-verified

59}
60
61export default async function handler(
62 request: NextApiRequest,
63 response: NextApiResponse
64) {
65 if (request.method === 'OPTIONS') {
66 return preflight(request, response, ['GET']);
67 }
68 cors(request, response);
69
70 const schema = z.object({
71 community: z.enum(['discord', 'slack']),
72 accountId: z.string().uuid(),
73 syncOpt: z.enum(['since-all', 'since-date']).optional(),
74 dateFrom: z.string().optional(),
75 });
76
77 const body = schema.parse(request.query);
78
79 const permissions = await PermissionsService.get({
80 request,
81 response,
82 params: {
83 communityId: body.accountId,
84 },
85 });
86 if (!permissions.manage) {
87 throw new Error('Unauthorized');
88 }
89
90 if (body.syncOpt === 'since-date' && body.dateFrom) {
91 const syncFrom = new Date(body.dateFrom);
92
93 if (body.community === 'slack') {
94 await handleSlack({ accountId: body.accountId, syncFrom });
95 }
96 if (body.community === 'discord') {
97 await handleDiscord({ accountId: body.accountId, syncFrom });
98 }
99 }
100
101 return response.json({
102 url: integrationAuthorizer(body.community, body.accountId),
103 });
104}
105
106async function handleSlack({
107 accountId,

Callers

nothing calls this directly

Calls 6

preflightFunction · 0.90
corsFunction · 0.90
handleSlackFunction · 0.85
handleDiscordFunction · 0.85
integrationAuthorizerFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected