Fixed sk1 upload

This commit is contained in:
root 2026-05-12 21:49:32 +02:00
parent ac68441826
commit 06118cf008
13 changed files with 696 additions and 1 deletions

1
sk1

@ -1 +0,0 @@
Subproject commit ab722d7325e910cbe4b7089e5f211f8bf66756c9

6
sk1/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
ssl/
uploads/
backups/
__pycache__/
.env
__pycache__/

0
sk1/README.md Normal file
View File

11
sk1/backend/Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM python:3.11
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]

111
sk1/backend/app.py Normal file
View File

@ -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/<filename>', 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
)

View File

@ -0,0 +1,3 @@
flask
flask-cors
psycopg2-binary

7
sk1/backup.sh Executable file
View File

@ -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/

50
sk1/docker-compose.yml Normal file
View File

@ -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:

3
sk1/frontend/Dockerfile Normal file
View File

@ -0,0 +1,3 @@
FROM nginx:alpine
COPY index.html /usr/share/nginx/html/index.html

476
sk1/frontend/index.html Normal file
View File

@ -0,0 +1,476 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Smart Share Hub</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background:
linear-gradient(
135deg,
#020617,
#0f172a,
#111827
);
color: white;
min-height: 100vh;
padding: 40px 20px;
}
.container {
max-width: 1000px;
margin: auto;
}
.title {
text-align: center;
margin-bottom: 40px;
}
.title h1 {
font-size: 50px;
color: #38bdf8;
margin-bottom: 10px;
}
.title p {
color: #94a3b8;
font-size: 18px;
}
.card {
background: rgba(30, 41, 59, 0.9);
border-radius: 18px;
padding: 25px;
margin-bottom: 25px;
box-shadow:
0 10px 30px rgba(0,0,0,0.3);
}
.section-title {
font-size: 26px;
margin-bottom: 20px;
color: #7dd3fc;
}
input[type="file"] {
margin-bottom: 15px;
color: white;
}
textarea {
width: 100%;
padding: 15px;
border-radius: 12px;
border: none;
resize: vertical;
min-height: 120px;
background: #334155;
color: white;
font-size: 16px;
}
textarea::placeholder {
color: #cbd5e1;
}
button {
padding: 12px 20px;
border: none;
border-radius: 10px;
background: #38bdf8;
color: black;
font-weight: bold;
cursor: pointer;
margin-top: 15px;
margin-right: 10px;
transition: 0.3s;
}
button:hover {
background: #0ea5e9;
transform: scale(1.03);
}
.file-item,
.note-item {
background: #334155;
padding: 18px;
border-radius: 12px;
margin-top: 15px;
}
.file-header {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 10px;
}
.file-name {
font-size: 16px;
word-break: break-word;
}
.footer {
text-align: center;
margin-top: 40px;
color: #64748b;
}
a {
text-decoration: none;
}
.top-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 25px;
}
@media(max-width: 768px) {
.top-grid {
grid-template-columns: 1fr;
}
.title h1 {
font-size: 38px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="title">
<h1>Smart Share Hub</h1>
<p>
Secure HTTPS Cloud File & Note Sharing Platform
</p>
</div>
<div class="top-grid">
<!-- Upload -->
<div class="card">
<div class="section-title">
Upload Files
</div>
<input type="file"
id="fileInput">
<br>
<button onclick="uploadFile()">
Upload File
</button>
</div>
<!-- Notes -->
<div class="card">
<div class="section-title">
Share Notes
</div>
<textarea
id="noteText"
placeholder="Write something to share..."></textarea>
<button onclick="shareNote()">
Share Note
</button>
</div>
</div>
<!-- Files -->
<div class="card">
<div class="section-title">
Uploaded Files
</div>
<div id="fileList"></div>
</div>
<!-- Notes -->
<div class="card">
<div class="section-title">
Shared Notes
</div>
<div id="notesList"></div>
</div>
<div class="footer">
Smart Share Hub • Docker • Flask • PostgreSQL • HTTPS
</div>
</div>
<script>
async function loadFiles() {
let response =
await fetch('/api/files');
let files =
await response.json();
let fileList =
document.getElementById('fileList');
fileList.innerHTML = '';
files.forEach(file => {
fileList.innerHTML += `
<div class="file-item">
<div class="file-header">
<div class="file-name">
${file}
</div>
<div>
<a href="/api/download/${file}"
target="_blank">
<button>
Download
</button>
</a>
<button onclick="copyLink('${file}')">
Copy Link
</button>
</div>
</div>
</div>
`;
});
}
async function uploadFile() {
let fileInput =
document.getElementById('fileInput');
if(fileInput.files.length === 0) {
alert('Please choose a file');
return;
}
let formData = new FormData();
formData.append(
'file',
fileInput.files[0]
);
await fetch('/api/upload', {
method: 'POST',
body: formData
});
alert('File uploaded successfully');
fileInput.value = '';
loadFiles();
}
async function loadNotes() {
let response =
await fetch('/api/notes');
let notes =
await response.json();
let notesList =
document.getElementById('notesList');
notesList.innerHTML = '';
notes.forEach(note => {
notesList.innerHTML += `
<div class="note-item">
${note.text}
</div>
`;
});
}
async function shareNote() {
let text =
document.getElementById('noteText').value;
if(text.trim() === '') {
alert('Please write something');
return;
}
await fetch('/api/notes', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: text
})
});
document.getElementById('noteText').value = '';
loadNotes();
}
function copyLink(fileName) {
const url =
window.location.origin +
'/api/download/' +
fileName;
navigator.clipboard.writeText(url);
alert('Download link copied!');
}
loadFiles();
loadNotes();
</script>
</body>
</html>

23
sk1/nginx/default.conf Normal file
View File

@ -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/;
}
}

3
sk1/prepare-app.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
docker-compose up -d --build

3
sk1/remove-app.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
docker-compose down