|
1 | 1 | import { createTRPCRouter, publicProcedure } from '@/server/api/trpc';
|
| 2 | +import axios from 'axios'; |
2 | 3 | import { z } from 'zod';
|
3 | 4 |
|
4 | 5 | export const codeRouter = createTRPCRouter({
|
5 | 6 | compileCode: publicProcedure
|
6 | 7 | .input(
|
7 | 8 | z.object({
|
8 |
| - subjectName: z.string(), |
9 |
| - totalClasses: z.number(), |
10 |
| - attendedClasses: z.number(), |
11 |
| - color: z.string(), |
| 9 | + language: z.number(), |
| 10 | + code: z.string(), |
| 11 | + input: z.string(), |
12 | 12 | }),
|
13 | 13 | )
|
14 |
| - .mutation(async ({ input, ctx }) => { |
| 14 | + .mutation(async ({ input }) => { |
| 15 | + const { language, code, input: customInput } = input; |
| 16 | + const options = { |
| 17 | + method: 'POST', |
| 18 | + url: process.env.SUBMISSIONS_URL, |
| 19 | + params: { base64_encoded: 'true', fields: '*' }, |
| 20 | + headers: { |
| 21 | + 'content-type': 'application/json', |
| 22 | + 'Content-Type': 'application/json', |
| 23 | + 'X-RapidAPI-Key': process.env.RAPIDAPI_KEY, |
| 24 | + 'X-RapidAPI-Host': process.env.RAPIDAPI_HOST, |
| 25 | + }, |
| 26 | + data: { |
| 27 | + language_id: language, |
| 28 | + source_code: btoa(code), |
| 29 | + stdin: btoa(customInput), |
| 30 | + }, |
| 31 | + }; |
| 32 | + |
| 33 | + try { |
| 34 | + const response = await axios.request(options); |
| 35 | + console.log(response.data); |
| 36 | + } catch (error) { |
| 37 | + console.error(error); |
| 38 | + } |
| 39 | + |
15 | 40 | return 'code compiled';
|
16 | 41 | }),
|
17 | 42 | });
|
0 commit comments