diff --git a/anonkun.py b/anonkun.py index 411acd7..e60eeb5 100644 --- a/anonkun.py +++ b/anonkun.py @@ -57,7 +57,6 @@ app.wsgi_app = ProxyFix(app.wsgi_app) app.register_blueprint(views) app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 app.config['SESSION_TYPE'] = 'filesystem' -app.url_map.strict_slashes = False app.jinja_env.trim_blocks = True app.jinja_env.lstrip_blocks = True #app.jinja_env.undefined = "StrictUndefined" diff --git a/anonkun.sql b/anonkun.sql index d109125..4e96a1b 100644 --- a/anonkun.sql +++ b/anonkun.sql @@ -27,6 +27,7 @@ CREATE TABLE `quest_meta` ( CREATE TABLE `quest_data` ( `post_id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, `quest_id` SMALLINT UNSIGNED NOT NULL, + `page_num` TINYINT UNSIGNED NOT NULL, `post_type` ENUM('text', 'dice', 'poll') NOT NULL, `post` MEDIUMTEXT NOT NULL, `timestamp` INT UNSIGNED NOT NULL, diff --git a/database.py b/database.py index 9952d1c..cf3c356 100644 --- a/database.py +++ b/database.py @@ -130,12 +130,13 @@ def insert_quest(canon_title, owner_id): return quest_id -def insert_quest_post(quest_id, post_type, post, timestamp): +def insert_quest_post(quest_id, page_num, post_type, post, timestamp): """Insers a new quest post.""" _DB.execute( "INSERT INTO `quest_data`" \ - + "(`quest_id`, `post_type`, `post`, `timestamp`) " \ - + "VALUES (%s, %s, %s, %s)", (quest_id, post_type, post, timestamp)) + + "(`quest_id`, `page_num`, `post_type`, `post`, `timestamp`) " \ + + "VALUES (%s, %s, %s, %s, %s)", + (quest_id, page_num, post_type, post, timestamp)) post_id = _DB.execute( "SELECT `post_id` FROM `quest_data` WHERE `quest_id` = %s " \ + "ORDER BY `post_id` DESC", (quest_id,)).fetchone()[0] diff --git a/events.py b/events.py index 22bb3e9..0ff3fd6 100644 --- a/events.py +++ b/events.py @@ -28,17 +28,16 @@ def qm_only(msg=""): def _nop(*args, **kwargs): data = args[0] room = data.get("room") - res = db.get_quest_meta(quest_id=room) + res = db.get_quest_meta(room) if not res: return msg - if session.get("user_id") != res[3]: + if session.get("user_id") != res[2]: return msg return func(*args, **kwargs) return _nop return actual_decorator - @socketio.on('joined') def joined(data): """ @@ -167,12 +166,14 @@ def new_post(data, internal=False): """ room = data.get("room") post = data.get("post") + page_num = data.get("page_num") + post = bleach.clean(post.strip()) post = post.replace("\n", "
") post = tools.handle_img(post) date = int(time.time()) - post_id = db.insert_quest_post(room, "text", post, date) + post_id = db.insert_quest_post(room, page_num, "text", post, date) db.set_post_closed(room) data = {} @@ -229,6 +230,7 @@ def dice_post(data): except (ValueError, AssertionError): return diceStrict = bool(data.get("diceStrict")) + page_num = data.get("page_num") dice_roll = f"{data['diceNum']}d{data['diceSides']}" if diceMod: @@ -241,7 +243,7 @@ def dice_post(data): post += " vs DC" + str(diceChal) date = int(time.time()) - post_id = db.insert_quest_post(room, "dice", post, date) + post_id = db.insert_quest_post(room, page_num, "dice", post, date) new_call = (dice_roll, diceStrict, diceChal, diceRollsTaken) db.insert_dice_call(post_id, room, new_call) db.set_post_open(post_id, room) @@ -295,6 +297,7 @@ def poll_post(data): room = data.pop("room", None) multi_choice = bool(data.pop("pollAllowMultipleChoices", None)) allow_writein = bool(data.pop("pollAllowUserOptions", None)) + page_num = data.get("page_num") options = [] for key, value in data.items(): if not value or not key.startswith("pollOption-"): @@ -307,7 +310,7 @@ def poll_post(data): post = "Poll" date = int(time.time()) - post_id = db.insert_quest_post(room, "poll", post, date) + post_id = db.insert_quest_post(room, page_num, "poll", post, date) db.insert_poll(post_id, room, multi_choice, allow_writein) new_options = [] for option in options: diff --git a/static/anonkunQM.js b/static/anonkunQM.js index 146a717..be34a39 100644 --- a/static/anonkunQM.js +++ b/static/anonkunQM.js @@ -5,7 +5,7 @@ var tid = setInterval( function () { clearInterval( tid ); document.getElementById('chatWindow').scrollTop = document.getElementById('chatWindow').scrollHeight; - socket = io.connect('https://' + document.domain + ':' + location.port); + socket = io.connect('https://' + document.domain + location.port); socket.on('connect', function() { socket.emit('joined', {room: room_id}); }); @@ -223,7 +223,7 @@ function makePost() { let text = qparea.value.trim(); qparea.value = ''; if (text == '') { return; } - socket.emit('new_post', {post: text, room: room_id}); + socket.emit('new_post', {post: text, page_num: page_num, room: room_id}); } function edit_post(post_id) { document.getElementById('questPostData-' + post_id).contentEditable = 'true'; @@ -247,6 +247,7 @@ function form_post(form_id, emit_msg) { obj[key] = value; }); obj.room = room_id; + obj.page_num = page_num; socket.emit(emit_msg, obj); document.getElementById(form_id).reset(); } diff --git a/templates/quest.html b/templates/quest.html index 90bcd67..f453ee1 100644 --- a/templates/quest.html +++ b/templates/quest.html @@ -2,7 +2,7 @@ {% block title %}{{ quest_title }}{% endblock %} {% block head %} - + {% if session.get("user_id") == owner_id %} {% else %} @@ -11,7 +11,14 @@ {% endblock %} {% block header %} {% if session.get("user_id") == owner_id %} -
  • Edit Quest
  • +
  • Edit Quest
  • +
  • Page 1
  • +
  • + +
  • {% endif %} {% endblock %} {% block content %} @@ -20,20 +27,20 @@

    {{ quest_title }}

    {% for quest_post in quest_posts %} - {% if quest_post[2] == "text" %} + {% if quest_post[3] == "text" %}
    - {% elif quest_post[2] == "dice" %} + {% elif quest_post[3] == "dice" %}
    - {% elif quest_post[2] == "poll" %} + {% elif quest_post[3] == "poll" %}
    {% endif %}
    - {{ quest_post[4] | strftime }} + {{ quest_post[5] | strftime }} {% if session.get("user_id") == owner_id %} - {% if quest_post[2] == "text" %} + {% if quest_post[3] == "text" %}
    Edit - {% elif quest_post[2] == "dice" or quest_post[2] == "poll" and quest_post == quest_posts|last %} + {% elif quest_post[3] == "dice" or quest_post[3] == "poll" and quest_post == quest_posts|last %} {% if quest_post[0] == open_post_id %}
    Close @@ -45,19 +52,19 @@ {% endif %}
    - {% if quest_post[2] == "text" %} + {% if quest_post[3] == "text" %} {% autoescape false %} - {{ quest_post[3] }} + {{ quest_post[4] }} {% endautoescape %} - {% elif quest_post[2] == "dice" %} -

    {{ quest_post[3] }} - {% if quest_post[0] == open_post_id %}Open{% else %}Closed{% endif %}

    + {% elif quest_post[3] == "dice" %} +

    {{ quest_post[4] }} - {% if quest_post[0] == open_post_id %}Open{% else %}Closed{% endif %}

    {% for dice_roll in dice_rolls[quest_post[0]] %}
    Rolled {{ dice_roll[4] }} = {{ dice_roll[5] }} ({{ dice_roll[3] }}){% if quest_post[0]|dice_chal != 0 %} - {% if dice_roll[5] >= quest_post[0]|dice_chal %}Pass{% else %} Fail{% endif %}{% endif %}
    {% endfor %} - {% elif quest_post[2] == "poll" %} -

    {{ quest_post[3] }} - {% if quest_post[0] == open_post_id %}Open{% else %}Closed{% endif %}

    + {% elif quest_post[3] == "poll" %} +

    {{ quest_post[4] }} - {% if quest_post[0] == open_post_id %}Open{% else %}Closed{% endif %}

    diff --git a/todo b/todo index fa22a96..1ea8f53 100644 --- a/todo +++ b/todo @@ -13,6 +13,7 @@ Account managament/logout Display profile link in header bar Tagging system Quote backlinks +Make chat hideable Improvements: Revamp post editing diff --git a/views.py b/views.py index 8231066..da88d97 100644 --- a/views.py +++ b/views.py @@ -43,6 +43,7 @@ def login_required(url=None): @views.route("/quest/", strict_slashes=False) +@views.route("/quest///") def quest(quest_id, page_num=1): """ An arbituary quest page. @@ -53,8 +54,8 @@ def quest(quest_id, page_num=1): quest_id = room_id = data[0] quest_title = data[1] - owner_id = data[3] - open_post_id = data[4] + owner_id = data[2] + open_post_id = data[2] ip_address = request.remote_addr quest_posts = db.get_quest_data(quest_id) @@ -127,9 +128,10 @@ def create_quest(): owner_id = session.get("user_id") timestamp = int(time.time()) + page_num = 1 quest_id = db.insert_quest(quest_title, owner_id) - db.insert_quest_post(quest_id, "text", quest_body, timestamp) + db.insert_quest_post(quest_id, page_num, "text", quest_body, timestamp) return redirect(url_for('.quest', quest_id=quest_id))