Use cache tags

This commit is contained in:
Dylan
2025-07-28 16:45:10 +01:00
parent a6be414129
commit 911a49b04f

View File

@@ -67,13 +67,14 @@ def isValidUserAgent(user_agent):
return False return False
def message(text): def message(text):
return render_template( rendered = render_template(
'default.html', 'default.html',
message = text, message = text,
color = config['config']['color'], color = config['config']['color'],
appname = config['config']['appname'], appname = config['config']['appname'],
repo = config['config']['repo'], repo = config['config']['repo'],
url = config['config']['url'] ) url = config['config']['url'] )
return Response(rendered, mimetype='text/html',headers={"Cache-Tag": "message"})
def generateActivityLink(tweetData,media=None,mediatype=None,embedIndex=-1): def generateActivityLink(tweetData,media=None,mediatype=None,embedIndex=-1):
global user_agent global user_agent
@@ -422,26 +423,26 @@ def twitfix(sub_path):
return renderTextTweetEmbed(tweetData) return renderTextTweetEmbed(tweetData)
else: else:
if renderMedia['type'] == "image": if renderMedia['type'] == "image":
return render_template("rawimage.html",media=renderMedia) return Response(render_template("rawimage.html",media=renderMedia),headers={"Cache-Tag": "embed"})
elif renderMedia['type'] == "video" or renderMedia['type'] == "gif": elif renderMedia['type'] == "video" or renderMedia['type'] == "gif":
return render_template("rawvideo.html",media=renderMedia) return Response(render_template("rawvideo.html",media=renderMedia),headers={"Cache-Tag": "embed"})
else: # full embed else: # full embed
embedTweetData = determineEmbedTweet(tweetData) embedTweetData = determineEmbedTweet(tweetData)
embeddingMedia = embedTweetData['hasMedia'] embeddingMedia = embedTweetData['hasMedia']
if "article" in embedTweetData and embedTweetData["article"] is not None: if "article" in embedTweetData and embedTweetData["article"] is not None:
return renderArticleTweetEmbed(tweetData," • See original tweet for full article") return Response(renderArticleTweetEmbed(tweetData," • See original tweet for full article"),headers={"Cache-Tag": "embed"})
elif not embeddingMedia: elif not embeddingMedia:
return renderTextTweetEmbed(tweetData) return Response(renderTextTweetEmbed(tweetData),headers={"Cache-Tag": "embed"})
else: else:
media = determineMediaToEmbed(embedTweetData,embedIndex) media = determineMediaToEmbed(embedTweetData,embedIndex)
suffix="" suffix=""
if "suffix" in media: if "suffix" in media:
suffix = media["suffix"] suffix = media["suffix"]
if media['type'] == "image": if media['type'] == "image":
return renderImageTweetEmbed(tweetData,media['url'] , appnameSuffix=suffix,embedIndex=embedIndex) return Response(renderImageTweetEmbed(tweetData,media['url'] , appnameSuffix=suffix,embedIndex=embedIndex),headers={"Cache-Tag": "embed"})
elif media['type'] == "video" or media['type'] == "gif": elif media['type'] == "video" or media['type'] == "gif":
return renderVideoTweetEmbed(tweetData,media,appnameSuffix=suffix,embedIndex=embedIndex) return Response(renderVideoTweetEmbed(tweetData,media,appnameSuffix=suffix,embedIndex=embedIndex),headers={"Cache-Tag": "embed"})
return message(msgs.failedToScan) return message(msgs.failedToScan)