Compare commits
2 Commits
70c480a7cd
...
26b2745e9b
| Author | SHA1 | Date |
|---|---|---|
|
|
26b2745e9b | |
|
|
afa7cf782d |
|
|
@ -1 +1,2 @@
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
.venv/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
# =====CONFIG=====
|
||||||
|
PYTHON := python3
|
||||||
|
VENV := .venv
|
||||||
|
|
||||||
|
|
||||||
|
# =====RECIPES=====
|
||||||
|
# Create the virtual environment
|
||||||
|
$(VENV)/bin/activate: setup.py
|
||||||
|
'$(PYTHON)' -m venv '$(VENV)'
|
||||||
|
'$(VENV)/bin/pip' install -r requirements.txt
|
||||||
|
|
||||||
|
venv: $(VENV)/bin/activate
|
||||||
|
.PHONY: venv
|
||||||
|
|
||||||
|
# Remove any temporary files
|
||||||
|
clean:
|
||||||
|
@ rm -rf '$(VENV)'
|
||||||
|
.PHONY: clean
|
||||||
9
app.py
9
app.py
|
|
@ -4,8 +4,8 @@ from pathlib import Path
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
UPLOAD_FOLDER = './data'
|
UPLOAD_FOLDER = Path(os.environ['REPO_DIR']) / "pkgs"
|
||||||
API_KEY = 'yeet'
|
API_KEY = os.environ['API_KEY']
|
||||||
ALLOWED_EXTENSIONS = {'pkg.tar.zst', 'pkg.tar.gz'}
|
ALLOWED_EXTENSIONS = {'pkg.tar.zst', 'pkg.tar.gz'}
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
@ -46,7 +46,7 @@ def upload_file():
|
||||||
|
|
||||||
# Create path for file & check if it already exists
|
# Create path for file & check if it already exists
|
||||||
filename = secure_filename(file.filename)
|
filename = secure_filename(file.filename)
|
||||||
path = Path(app.config['UPLOAD_FOLDER']) / 'pkgs' / filename
|
path = Path(app.config['UPLOAD_FOLDER']) / filename
|
||||||
|
|
||||||
if path.exists():
|
if path.exists():
|
||||||
return {'message': 'File already exists.'}, 400
|
return {'message': 'File already exists.'}, 400
|
||||||
|
|
@ -57,7 +57,7 @@ def upload_file():
|
||||||
file.save(path)
|
file.save(path)
|
||||||
|
|
||||||
# Run repo-add on the file
|
# Run repo-add on the file
|
||||||
res = subprocess.run(["repo-add", path.parent.parent / "repo.db.tar.gz", path])
|
res = subprocess.run(["repo-add", path.parent / "repo.db.tar.gz", path])
|
||||||
|
|
||||||
if res.returncode != 0:
|
if res.returncode != 0:
|
||||||
path.unlink()
|
path.unlink()
|
||||||
|
|
@ -65,4 +65,3 @@ def upload_file():
|
||||||
return {'message': 'Failed to add file to repository.'}, 500
|
return {'message': 'Failed to add file to repository.'}, 500
|
||||||
|
|
||||||
return {'message': 'Success.'}, 200
|
return {'message': 'Success.'}, 200
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
Flask==2.0.2
|
||||||
|
gunicorn==20.1.0
|
||||||
Reference in New Issue