From a35697e55e8e1d97e9f8f6e791578c47a2823b6c Mon Sep 17 00:00:00 2001 From: TLSM Date: Tue, 30 Aug 2022 17:02:46 -0400 Subject: [PATCH] Replace nearly all ?v= cachebusts with assetcache. Using the new assetcache module, we replace (almost) all instances of `?v=` cachebusting query parameters in Python and in Jinja templates. The primary exceptions were: user site backgrounds, and some infrequently changed graphics referenced literally from .js files. --- files/classes/badges.py | 3 +- files/classes/submission.py | 16 ++-- files/classes/user.py | 11 ++- files/routes/comments.py | 3 +- files/routes/users.py | 5 +- files/templates/admin/badge_grant.html | 2 +- files/templates/admin/badge_remove.html | 2 +- files/templates/admins.html | 2 +- files/templates/authforms.html | 10 +-- files/templates/award_modal.html | 2 +- files/templates/badges.html | 4 +- files/templates/ban_modal.html | 2 +- files/templates/changelog.html | 2 +- files/templates/chat.html | 12 +-- files/templates/comments.html | 22 +++--- files/templates/default.html | 92 +++++++++++----------- files/templates/delete_post_modal.html | 2 +- files/templates/followers.html | 2 +- files/templates/following.html | 2 +- files/templates/gif_modal.html | 2 +- files/templates/header.html | 6 +- files/templates/home.html | 4 +- files/templates/log.html | 10 +-- files/templates/login.html | 8 +- files/templates/login_2fa.html | 6 +- files/templates/message_success.html | 2 +- files/templates/mobile_navigation_bar.html | 2 +- files/templates/patrons.html | 2 +- files/templates/report_post_modal.html | 2 +- files/templates/settings.html | 14 ++-- files/templates/settings2.html | 18 ++--- files/templates/settings_blocks.html | 2 +- files/templates/settings_profile.html | 2 +- files/templates/settings_security.html | 2 +- files/templates/shop.html | 2 +- files/templates/sign_up.html | 16 ++-- files/templates/sign_up_failed_ref.html | 12 +-- files/templates/sub/subs.html | 2 +- files/templates/submission.html | 26 +++--- files/templates/submission_listing.html | 10 +-- files/templates/submit.html | 22 +++--- files/templates/userpage.html | 18 ++--- files/templates/userpage_comments.html | 4 +- files/templates/userpage_private.html | 4 +- 44 files changed, 203 insertions(+), 191 deletions(-) diff --git a/files/classes/badges.py b/files/classes/badges.py index 6464d5d3a..80597fa56 100644 --- a/files/classes/badges.py +++ b/files/classes/badges.py @@ -4,6 +4,7 @@ from files.__main__ import Base, app from os import environ from files.helpers.lazy import lazy from files.helpers.const import * +from files.helpers.assetcache import assetcache_path from datetime import datetime from json import loads @@ -61,7 +62,7 @@ class Badge(Base): @property @lazy def path(self): - return f"/assets/images/badges/{self.badge_id}.webp" + return assetcache_path(f'images/badges/{self.badge_id}.webp') @property @lazy diff --git a/files/classes/submission.py b/files/classes/submission.py index b5bfe4aa4..d5bd4e69b 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -9,6 +9,7 @@ from sqlalchemy.orm import relationship, deferred from files.__main__ import Base from files.helpers.const import * from files.helpers.lazy import lazy +from files.helpers.assetcache import assetcache_path from .flags import Flag from .comment import Comment from flask import g @@ -266,13 +267,18 @@ class Submission(Base): @property @lazy def thumb_url(self): - if self.over_18: return f"{SITE_FULL}/assets/images/nsfw.webp?v=1" - elif not self.url: return f"{SITE_FULL}/assets/images/{SITE_ID}/default_text.webp?v=1" + if self.over_18: + return SITE_FULL + assetcache_path('images/nsfw.webp') + elif not self.url: + return SITE_FULL + assetcache_path(f'images/{SITE_ID}/default_text.webp') elif self.thumburl: - if self.thumburl.startswith('/'): return SITE_FULL + self.thumburl + if self.thumburl.startswith('/'): + return SITE_FULL + self.thumburl return self.thumburl - elif self.is_youtube or self.is_video: return f"{SITE_FULL}/assets/images/default_thumb_yt.webp?v=1" - else: return f"{SITE_FULL}/assets/images/default_thumb_link.webp?v=1" + elif self.is_youtube or self.is_video: + return SITE_FULL + assetcache_path('images/default_thumb_yt.webp') + else: + return SITE_FULL + assetcache_path('images/default_thumb_link.webp') @property @lazy diff --git a/files/classes/user.py b/files/classes/user.py index 880ad077c..853daf30d 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -19,6 +19,7 @@ from .exiles import * from .sub_block import * from files.__main__ import app, Base, cache from files.helpers.security import * +from files.helpers.assetcache import assetcache_path import random from datetime import datetime from os import environ, remove, path @@ -528,16 +529,18 @@ class User(Base): @property @lazy def banner_url(self): - if self.bannerurl: return self.bannerurl - else: return f"/assets/images/{SITE_ID}/site_preview.webp?v=1015" + if self.bannerurl: + return self.bannerurl + return assetcache_path(f'images/{SITE_ID}/site_preview.webp') @property @lazy def profile_url(self): if self.profileurl: - if self.profileurl.startswith('/'): return SITE_FULL + self.profileurl + if self.profileurl.startswith('/'): + return SITE_FULL + self.profileurl return self.profileurl - return f"{SITE_FULL}/assets/images/default-profile-pic.webp?v=1008" + return assetcache_path('images/default-profile-pic.webp') @lazy def json_popover(self, v): diff --git a/files/routes/comments.py b/files/routes/comments.py index eb00886f2..bfb264660 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -11,6 +11,7 @@ from pusher_push_notifications import PushNotifications from flask import * from files.__main__ import app, limiter from files.helpers.sanitize import filter_emojis_only +from files.helpers.assetcache import assetcache_path import requests from shutil import copyfile from json import loads @@ -38,7 +39,7 @@ def pusher_thread(interests, c, username): 'title': f'New reply by @{username}', 'body': notifbody, 'deep_link': f'{SITE_FULL}/comment/{c.id}?context=8&read=true#context', - 'icon': f'{SITE_FULL}/assets/images/{SITE_ID}/icon.webp?v=1015', + 'icon': SITE_FULL + assetcache_path(f'images/{SITE_ID}/icon.webp'), } }, 'fcm': { diff --git a/files/routes/users.py b/files/routes/users.py index 87665ab5e..a647fad79 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -6,6 +6,7 @@ from files.classes.views import ViewerRelationship from files.helpers.alerts import * from files.helpers.sanitize import * from files.helpers.const import * +from files.helpers.assetcache import assetcache_path from files.mail import * from flask import * from files.__main__ import app, limiter, db_session @@ -26,7 +27,7 @@ def pusher_thread2(interests, notifbody, username): 'title': f'New message from @{username}', 'body': notifbody, 'deep_link': f'{SITE_FULL}/notifications?messages=true', - 'icon': f'{SITE_FULL}/assets/images/{SITE_ID}/icon.webp?v=1015', + 'icon': SITE_FULL + assetcache_path(f'images/{SITE_ID}/icon.webp'), } }, 'fcm': { @@ -704,7 +705,7 @@ def messagereply(v): 'title': f'New message from @{v.username}', 'body': notifbody, 'deep_link': f'{SITE_FULL}/notifications?messages=true', - 'icon': f'{SITE_FULL}/assets/images/{SITE_ID}/icon.webp"a=1010', + 'icon': SITE_FULL + assetcache_path(f'images/{SITE_ID}/icon.webp'), } }, 'fcm': { diff --git a/files/templates/admin/badge_grant.html b/files/templates/admin/badge_grant.html index f60ccaab3..5d548fa27 100644 --- a/files/templates/admin/badge_grant.html +++ b/files/templates/admin/badge_grant.html @@ -60,7 +60,7 @@ - + {{badge.name}} {{badge.description}} diff --git a/files/templates/admin/badge_remove.html b/files/templates/admin/badge_remove.html index d7e77a0fe..2656958d4 100644 --- a/files/templates/admin/badge_remove.html +++ b/files/templates/admin/badge_remove.html @@ -60,7 +60,7 @@ - + {{badge.name}} {{badge.description}} diff --git a/files/templates/admins.html b/files/templates/admins.html index d35f54cab..1dad1fe78 100644 --- a/files/templates/admins.html +++ b/files/templates/admins.html @@ -4,7 +4,7 @@ {% block content %} - +

 
Admins
diff --git a/files/templates/authforms.html b/files/templates/authforms.html index f7112ee9b..531fe0dfe 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,15 +15,15 @@ {% if v %} - - + + {% if v.css %} {% endif %} {% else %} - - + + {% endif %} @@ -94,7 +94,7 @@
- cover + cover diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index 9cd0d368a..9e3c2c8d9 100644 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -44,4 +44,4 @@ - + diff --git a/files/templates/badges.html b/files/templates/badges.html index 37e695703..1c88f40f8 100644 --- a/files/templates/badges.html +++ b/files/templates/badges.html @@ -1,6 +1,6 @@ {% extends "default.html" %} {% block content %} - +
 
 
@@ -27,7 +27,7 @@
 	
 		{{loop.index}}
 		{{badge.name}}
-		{{badge.name}}
+		{{badge.name}}
 		{{badge.description}}
 		{%- set ct = counts[badge.id] if badge.id in counts else (0, 0) %}
 		{{ ct[0] }}
diff --git a/files/templates/ban_modal.html b/files/templates/ban_modal.html
index 79aaa11c6..b77fc8dd0 100644
--- a/files/templates/ban_modal.html
+++ b/files/templates/ban_modal.html
@@ -1,5 +1,5 @@
 
-
+
 
 
 
-
+
 
 {% if v %}
-	
-	
+	
+	
 {% endif %}
 
-
+
 
 
+
 
 
 
-
+
diff --git a/files/templates/header.html b/files/templates/header.html
index 78738a003..12773cc73 100644
--- a/files/templates/header.html
+++ b/files/templates/header.html
@@ -12,7 +12,7 @@
 	
 
 				
diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html
index 8766d6605..415f914da 100644
--- a/files/templates/login_2fa.html
+++ b/files/templates/login_2fa.html
@@ -14,8 +14,8 @@
 		2-Step Login - {{SITE_TITLE}}
 
 		
-		
-		
+		
+		
 
 
 
@@ -93,7 +93,7 @@
 
 						
- cover + cover diff --git a/files/templates/message_success.html b/files/templates/message_success.html index 93205d7dc..a17e52a62 100644 --- a/files/templates/message_success.html +++ b/files/templates/message_success.html @@ -9,7 +9,7 @@ {% block content %}
- success state + success state
{{title}}

{{message}}

diff --git a/files/templates/mobile_navigation_bar.html b/files/templates/mobile_navigation_bar.html index 695a8eaa5..2a155be37 100644 --- a/files/templates/mobile_navigation_bar.html +++ b/files/templates/mobile_navigation_bar.html @@ -50,4 +50,4 @@
- + diff --git a/files/templates/patrons.html b/files/templates/patrons.html index f59e5ac54..9373be010 100644 --- a/files/templates/patrons.html +++ b/files/templates/patrons.html @@ -14,7 +14,7 @@ {{loop.index}} {{u.username}} - 2{{u.patron}} + 2{{u.patron}} {% endfor %} diff --git a/files/templates/report_post_modal.html b/files/templates/report_post_modal.html index 94c1e0755..b39c2e078 100644 --- a/files/templates/report_post_modal.html +++ b/files/templates/report_post_modal.html @@ -32,4 +32,4 @@ - + diff --git a/files/templates/settings.html b/files/templates/settings.html index b08ea34d9..b2984d0b6 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -5,20 +5,20 @@ - + - + {% block pagetitle %}Settings - {{SITE_TITLE}}{% endblock %} - + @@ -29,13 +29,13 @@ - + - - + + {% if v.css and not request.path.startswith('/settings/css') %} {% endif %} @@ -241,7 +241,7 @@ {% block onload %}{% endblock %} - + diff --git a/files/templates/settings2.html b/files/templates/settings2.html index c4e9e8917..96d4e9f3f 100644 --- a/files/templates/settings2.html +++ b/files/templates/settings2.html @@ -6,19 +6,19 @@ - + - - + + - + @@ -29,7 +29,7 @@ - + @@ -39,12 +39,12 @@ {% if v %} - - + + {% else %} - - + + {% endif %} diff --git a/files/templates/settings_blocks.html b/files/templates/settings_blocks.html index 1a202730e..9b8838af1 100644 --- a/files/templates/settings_blocks.html +++ b/files/templates/settings_blocks.html @@ -4,7 +4,7 @@ {% block content %} - +
diff --git a/files/templates/settings_profile.html b/files/templates/settings_profile.html index 51b185bc8..1ada54b9a 100644 --- a/files/templates/settings_profile.html +++ b/files/templates/settings_profile.html @@ -501,7 +501,7 @@
- + {% include "gif_modal.html" %} diff --git a/files/templates/settings_security.html b/files/templates/settings_security.html index c52702cbe..7ff000ffd 100644 --- a/files/templates/settings_security.html +++ b/files/templates/settings_security.html @@ -257,6 +257,6 @@ - + {% endblock %} diff --git a/files/templates/shop.html b/files/templates/shop.html index 3f2a692a4..dc4dc262f 100644 --- a/files/templates/shop.html +++ b/files/templates/shop.html @@ -8,7 +8,7 @@ {% block Banner %}
- shop banner + shop banner

Stir drama. Earn coins.

Total sales: {{sales}} coins
Coins spent by you: {{v.coins_spent}} coins
diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index 513f4f3a2..86cc26403 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -5,7 +5,7 @@ - + @@ -14,7 +14,7 @@ - + @@ -25,14 +25,14 @@ - + {% if ref_user %}{{ref_user.username}} invites you to {{SITE_TITLE}}{% else %}Sign up - {{SITE_TITLE}}{% endif %} - - + + @@ -140,7 +140,7 @@
- cover + cover @@ -148,10 +148,10 @@ - + {% if hcaptcha %} - + {% endif %} diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index 482ce700f..6cf9f3f91 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -6,7 +6,7 @@ - + @@ -15,7 +15,7 @@ - + @@ -26,14 +26,14 @@ - + {% if ref_user %}{{ref_user.username}} invites you to {{SITE_TITLE}}{% else %}{{SITE_TITLE}}{% endif %} - - + + @@ -84,7 +84,7 @@
- cover + cover diff --git a/files/templates/sub/subs.html b/files/templates/sub/subs.html index 5d70ab810..b96adeb90 100644 --- a/files/templates/sub/subs.html +++ b/files/templates/sub/subs.html @@ -1,6 +1,6 @@ {% extends "default.html" %} {% block content %} - +
 
diff --git a/files/templates/submission.html b/files/templates/submission.html
index 7d2168664..dafc85c2a 100644
--- a/files/templates/submission.html
+++ b/files/templates/submission.html
@@ -43,7 +43,7 @@
 
 
 
-
+
 {% if p.is_video %}
 	
 {% endif %}
@@ -55,7 +55,7 @@
 
 
 
-
+
 
 
 {% else %}
@@ -68,7 +68,7 @@
 
 {% if p.author %}{% endif %}
 
-
+
 {% if p.url and p.is_video %}
 
 {% endif %}
@@ -80,7 +80,7 @@
 
 {% if p.author %}{% endif %}
 
-
+
 
 
 {% endif %}
@@ -246,9 +246,9 @@
 							{% if p.domain == "twitter.com" %}
 								{{p.embed_url | safe}}
 								{% if v and v.theme.split("_")[0] in ["light", "coffee", "4chan"] %}
-									
+									
 								{% else %}
-									
+									
 								{% endif %}
 							{% elif p.domain in ['youtu.be','youtube.com'] and p.embed_url and p.embed_url.startswith(' 1 and v.admin_level > 2) %}
-	
+	
 {% endif %}
 
 {% if not v or v.highlightcomments %}
-	
+	
 {% endif %}
 
-
+
 
 {% if not p.replies %}
 	{% include "comments.html" %}
 {% endif %}
 
 {% if p.award_count("shit") %}
-	
-	
+	
+	
 {% endif %}
 
 
 {% if p.award_count("fireflies") %}
-	
-	
+	
+	
 {% endif %}
 
 
diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html
index bf035649d..f0fb444b5 100644
--- a/files/templates/submission_listing.html
+++ b/files/templates/submission_listing.html
@@ -1,11 +1,11 @@
 {% set cc='COUNTRY CLUB' %}
 
 {% if not v or v.highlightcomments %}
-	
+	
 {% endif %}
 
 {% if v and v.admin_level > 2 %}
-	
+	
 {% endif %}