mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
Add the option to serve static files with the http server
This commit is contained in:
parent
3dea3a7f3d
commit
db8ce9b7f4
2 changed files with 18 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ targets.json
|
||||||
*.kdev4
|
*.kdev4
|
||||||
.env
|
.env
|
||||||
*.pyc
|
*.pyc
|
||||||
|
web/static
|
|
@ -4,6 +4,7 @@ import sys
|
||||||
import discord
|
import discord
|
||||||
import os
|
import os
|
||||||
import httpx
|
import httpx
|
||||||
|
from pathlib import Path
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from hashlib import sha512
|
from hashlib import sha512
|
||||||
|
|
||||||
|
@ -13,20 +14,34 @@ from http import HTTPStatus
|
||||||
from utils import Student, get_or_none, VerifyCode, console, BannedStudentID
|
from utils import Student, get_or_none, VerifyCode, console, BannedStudentID
|
||||||
from config import guilds
|
from config import guilds
|
||||||
|
|
||||||
|
SF_ROOT = Path(__file__).parent / "static"
|
||||||
|
if SF_ROOT.exists() and SF_ROOT.is_dir():
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
else:
|
||||||
|
StaticFiles = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from config import OAUTH_ID, OAUTH_SECRET, OAUTH_REDIRECT_URI
|
from config import OAUTH_ID, OAUTH_SECRET, OAUTH_REDIRECT_URI
|
||||||
except ImportError:
|
except ImportError:
|
||||||
OAUTH_ID = OAUTH_SECRET = OAUTH_REDIRECT_URI = None
|
OAUTH_ID = OAUTH_SECRET = OAUTH_REDIRECT_URI = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
from config import WEB_ROOT_PATH
|
||||||
|
except ImportError:
|
||||||
|
WEB_ROOT_PATH = ""
|
||||||
|
|
||||||
GENERAL = "https://ptb.discord.com/channels/994710566612500550/1018915342317277215/"
|
GENERAL = "https://ptb.discord.com/channels/994710566612500550/1018915342317277215/"
|
||||||
|
|
||||||
OAUTH_ENABLED = OAUTH_ID and OAUTH_SECRET and OAUTH_REDIRECT_URI
|
OAUTH_ENABLED = OAUTH_ID and OAUTH_SECRET and OAUTH_REDIRECT_URI
|
||||||
|
|
||||||
app = FastAPI(root_path="/jimmy")
|
app = FastAPI(root_path=WEB_ROOT_PATH)
|
||||||
app.state.bot = None
|
app.state.bot = None
|
||||||
app.state.states = {}
|
app.state.states = {}
|
||||||
app.state.http = httpx.Client()
|
app.state.http = httpx.Client()
|
||||||
|
|
||||||
|
if StaticFiles:
|
||||||
|
app.mount("/static", StaticFiles(directory=SF_ROOT), name="static")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from utils.client import bot
|
from utils.client import bot
|
||||||
app.state.bot = bot
|
app.state.bot = bot
|
||||||
|
|
Loading…
Reference in a new issue