Compare commits

..

4 Commits

Author SHA1 Message Date
71e1d3b335 Update command 2023-03-26 08:53:16 +02:00
93c062eadf Fix error when using python 3.9 2023-03-26 08:53:01 +02:00
ea7409556a Add proxy headers 2023-03-26 08:52:35 +02:00
23cfbe6bc0 remove .gitea/workflows 2023-03-26 08:52:15 +02:00
5 changed files with 7 additions and 44 deletions

View File

@ -1,19 +0,0 @@
# .gitea/workflows/build.yaml
name: Gitea Actions Demo
run-name: ${{ github.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
Explore-Gitea-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."

View File

@ -1,19 +0,0 @@
name: Docker Image CI
on:
push:
branches: [ main ]
jobs:
compile:
name: Build and run the container
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build
uses: docker/build-push-action@v2
with:
push: false

View File

@ -10,4 +10,4 @@ RUN apk add --no-cache --update libmagic \
COPY . . COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] CMD ["uvicorn", "main:app", "--host", "127.0.0.1", "--port", "8000", "--proxy-headers"]

View File

@ -20,7 +20,7 @@ source venv/bin/activate
pip install -r requirements.txt pip install -r requirements.txt
# Run the project # Run the project
uvicorn main:app --host 0.0.0.0 --port 8000 uvicorn main:app --host 127.0.0.1 --port 8000 --proxy-headers
``` ```
### Docker ### Docker

View File

@ -1,4 +1,5 @@
import shutil, magic, re import shutil, magic, re
from typing import Annotated, Union
from os import listdir, remove from os import listdir, remove
from os.path import abspath, dirname, exists from os.path import abspath, dirname, exists
from fastapi import FastAPI, Request, UploadFile, File, Header from fastapi import FastAPI, Request, UploadFile, File, Header
@ -56,7 +57,7 @@ app.mount("/static", StaticFiles(directory="static"), name='static')
# show the homepage when just getting the website # show the homepage when just getting the website
@app.get("/", response_class=HTMLResponse) @app.get("/", response_class=HTMLResponse)
async def index(request: Request, user_agent: str | None = Header(default=None)): async def index(request: Request, user_agent: Annotated[Union[str, None], Header()] = None):
if re.search("^curl/.*", str(user_agent)): if re.search("^curl/.*", str(user_agent)):
return PlainTextResponse("It fucking works!\n") return PlainTextResponse("It fucking works!\n")
else: else:
@ -66,7 +67,7 @@ async def index(request: Request, user_agent: str | None = Header(default=None))
# get the file user want's to upload and save it # get the file user want's to upload and save it
@app.post("/") @app.post("/")
async def upload( request: Request, file: UploadFile = File(...), user_agent: str | None = Header(default=None)): async def upload( request: Request, file: UploadFile = File(...), user_agent: Annotated[Union[str, None], Header()] = None):
file_location = f"upload/{file.filename}" file_location = f"upload/{file.filename}"
if exists(file_location): if exists(file_location):
context = f'''File: "{request.url._url}files/{file.filename}" already exists on the server! context = f'''File: "{request.url._url}files/{file.filename}" already exists on the server!
@ -82,7 +83,7 @@ Please rename the file or delete the one on the server\n'''
# show the files page with the list of all files or if run with curl list all files in url format # show the files page with the list of all files or if run with curl list all files in url format
@app.get("/files") @app.get("/files")
async def files( request: Request, user_agent: str | None = Header(default=None)): async def files( request: Request, user_agent: Annotated[Union[str, None], Header()] = None):
path = f"{dirname(abspath(__file__))}/upload/" path = f"{dirname(abspath(__file__))}/upload/"
file_list = listdir(path) file_list = listdir(path)
files = file_list_generator(path, file_list) files = file_list_generator(path, file_list)
@ -98,7 +99,7 @@ async def files( request: Request, user_agent: str | None = Header(default=None)
# delete specific file when getting this request # delete specific file when getting this request
@app.get("/delete/{file}") @app.get("/delete/{file}")
async def delete(request: Request, file: str, user_agent: str | None = Header(default=None)): async def delete(request: Request, file: str, user_agent: Annotated[Union[str, None], Header()] = None):
file_path = f"{dirname(abspath(__file__))}/upload/{file}" file_path = f"{dirname(abspath(__file__))}/upload/{file}"
if exists(file_path): if exists(file_path):
remove(file_path) remove(file_path)