diff --git a/files/assets/js/emoji_modal.js b/files/assets/js/emoji_modal.js index e62e57b8f..cbe1330ca 100644 --- a/files/assets/js/emoji_modal.js +++ b/files/assets/js/emoji_modal.js @@ -156,7 +156,8 @@ const emojisSearchDictionary = { function makeEmojisSearchDictionary() { // get public emojis list const headers = new Headers({xhr: "xhr"}) - return fetch("/emojis.json", { + const emoji_num = document.getElementById('emoji_num').value + return fetch(`/emojis.csv?x=${emoji_num}`, { headers, }) .then(res => res.json()) @@ -190,7 +191,8 @@ function makeEmojisSearchDictionary() { // get public emojis list function fetchEmojis() { const headers = new Headers({xhr: "xhr"}) - return fetch("/emojis.json", { + const emoji_num = document.getElementById('emoji_num').value + return fetch(`/emojis.csv?x=${emoji_num}`, { headers, }) .then(res => res.json()) diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index b9fb66ddd..e1c80f961 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -475,7 +475,7 @@ ERROR_MARSEYS = { 500: "marseycarp3", } -EMOJI_SRCS = ['files/assets/emojis.json'] +EMOJI_SRCS = ['files/assets/emojis.csv'] PIN_LIMIT = 3 POST_TITLE_LENGTH_LIMIT = 500 # do not make larger than 500 without altering the table diff --git a/files/routes/allroutes.py b/files/routes/allroutes.py index 28701ac4c..fcb9fbb77 100644 --- a/files/routes/allroutes.py +++ b/files/routes/allroutes.py @@ -54,6 +54,9 @@ def before_request(): @app.after_request def after_request(response): + if request.path == '/emojis.csv': + response.cache_control.max_age = 2678400 + user_id = None if response.status_code < 400: diff --git a/files/routes/asset_submissions.py b/files/routes/asset_submissions.py index 931f3b9ee..0c9a76457 100644 --- a/files/routes/asset_submissions.py +++ b/files/routes/asset_submissions.py @@ -246,6 +246,8 @@ def approve_emoji(v, name): cache.delete("emojis_False") cache.delete(f"emoji_list_{emoji.kind}_False") + cache.set("emojis_num", g.db.query(Emojis).count()) + purge_files_in_cloudflare_cache(f"{SITE_FULL_IMAGES}/e/{emoji.name}/webp") return {"message": f"'{emoji.name}' approved!"} @@ -569,6 +571,8 @@ def update_emoji(v): cache.delete("emojis_False") cache.delete(f"emoji_list_{existing.kind}_False") + cache.set("emojis_num", g.db.query(Emojis).count()) + return {"message": f"'{name}' updated successfully!"} @app.get("/admin/update/hats") diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index b376a4ba6..5e85c09cf 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -151,5 +151,5 @@ def inject_constants(): "CHUD_PHRASES":CHUD_PHRASES, "hasattr":hasattr, "calc_users":calc_users, "HOLE_INACTIVITY_DELETION":HOLE_INACTIVITY_DELETION, "LIGHT_THEMES":LIGHT_THEMES, "OVER_18_EMOJIS":OVER_18_EMOJIS, "MAX_IMAGE_AUDIO_SIZE_MB":MAX_IMAGE_AUDIO_SIZE_MB, "MAX_IMAGE_AUDIO_SIZE_MB_PATRON":MAX_IMAGE_AUDIO_SIZE_MB_PATRON, "MAX_VIDEO_SIZE_MB":MAX_VIDEO_SIZE_MB, "MAX_VIDEO_SIZE_MB_PATRON":MAX_VIDEO_SIZE_MB_PATRON, - "CURSORMARSEY_DEFAULT":CURSORMARSEY_DEFAULT, "SNAPPY_ID":SNAPPY_ID, "get_running_orgy":get_running_orgy, "TRUESCORE_MINIMUM":TRUESCORE_MINIMUM, "bar_position":bar_position, "datetime":datetime, "CSS_LENGTH_LIMIT":CSS_LENGTH_LIMIT + "CURSORMARSEY_DEFAULT":CURSORMARSEY_DEFAULT, "SNAPPY_ID":SNAPPY_ID, "get_running_orgy":get_running_orgy, "TRUESCORE_MINIMUM":TRUESCORE_MINIMUM, "bar_position":bar_position, "datetime":datetime, "CSS_LENGTH_LIMIT":CSS_LENGTH_LIMIT, "emoji_num":cache.get("emojis_num") or 0, } diff --git a/files/routes/static.py b/files/routes/static.py index 9316ed49c..43b446fb0 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -114,7 +114,7 @@ def get_emojis(nsfw): collected.append(emoji.json()) return collected -@app.get("/emojis.json") +@app.get("/emojis.csv") @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required diff --git a/files/templates/modals/emoji.html b/files/templates/modals/emoji.html index 266bfb47b..e3065ccde 100644 --- a/files/templates/modals/emoji.html +++ b/files/templates/modals/emoji.html @@ -70,4 +70,5 @@ +