From 06118cf008ac55af530f9ba1c9fd28c06f808326 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 12 May 2026 21:49:32 +0200 Subject: [PATCH] Fixed sk1 upload --- sk1 | 1 - sk1/.gitignore | 6 + sk1/README.md | 0 sk1/backend/Dockerfile | 11 + sk1/backend/app.py | 111 ++++++++ sk1/backend/requirements.txt | 3 + sk1/backup.sh | 7 + sk1/docker-compose.yml | 50 ++++ sk1/frontend/Dockerfile | 3 + sk1/frontend/index.html | 476 +++++++++++++++++++++++++++++++++++ sk1/nginx/default.conf | 23 ++ sk1/prepare-app.sh | 3 + sk1/remove-app.sh | 3 + 13 files changed, 696 insertions(+), 1 deletion(-) delete mode 160000 sk1 create mode 100644 sk1/.gitignore create mode 100644 sk1/README.md create mode 100644 sk1/backend/Dockerfile create mode 100644 sk1/backend/app.py create mode 100644 sk1/backend/requirements.txt create mode 100755 sk1/backup.sh create mode 100644 sk1/docker-compose.yml create mode 100644 sk1/frontend/Dockerfile create mode 100644 sk1/frontend/index.html create mode 100644 sk1/nginx/default.conf create mode 100755 sk1/prepare-app.sh create mode 100755 sk1/remove-app.sh diff --git a/sk1 b/sk1 deleted file mode 160000 index ab722d7..0000000 --- a/sk1 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ab722d7325e910cbe4b7089e5f211f8bf66756c9 diff --git a/sk1/.gitignore b/sk1/.gitignore new file mode 100644 index 0000000..8d2798d --- /dev/null +++ b/sk1/.gitignore @@ -0,0 +1,6 @@ +ssl/ +uploads/ +backups/ +__pycache__/ +.env +__pycache__/ diff --git a/sk1/README.md b/sk1/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sk1/backend/Dockerfile b/sk1/backend/Dockerfile new file mode 100644 index 0000000..9d4e78e --- /dev/null +++ b/sk1/backend/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.11 + +WORKDIR /app + +COPY requirements.txt . + +RUN pip install -r requirements.txt + +COPY . . + +CMD ["python", "app.py"] diff --git a/sk1/backend/app.py b/sk1/backend/app.py new file mode 100644 index 0000000..5f61e7a --- /dev/null +++ b/sk1/backend/app.py @@ -0,0 +1,111 @@ +from flask import Flask, request, jsonify, send_from_directory +from flask_cors import CORS +import os +import psycopg2 + +app = Flask(__name__) +CORS(app) + +UPLOAD_FOLDER = "uploads" + +os.makedirs(UPLOAD_FOLDER, exist_ok=True) + +shared_notes = [] + +# PostgreSQL connection +conn = psycopg2.connect( + host="postgres", + database="smartshare", + user="postgres", + password=os.getenv("DB_PASSWORD") +) + +@app.route('/') +def home(): + return jsonify({ + "message": "Backend is running" + }) + +@app.route('/upload', methods=['POST']) +def upload_file(): + + if 'file' not in request.files: + return jsonify({ + "error": "No file uploaded" + }), 400 + + file = request.files['file'] + + if file.filename == '': + return jsonify({ + "error": "Empty filename" + }), 400 + + filepath = os.path.join( + UPLOAD_FOLDER, + file.filename + ) + + file.save(filepath) + + return jsonify({ + "message": "File uploaded successfully" + }) + +@app.route('/files', methods=['GET']) +def list_files(): + + files = os.listdir(UPLOAD_FOLDER) + + return jsonify(files) + +@app.route('/download/', methods=['GET']) +def download_file(filename): + + return send_from_directory( + UPLOAD_FOLDER, + filename, + as_attachment=True + ) + +@app.route('/db-test', methods=['GET']) +def db_test(): + + cur = conn.cursor() + + cur.execute("SELECT version();") + + version = cur.fetchone() + + cur.close() + + return jsonify({ + "database": "connected", + "postgres_version": version[0] + }) + +@app.route('/notes', methods=['GET']) +def get_notes(): + + return jsonify(shared_notes) + +@app.route('/notes', methods=['POST']) +def add_note(): + + data = request.json + + note = { + "text": data.get("text") + } + + shared_notes.append(note) + + return jsonify({ + "message": "Note added" + }) + +if __name__ == "__main__": + app.run( + host="0.0.0.0", + port=5000 + ) diff --git a/sk1/backend/requirements.txt b/sk1/backend/requirements.txt new file mode 100644 index 0000000..d08038d --- /dev/null +++ b/sk1/backend/requirements.txt @@ -0,0 +1,3 @@ +flask +flask-cors +psycopg2-binary diff --git a/sk1/backup.sh b/sk1/backup.sh new file mode 100755 index 0000000..c32d664 --- /dev/null +++ b/sk1/backup.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +mkdir -p backups + +docker exec postgres pg_dump -U postgres smartshare > backups/backup.sql + +tar -czf backups/uploads.tar.gz uploads/ diff --git a/sk1/docker-compose.yml b/sk1/docker-compose.yml new file mode 100644 index 0000000..78736b0 --- /dev/null +++ b/sk1/docker-compose.yml @@ -0,0 +1,50 @@ +version: '3' + +services: + + frontend: + build: ./frontend + container_name: frontend + restart: always + + backend: + build: ./backend + container_name: backend + restart: always + environment: + DB_HOST: postgres + DB_NAME: smartshare + DB_USER: postgres + DB_PASSWORD: postgres123 + volumes: + - ./uploads:/app/uploads + depends_on: + - postgres + + postgres: + image: postgres:15 + container_name: postgres + restart: always + environment: + POSTGRES_DB: smartshare + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres123 + volumes: + - postgres_data:/var/lib/postgresql/data + + nginx: + image: nginx:latest + container_name: nginx + restart: always + ports: + - "80:80" + - "443:443" + volumes: + - ./nginx/default.conf:/etc/nginx/conf.d/default.conf + - ./ssl:/etc/nginx/ssl + depends_on: + - frontend + - backend + +volumes: + postgres_data: diff --git a/sk1/frontend/Dockerfile b/sk1/frontend/Dockerfile new file mode 100644 index 0000000..06ef7e2 --- /dev/null +++ b/sk1/frontend/Dockerfile @@ -0,0 +1,3 @@ +FROM nginx:alpine + +COPY index.html /usr/share/nginx/html/index.html diff --git a/sk1/frontend/index.html b/sk1/frontend/index.html new file mode 100644 index 0000000..3986114 --- /dev/null +++ b/sk1/frontend/index.html @@ -0,0 +1,476 @@ + + + + + + + + + + Smart Share Hub + + + + + + + +
+ +
+ +

Smart Share Hub

+ +

+ Secure HTTPS Cloud File & Note Sharing Platform +

+ +
+ +
+ + + +
+ +
+ Upload Files +
+ + + +
+ + + +
+ + + +
+ +
+ Share Notes +
+ + + + + +
+ +
+ + + +
+ +
+ Uploaded Files +
+ +
+ +
+ + + +
+ +
+ Shared Notes +
+ +
+ +
+ + + +
+ + + + + diff --git a/sk1/nginx/default.conf b/sk1/nginx/default.conf new file mode 100644 index 0000000..f9e1078 --- /dev/null +++ b/sk1/nginx/default.conf @@ -0,0 +1,23 @@ +server { + listen 80; + server_name joblin-share.duckdns.org; + + return 301 https://$host$request_uri; +} + +server { + listen 443 ssl; + + server_name joblin-share.duckdns.org; + + ssl_certificate /etc/nginx/ssl/nginx.crt; + ssl_certificate_key /etc/nginx/ssl/nginx.key; + + location / { + proxy_pass http://frontend:80; + } + + location /api/ { + proxy_pass http://backend:5000/; + } +} diff --git a/sk1/prepare-app.sh b/sk1/prepare-app.sh new file mode 100755 index 0000000..ef12dd4 --- /dev/null +++ b/sk1/prepare-app.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker-compose up -d --build diff --git a/sk1/remove-app.sh b/sk1/remove-app.sh new file mode 100755 index 0000000..f163d8d --- /dev/null +++ b/sk1/remove-app.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker-compose down