shakecities/sites/slds.py

59 lines
1.3 KiB
Python
Raw Normal View History

2023-11-08 20:43:33 +11:00
from flask import Flask, make_response, redirect, render_template_string, request, jsonify, render_template, send_from_directory
2023-11-08 17:55:49 +11:00
import os
import dotenv
import requests
import json
import schedule
import time
2023-11-08 20:43:33 +11:00
import db
import website
2023-11-08 19:06:08 +11:00
2023-11-08 17:55:49 +11:00
app = Flask(__name__)
dotenv.load_dotenv()
#Assets routes
@app.route('/assets/<path:path>')
def assets(path):
return send_from_directory('templates/assets', path)
#! TODO make prettier
def error(message):
return jsonify({'success': False, 'message': message}), 400
@app.route('/')
def index():
host = request.host
2023-11-08 20:49:03 +11:00
if len(host.split('.')) != 2:
2023-11-08 20:43:33 +11:00
return error('Invalid domain')
2023-11-08 20:49:03 +11:00
host = host.split('.')[0]
2023-11-08 20:43:33 +11:00
# Get website data
data = db.get_website_data(host)
# Render as HTML
return website.render(data)
2023-11-08 17:55:49 +11:00
2023-11-09 12:13:59 +11:00
@app.route('/.well-known/wallets/<token>')
def wallet(token):
address = db.get_website_wallet(request.host.split('.')[0],token)
if address == "":
return redirect('/')
# Plain text
response = make_response(address)
response.mimetype = "text/plain"
return response
2023-11-08 17:55:49 +11:00
@app.route('/<path:path>')
def catch_all(path):
return redirect('/') # 404 catch all
# 404 catch all
@app.errorhandler(404)
def not_found(e):
return redirect('/')
if __name__ == '__main__':
app.run(debug=False, port=5000, host='0.0.0.0')