mirror of
https://github.com/Xevion/the-office.git
synced 2025-12-15 06:13:30 -06:00
fully converted to proper bootstrap-vue, black theme styling, api routes for data retrieval,
This commit is contained in:
0
server/__init__.py
Normal file
0
server/__init__.py
Normal file
@@ -3,15 +3,46 @@ api.py
|
||||
|
||||
Provides a accessible protected backend API. JSON I/O only, CSRF protected.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
|
||||
import flask_wtf
|
||||
from flask import current_app, jsonify
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
with open(os.path.join(BASE_DIR, 'data', 'data.json'), 'r', encoding='utf-8') as file:
|
||||
data = json.load(file)
|
||||
|
||||
|
||||
@current_app.route('/api/csrf/')
|
||||
def csrf():
|
||||
def api_csrf():
|
||||
"""
|
||||
Page used for refreshing expired CSRF tokens via AJAX.
|
||||
|
||||
Probably secure: https://medium.com/@iaincollins/csrf-tokens-via-ajax-a885c7305d4a
|
||||
"""
|
||||
return jsonify(flask_wtf.csrf.generate_csrf())
|
||||
|
||||
|
||||
@current_app.route('/api/episodes/')
|
||||
def api_episodes():
|
||||
"""
|
||||
Returns a list of episodes with basic information (no quotes).
|
||||
Used for the left side season bar.
|
||||
"""
|
||||
seasons = []
|
||||
copy = list(data)
|
||||
for season in copy:
|
||||
for episode in season.get('episodes'):
|
||||
if 'scenes' in episode.keys():
|
||||
del episode['scenes']
|
||||
seasons.append(season)
|
||||
return jsonify(seasons)
|
||||
|
||||
|
||||
@current_app.route('/api/all/')
|
||||
def api_data():
|
||||
"""
|
||||
Season data route
|
||||
"""
|
||||
return jsonify(data)
|
||||
|
||||
@@ -15,7 +15,6 @@ from werkzeug.exceptions import HTTPException
|
||||
from server.config import configs
|
||||
|
||||
csrf = CSRFProtect()
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
cors = CORS(resources={r'/*': {'origins': '*'}})
|
||||
|
||||
|
||||
@@ -65,6 +64,7 @@ def create_app(env=None):
|
||||
|
||||
@app.context_processor
|
||||
def inject_data():
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
with open(os.path.join(BASE_DIR, 'data', 'data.json'), 'r', encoding='utf-8') as file:
|
||||
return dict(data=json.load(file))
|
||||
|
||||
@@ -72,5 +72,7 @@ def create_app(env=None):
|
||||
with app.app_context():
|
||||
# noinspection PyUnresolvedReferences
|
||||
from server import routes
|
||||
# noinspection PyUnresolvedReferences
|
||||
from server import api
|
||||
|
||||
return app
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user