Compare commits
No commits in common. "71e1d3b3358e2892f80cfdd05a8217cddc831075" and "7a54f1e629d04654764375920dcde11a21813319" have entirely different histories.
71e1d3b335
...
7a54f1e629
19
.gitea/workflows/build.yaml
Normal file
19
.gitea/workflows/build.yaml
Normal file
@ -0,0 +1,19 @@
|
||||
# .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 }}."
|
19
.gitea/workflows/docker-build.yaml
Normal file
19
.gitea/workflows/docker-build.yaml
Normal file
@ -0,0 +1,19 @@
|
||||
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
|
@ -10,4 +10,4 @@ RUN apk add --no-cache --update libmagic \
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["uvicorn", "main:app", "--host", "127.0.0.1", "--port", "8000", "--proxy-headers"]
|
||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
|
@ -20,7 +20,7 @@ source venv/bin/activate
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Run the project
|
||||
uvicorn main:app --host 127.0.0.1 --port 8000 --proxy-headers
|
||||
uvicorn main:app --host 0.0.0.0 --port 8000
|
||||
```
|
||||
|
||||
### Docker
|
||||
|
9
main.py
9
main.py
@ -1,5 +1,4 @@
|
||||
import shutil, magic, re
|
||||
from typing import Annotated, Union
|
||||
from os import listdir, remove
|
||||
from os.path import abspath, dirname, exists
|
||||
from fastapi import FastAPI, Request, UploadFile, File, Header
|
||||
@ -57,7 +56,7 @@ app.mount("/static", StaticFiles(directory="static"), name='static')
|
||||
|
||||
# show the homepage when just getting the website
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def index(request: Request, user_agent: Annotated[Union[str, None], Header()] = None):
|
||||
async def index(request: Request, user_agent: str | None = Header(default=None)):
|
||||
if re.search("^curl/.*", str(user_agent)):
|
||||
return PlainTextResponse("It fucking works!\n")
|
||||
else:
|
||||
@ -67,7 +66,7 @@ async def index(request: Request, user_agent: Annotated[Union[str, None], Header
|
||||
|
||||
# get the file user want's to upload and save it
|
||||
@app.post("/")
|
||||
async def upload( request: Request, file: UploadFile = File(...), user_agent: Annotated[Union[str, None], Header()] = None):
|
||||
async def upload( request: Request, file: UploadFile = File(...), user_agent: str | None = Header(default=None)):
|
||||
file_location = f"upload/{file.filename}"
|
||||
if exists(file_location):
|
||||
context = f'''File: "{request.url._url}files/{file.filename}" already exists on the server!
|
||||
@ -83,7 +82,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
|
||||
@app.get("/files")
|
||||
async def files( request: Request, user_agent: Annotated[Union[str, None], Header()] = None):
|
||||
async def files( request: Request, user_agent: str | None = Header(default=None)):
|
||||
path = f"{dirname(abspath(__file__))}/upload/"
|
||||
file_list = listdir(path)
|
||||
files = file_list_generator(path, file_list)
|
||||
@ -99,7 +98,7 @@ async def files( request: Request, user_agent: Annotated[Union[str, None], Heade
|
||||
|
||||
# delete specific file when getting this request
|
||||
@app.get("/delete/{file}")
|
||||
async def delete(request: Request, file: str, user_agent: Annotated[Union[str, None], Header()] = None):
|
||||
async def delete(request: Request, file: str, user_agent: str | None = Header(default=None)):
|
||||
file_path = f"{dirname(abspath(__file__))}/upload/{file}"
|
||||
if exists(file_path):
|
||||
remove(file_path)
|
||||
|
Loading…
Reference in New Issue
Block a user