File size: 961 Bytes
ef60c31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from flask import Flask, abort, request, json, jsonify, send_file
import os

app = Flask(__name__)
last_editor = "1"

@app.route('/', methods=['GET'])
def home():
    return send_file('index.html')

@app.route('/editor.js', methods=['GET'])
def get_editor():
    return send_file('editor.js')

@app.route('/content', methods=['GET'])
def get_content():
    if os.path.exists('code.txt'):
        with open('code.txt', 'r') as file:
            content = file.read()
        return jsonify({'content': content, 'lastEditor': last_editor})
    else:
        abort(404, description="Whoops! Document not found")

@app.route('/update', methods=['POST'])
def update_file():
    data = json.loads(request.data)
    code = data["code"]
    global last_editor
    last_editor = data["iam"]
    with open('code.txt', 'w') as file:
        file.write(code)
    return ""

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860)