Skip to content

Commit

Permalink
Move JS to namespace, share constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Dvd848 committed Dec 2, 2020
1 parent 6a9a58c commit 8dd0f1c
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 111 deletions.
40 changes: 32 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
import filter
import requests
import os
import utils

class HttpStatus(Enum):
HTTP_500_INTERNAL_SERVER_ERROR = 500

class PageIds(Enum):
PAGE_INDEX = "index"
PAGE_LOGIN = "login"
PAGE_TOS = "tos"
PAGE_SETTINGS = "settings"
PAGE_FILTER = "filter"

app = Flask("ctftime-writeups")
logger = create_logger(app)

Expand All @@ -31,6 +39,7 @@ def writeups(uid):
headers = {
'User-Agent': 'CTFTime Writeups Filter 1.0',
}

r = requests.get("https://ctftime.org/writeups/rss/", headers = headers)

if (not r.headers['content-type'].startswith("application/rss+xml")):
Expand All @@ -51,29 +60,44 @@ def writeups(uid):

return res

@app.template_global()
def get_global_constants():
res = dict()

res["COOKIE_MENU_TYPE"] = "menu_type"
res["COOKIE_MENU_TYPE_LOGGED_IN"] = "logged_in"
res.update(utils.enum_to_dict(PageIds))

return res

@app.route('/')
def index_page():
return render_template('index.html', page_id = "index")
page = PageIds.PAGE_INDEX.value
return render_template(f'{page}.html', page_id = page)

@app.route('/login')
def login_page():
return render_template('login.html', title = "Sign-up / Sign-in", page_id = "login")
page = PageIds.PAGE_LOGIN.value
return render_template(f'{page}.html', title = "Sign-up / Sign-in", page_id = page)

@app.route('/tos')
def tos_page():
return render_template('tos.html', title = "Terms & Conditions", page_id = "tos")
page = PageIds.PAGE_TOS.value
return render_template(f'{page}.html', title = "Terms & Conditions", page_id = page)

@app.route('/settings')
def settings_page():
return render_template('settings.html', title = "Settings", page_id = "settings")
page = PageIds.PAGE_SETTINGS.value
return render_template(f'{page}.html', title = "Settings", page_id = page)

@app.route('/filter')
def filter_page():
return render_template('filter.html', title = "Filter", page_id = "filter",
max_ctf_entries = MAX_CTF_ENTRIES,
entry_separator = ENTRY_SEPARATOR,
max_entry_name_len = MAX_ENTRY_NAME_LEN)
page = PageIds.PAGE_FILTER.value
constants = get_global_constants()
constants.update(MAX_CTF_ENTRIES = MAX_CTF_ENTRIES,
ENTRY_SEPARATOR = ENTRY_SEPARATOR,
MAX_ENTRY_NAME_LEN = MAX_ENTRY_NAME_LEN)
return render_template(f'{page}.html', title = "Filter", page_id = page, constants = constants)

if __name__ == '__main__':
app.run(host = '0.0.0.0', threaded = True, port = 5000)
Loading

0 comments on commit 8dd0f1c

Please sign in to comment.