Team Ai
Apppublic

cosmoEagle/leetcode-api

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
fetchDataRawFormat.ts40 linesDownload Raw Back to Controllers
1import { Response } from 'express';2 3const fetchDataRawFormat = async (4    options: { username: string },5    res: Response,6    query: string7) => {8    try {9 10        const response = await fetch('https://leetcode.com/graphql', {11            method: 'POST',12            headers: {13                'Content-Type': 'application/json',14                Referer: 'https://leetcode.com',15            },16            body: JSON.stringify({17                query: query,18                variables: {19                    username: options.username, 20                },21            }),22        });23        24        const result = await response.json();25        if (!response.ok) {26            console.error(`HTTP error! status: ${response.status}`);27        }28        if (result.errors) {29            return res.send(result);30        }31 32        return res.json(result.data);33    } catch (err) {34        console.error('Error: ', err);35        return res.send(err);36    }37};38 39export default fetchDataRawFormat;40