nvm this fucked shit up
This commit is contained in:
parent
8128b223c0
commit
ac05692c6a
20
app.py
20
app.py
|
@ -9,13 +9,10 @@ from flask_limiter import Limiter
|
|||
from flask_limiter.util import get_remote_address
|
||||
import time
|
||||
import re
|
||||
from flask_socketio import SocketIO, emit
|
||||
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
app = Flask(__name__)
|
||||
socketio = SocketIO(app)
|
||||
app.secret_key = os.getenv("SECRET")
|
||||
USERS_FILE = "users.txt"
|
||||
DATA_DIR = "notes"
|
||||
|
@ -130,7 +127,6 @@ def public_board(username):
|
|||
return f.read(), 200
|
||||
|
||||
if request.method == "POST":
|
||||
|
||||
if user != username:
|
||||
return "Forbidden", 403
|
||||
data = request.get_json()
|
||||
|
@ -139,34 +135,24 @@ def public_board(username):
|
|||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(data["content"])
|
||||
socketio.emit('board_update', {'content': data["content"]})
|
||||
return jsonify({"status": "saved"})
|
||||
|
||||
@socketio.on('connect')
|
||||
def handle_connect():
|
||||
print('Client connected')
|
||||
|
||||
@socketio.on('disconnect')
|
||||
def handle_disconnect():
|
||||
print('Client disconnected')
|
||||
|
||||
# When content is updated via POST /boardapi
|
||||
@app.route("/boardapi", methods=["GET", "POST"])
|
||||
def shared_board():
|
||||
path = os.path.join(DATA_DIR, "__shared_board.txt")
|
||||
|
||||
if request.method == "GET":
|
||||
if not os.path.exists(path):
|
||||
return "", 200
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
return f.read(), 200
|
||||
elif request.method == "POST":
|
||||
|
||||
if request.method == "POST":
|
||||
data = request.get_json()
|
||||
if not data or "content" not in data:
|
||||
return "Bad request", 400
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(data["content"])
|
||||
# Broadcast new content to all clients
|
||||
socketio.emit('board_update', {'content': data["content"]})
|
||||
return jsonify({"status": "saved"})
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
bidict==0.23.1
|
||||
blinker==1.9.0
|
||||
cffi==1.17.1
|
||||
click==8.2.1
|
||||
|
@ -6,8 +5,6 @@ cryptography==45.0.3
|
|||
Deprecated==1.2.18
|
||||
Flask==3.1.1
|
||||
Flask-Limiter==3.12
|
||||
Flask-SocketIO==5.5.1
|
||||
h11==0.16.0
|
||||
itsdangerous==2.2.0
|
||||
Jinja2==3.1.6
|
||||
limits==5.2.0
|
||||
|
@ -19,11 +16,7 @@ packaging==25.0
|
|||
pycparser==2.22
|
||||
Pygments==2.19.1
|
||||
python-dotenv==1.1.0
|
||||
python-engineio==4.12.2
|
||||
python-socketio==5.13.0
|
||||
rich==13.9.4
|
||||
simple-websocket==1.1.0
|
||||
typing_extensions==4.14.0
|
||||
Werkzeug==3.1.3
|
||||
wrapt==1.17.2
|
||||
wsproto==1.2.0
|
||||
|
|
|
@ -79,15 +79,3 @@ textarea.addEventListener("input", () => {
|
|||
}
|
||||
}, 500);
|
||||
});
|
||||
|
||||
|
||||
const socket = io();
|
||||
|
||||
// Listen for updates
|
||||
socket.on('board_update', data => {
|
||||
if (true && data.content !== last) {
|
||||
textarea.value = data.content;
|
||||
last = data.content;
|
||||
status.textContent = "Updated from server";
|
||||
}
|
||||
});
|
|
@ -16,9 +16,7 @@
|
|||
<script>
|
||||
const noteName = "{{ note|e }}";
|
||||
</script>
|
||||
<script src="https://cdn.socket.io/4.4.1/socket.io.min.js"></script>
|
||||
<script src="{{ url_for('static', filename='note.js') }}"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
|
|
Loading…
Reference in a new issue