This repository has been archived by the owner on Apr 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (57 loc) · 2.02 KB
/
main.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Import modules
import os
from sys import int_info
from typing import Optional
from fastapi import FastAPI
from dotenv import load_dotenv
import requests
# Load env variables
load_dotenv()
# Create FastAPI app
app = FastAPI()
# Declare global variables
headers = {
'Accept': 'application/json',
'x-api-key': os.environ['API_KEY']
}
url = 'https://api.curseforge.com'
# API listners
@app.get('/')
def read_root():
return {'Hello': 'Welcome to the Curseforge Relay API!'}
@app.get('/getGame/{gameId}')
def getGameAPI(gameId: int):
getGame = requests.get(f'{url}/v1/games/{gameId}', headers = headers)
return getGame.json()
@app.get('/getModloader')
def getModloaderAPI():
getModloader = requests.get(f'{url}/v1/minecraft/modloader', headers = headers)
return getModloader.json()
@app.get('/getMod/{modId}')
def getModAPI(modId: int):
getMod = requests.get(f'{url}/v1/mods/{modId}', headers = headers)
return getMod.json()
@app.get('/getVersions/{gameId}')
def getVersionsAPI(gameId: int):
getVersions = requests.get(f'{url}/v1/games/{gameId}/versions', headers = headers)
return getVersions.json()
@app.get('/searchMods')
def searchModsAPI(gameId = 432, classId = None, gameVersion = '1.18.2', searchFilter = None, sortField = None, sortOrder = None, modLoaderType = 4, gameVersionTypeId = None, slug = None, index = None, pageSize = None):
searchMods = requests.get(f'{url}/v1/mods/search', params= {
'gameId': gameId,
'classID': classId,
'gameVersion': gameVersion,
'searchFilter': searchFilter,
'sortField': sortField,
'sortOrder': sortOrder,
'modLoaderType': modLoaderType,
'gameVersionTypeId': gameVersionTypeId,
'slug': slug,
'index': index,
'pageSize': pageSize
}, headers = headers)
return searchMods.json()
@app.get('/getModDownloadURL/{modId}/{fileId}')
def getModDownloadURLAPI(modId: int, fileId: int):
getModDownloadURL = requests.get(f'{url}/v1/mods/{modId}/files/{fileId}/download-url', headers = headers)
return getModDownloadURL.json()