|
| 1 | +# LeetCode Daily Challenge Worker |
| 2 | + |
| 3 | +This is a Cloudflare worker that runs daily at 0:10 UTC-0. Its function is to fetch the daily challenge from LeetCode using the LeetCode GraphQL API. Then, it processes the data and sends it in Markdown format to an endpoint defined in the `ENDPOINT` environment variable. In our case, this endpoint corresponds to a Discord bot that creates a discussion thread where users can debate solutions and approaches to solve the daily challenge. |
| 4 | + |
| 5 | +## How It Works |
| 6 | + |
| 7 | +1. The worker is automatically activated at 0:10 UTC-0 thanks to a scheduled trigger in Cloudflare. |
| 8 | +2. A call is made to the LeetCode GraphQL API to get the details of the daily challenge. |
| 9 | +3. The challenge data is processed and converted to Markdown format. |
| 10 | +4. A POST request is sent to the API defined in the `ENDPOINT` environment variable with the challenge data in Markdown format. |
| 11 | +5. In our case, the `ENDPOINT` corresponds to a Discord bot that creates a discussion thread with the details of the challenge. |
| 12 | + |
| 13 | +## Configuration |
| 14 | + |
| 15 | +### Requirements |
| 16 | + |
| 17 | +To build and deploy this project, you will need the following: |
| 18 | + |
| 19 | +- [Rust](https://rust-lang.org) |
| 20 | +- [wrangler](https://developers.cloudflare.com/workers/wrangler/install-and-update/) |
| 21 | +- [worker-build](https://crates.io/crates/worker-build) |
| 22 | + - [wasm-pack](https://rustwasm.github.io/wasm-pack/) |
| 23 | + |
| 24 | +### Environment Variables |
| 25 | + |
| 26 | +- `ENDPOINT`: URL of the endpoint where the daily challenge data will be sent. |
| 27 | + |
| 28 | +### Local Testing |
| 29 | + |
| 30 | +To test the worker locally, you only need to configure the `ENDPOINT` environment variable in the `wrangler.toml` file. This is only necessary if you want to use a different endpoint than the one already configured. |
| 31 | + |
| 32 | +### Automatic Deployment |
| 33 | + |
| 34 | +This project is configured to deploy automatically using GitHub Actions workflows. For it to work correctly, you must configure the following secrets in GitHub: |
| 35 | + |
| 36 | +- `CLOUDFLARE_ACCOUNT_ID`: Your Cloudflare account ID. |
| 37 | +- `CLOUDFLARE_API_TOKEN`: Your Cloudflare API token. |
| 38 | +- `ENDPOINT`: URL of the API to which the daily challenge data will be sent. |
0 commit comments