Skip to content

Commit

Permalink
configured setup
Browse files Browse the repository at this point in the history
  • Loading branch information
cophilot committed Nov 29, 2023
1 parent 3961dad commit df66b16
Show file tree
Hide file tree
Showing 45 changed files with 7,707 additions and 2,070 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_API_URL=https://api.vite.net
VITE_API_URL=http://localhost:5000
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ dist-ssr
*.sln
*.sw?

coverage/*
coverage/*
backend/uploads/*
backend/dev/*
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
. "$(dirname -- "$0")/_/husky.sh"

npm run format
git add .
npm run lint
npm test
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
# wannadb-template

A demo for the wannadb-webapp.

---

## Installation

1. Make sure to have nodejs installed.
2. Install the dependencies with:

```bash
npm install
```

3. Make sure to have python installed.
4. Install the requirements with:

```bash
cd backend
pip install -r requirements.txt
```

---

## Usage

1. Start the frontend with:

```bash
npm run dev
```

2. Start the backend with:

```bash
cd backend
python main.py -dev
```

3. Open [localhost:5173](http://localhost:5173) in your browser.


---


# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Expand Down
1 change: 1 addition & 0 deletions backend/data/users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
119 changes: 119 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import os
import sys
from flask import Flask, request, jsonify
from flask_cors import CORS, cross_origin

app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'

DEVMODE = False

BASEPATH = ""

for arg in sys.argv:
if arg == "-dev":
DEVMODE = True

if DEVMODE:
#os.chdir("dev")
print("*** Running in dev mode ***")
BASEPATH = "dev/"


users= [
{
"id": 1,
"name": "Alena",
"password": "123"
},
{
"id": 2,
"name": "Benjamin",
"password": "123"
},
{
"id": 3,
"name": "Leon",
"password": "123"
},
{
"id": 4,
"name": "Nils",
"password": "123"
},
{
"id": 5,
"name": "Philipp",
"password": "123"
},
{
"id": 6,
"name": "Ramzes",
"password": "123"
},

]

@app.route('/login', methods=['POST'])
@cross_origin()
def login():
data = request.get_json()
# Check if both username and password are provided in the request
if 'username' not in data or 'password' not in data:
return jsonify({'error': 'Both username and password are required'}), 400

# Check if the provided username and password match the hardcoded values
username = data['username'].lower()
password = data['password'].lower()
for user in users:
if user['name'].lower() == username and user['password'].lower() == password:
return jsonify({'message': 'Login successful'}), 200

return jsonify({'error': 'Invalid username or password'}), 401

@app.route('/upload', methods=['POST'])
@cross_origin()
def upload():
data = request.get_json()
# Check if both username and password are provided in the request
if 'data' not in data or 'name' not in data or 'user' not in data:
return jsonify({'message': 'Error: Missing properties'}), 200

# save a txt file with the data
try:
os.makedirs(f"{BASEPATH}uploads/{data['user']}", exist_ok=True)

name = data['name'].replace(" ", "_")
if not ".txt" in name:
name = name + ".txt"

f = open(f"{BASEPATH}uploads/{data['user']}/{name}", "w")
f.write(data['data'].replace("\r\n", "\n"))
f.close()
return jsonify({'message': 'Upload successful'}), 200
except Exception as e:
return jsonify({'message': 'Error: Upload failed' + str(e)}), 200

@app.route('/get/file/names/<user>', methods=['GET'])
@cross_origin()
def get_file_names(user):
try:
files = os.listdir(f"{BASEPATH}uploads/{user}")
return jsonify(files), 200
except Exception as e:
return jsonify([]), 200

@app.route('/get/file/content/<user>/<filename>', methods=['GET'])
@cross_origin()
def get_file_content(user, filename):
try:
f = open(f"{BASEPATH}uploads/{user}/{filename}", "r")
content = f.read()
f.close()
return jsonify(content), 200
except Exception as e:
return jsonify({"message": "Error: File not found"}), 404

if __name__ == '__main__':
app.run(debug=DEVMODE, host='localhost', port=5000)
3 changes: 3 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flask==3.0.0
flask-login==0.6.3
flask-cors==4.0.0
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<title>wannadb</title>
</head>
<body>
<div id="root"></div>
Expand Down
Loading

0 comments on commit df66b16

Please sign in to comment.