diff --git a/api/api.py b/api/api.py
index 1006a2a..f26e96f 100644
--- a/api/api.py
+++ b/api/api.py
@@ -1,17 +1,75 @@
-from flask import Flask, config
+from http import HTTPStatus
+from flask import Flask, Response, config, json, jsonify, request, request_started
from dotenv import dotenv_values
from pymongo import MongoClient
from bson.json_util import dumps
+from bson import ObjectId
+from uuid import uuid4
config = dotenv_values(".env")
app = Flask(__name__)
-app.mongoclient = MongoClient(config["DB_URI"])
-app.db = app.mongoclient[config["DB_NAME"]]
+mongoclient = MongoClient(config["DB_URI"])
+db = mongoclient[config["DB_NAME"]]
print("Connected to MongoDB database")
@app.route('/api/message')
def get_messages():
- messages = dumps(list(app.db["message"].find(limit=100)))
+ messages = dumps(list(db["message"].find(limit=100)))
return messages
+
+@app.route('/api/new_message', methods=['POST'])
+def new_message():
+ position = list(json.loads(request.form['position']))
+ message = request.form['message']
+ token = request.form['token']
+ user = db['user'].find_one({'token': token})
+ if user is not None:
+ db["message"].insert_one({'position': position, 'message': message, 'userId': user['_id']})
+ return Response(status=HTTPStatus.NO_CONTENT)
+ else:
+ return Response(status=HTTPStatus.BAD_REQUEST)
+
+@app.route('/api/gen_token')
+def gen_token():
+ token = str(uuid4())
+ db["user"].insert_one({'token': token})
+ return { 'token': token }
+
+@app.route('/api/remove_message', methods=['DELETE'])
+def remove_message():
+ token = request.form['token']
+ message_id = ObjectId(request.form['message_id'])
+ user = db['user'].find_one({'token':token})
+ if user is not None:
+ message = db['message'].find_one({'_id': message_id})
+ if message is not None:
+ if message['userId'] == user['_id']:
+ db['message'].delete_one({'_id':message_id})
+ return Response(status=HTTPStatus.NO_CONTENT)
+ else:
+ return Response(status=HTTPStatus.UNAUTHORIZED)
+ else:
+ return Response(status=HTTPStatus.BAD_REQUEST)
+ else:
+ return Response(status=HTTPStatus.BAD_REQUEST)
+
+@app.route('/api/edit_message', methods=['PUT'])
+def edit_message():
+ token = request.form['token']
+ message_id = ObjectId(request.form['message_id'])
+ user = db['user'].find_one({'token':token})
+ new_message = request.form['message']
+ if user is not None and new_message is not None:
+ message = db['message'].find_one({'_id': message_id})
+ if message is not None:
+ if message['userId'] == user['_id']:
+ db['message'].update_one({'_id':message_id}, {'$set': { 'message': new_message }})
+ return Response(status=HTTPStatus.NO_CONTENT)
+ else:
+ return Response(status=HTTPStatus.UNAUTHORIZED)
+ else:
+ return Response(status=HTTPStatus.BAD_REQUEST)
+ else:
+ return Response(status=HTTPStatus.BAD_REQUEST)
diff --git a/index.html b/index.html
index afa6192..803731c 100644
--- a/index.html
+++ b/index.html
@@ -3,7 +3,7 @@
- soaos forum
+ soaos forum v0.1
diff --git a/package.json b/package.json
index 94e77cb..a2aee19 100644
--- a/package.json
+++ b/package.json
@@ -11,8 +11,9 @@
"start-api": "cd api && venv/bin/flask run --no-debugger"
},
"dependencies": {
- "@react-three/drei": "^9.121.4",
+ "@react-three/drei": "10.0.0-rc.2",
"@react-three/fiber": "^9.0.0-rc.7",
+ "@react-three/postprocessing": "3.0.0-rc.2",
"@react-three/rapier": "^1.5.0",
"@types/three": "^0.173.0",
"color": "^4.2.3",
diff --git a/src/App.jsx b/src/App.jsx
index 81436a8..fb72f6e 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -6,8 +6,10 @@ import Ground from './components/ground';
import React, { Suspense, useContext, useEffect, useRef, useState } from 'react';
import { Physics } from '@react-three/rapier';
import Sun from './components/sun';
-import { Fog } from 'three';
import * as everforest from './_everforest.module.scss'
+import { Bloom, EffectComposer, GodRays, LensFlare, Noise, Vignette } from '@react-three/postprocessing';
+import { AdditiveBlending } from 'three';
+import { useGLTF } from '@react-three/drei';
export const AppContext = React.createContext(null);
@@ -21,6 +23,7 @@ function App() {
const keys = useRef([]);
const keysPressed = useRef([]);
const [messages, setMessages] = useState();
+ const apiToken = useRef();
const playerKeyDown = (event) => {
if (!keys.current.includes(event.code)) {
keysPressed.current.push(event.code);
@@ -39,23 +42,36 @@ function App() {
};
}, []);
useEffect(() => {
+ const token = window.localStorage.getItem("token");
+ if (token == null) {
+ fetch('/api/gen_token').then((res) => res.json()).then((data) => {
+ window.localStorage.setItem("token", data.token);
+ apiToken.current = data.token;
+ });
+ } else {
+ console.log("setting token");
+ apiToken.current = token;
+ }
fetch('/api/message').then((res) => res.json()).then((data) => {
console.log(data);
setMessages(data);
});
- }, []);
+ },[]);
+ useGLTF.preload('../assets/terrain.glb');
+ useGLTF.preload('../assets/message-bubble.glb');
return (
<>
- E - read
- LMB - write
+ E - read
+ LMB - write
+ X - delete
-
+