Add subdomains as input for translation #273
This commit is contained in:
+17
-1
@@ -204,4 +204,20 @@ def test_embed_action():
|
|||||||
resp = client.get(testTextTweet.replace("https://twitter.com",""),headers={"User-Agent":"Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)"})
|
resp = client.get(testTextTweet.replace("https://twitter.com",""),headers={"User-Agent":"Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)"})
|
||||||
assert resp.status_code==200
|
assert resp.status_code==200
|
||||||
assert "application/activity+json" in str(resp.data)
|
assert "application/activity+json" in str(resp.data)
|
||||||
assert "%F0%9F%92%96" not in str(resp.data) # 💖
|
assert "%F0%9F%92%96" not in str(resp.data) # 💖
|
||||||
|
|
||||||
|
def test_embed_translated():
|
||||||
|
resp = client.get(testTextTweet.replace("https://twitter.com","")+"/jp",headers={"User-Agent":"test"})
|
||||||
|
assert resp.status_code==200
|
||||||
|
assert "→" in resp.text
|
||||||
|
resp = client.get(testTextTweet.replace("https://twitter.com","")+"/ja",headers={"User-Agent":"test"})
|
||||||
|
assert resp.status_code==200
|
||||||
|
assert "→" in resp.text
|
||||||
|
|
||||||
|
def test_embed_translated_subdomain():
|
||||||
|
resp = client.get(testTextTweet.replace("https://twitter.com","https://jp.vxtwitter.com"),headers={"User-Agent":"test"})
|
||||||
|
assert resp.status_code==200
|
||||||
|
assert "→" in resp.text
|
||||||
|
resp = client.get(testTextTweet.replace("https://twitter.com","https://ja.vxtwitter.com"),headers={"User-Agent":"test"})
|
||||||
|
assert resp.status_code==200
|
||||||
|
assert "→" in resp.text
|
||||||
+13
-3
@@ -322,13 +322,18 @@ def getUserData(twitter_url,includeFeed=False):
|
|||||||
@app.route('/<path:sub_path>') # Default endpoint used by everything
|
@app.route('/<path:sub_path>') # Default endpoint used by everything
|
||||||
def twitfix(sub_path):
|
def twitfix(sub_path):
|
||||||
splitPath=sub_path.split("/")
|
splitPath=sub_path.split("/")
|
||||||
|
if "|" in splitPath[-1]: # discord doesn't strip this when a link is spoilered
|
||||||
|
splitPath[-1] = splitPath[-1].replace("|","")
|
||||||
|
|
||||||
|
subdomain = request.host.rsplit(".",2)[0]
|
||||||
|
|
||||||
global user_agent
|
global user_agent
|
||||||
user_agent = request.headers.get('User-Agent', None)
|
user_agent = request.headers.get('User-Agent', None)
|
||||||
if user_agent is None:
|
if user_agent is None:
|
||||||
user_agent = "unknown"
|
user_agent = "unknown"
|
||||||
|
|
||||||
isApiRequest=request.url.startswith("https://api.vx") or request.url.startswith("http://api.vx")
|
isApiRequest=subdomain=="api"
|
||||||
if not isApiRequest and (request.url.startswith("https://l.vx") or request.url.startswith("https://old.vx")) and "Discord" in user_agent:
|
if not isApiRequest and (subdomain=="l" or subdomain=="old") and "Discord" in user_agent:
|
||||||
user_agent = user_agent.replace("Discord","LegacyEmbed") # TODO: Clean up; This is a hacky fix to make the new activity embed not trigger
|
user_agent = user_agent.replace("Discord","LegacyEmbed") # TODO: Clean up; This is a hacky fix to make the new activity embed not trigger
|
||||||
if sub_path in staticFiles:
|
if sub_path in staticFiles:
|
||||||
if 'path' not in staticFiles[sub_path] or staticFiles[sub_path]["path"] == None:
|
if 'path' not in staticFiles[sub_path] or staticFiles[sub_path]["path"] == None:
|
||||||
@@ -378,6 +383,11 @@ def twitfix(sub_path):
|
|||||||
translationLang = translation.languageAliases[splitPath[translationIndex].upper()]
|
translationLang = translation.languageAliases[splitPath[translationIndex].upper()]
|
||||||
else:
|
else:
|
||||||
translationLang = splitPath[translationIndex].lower()
|
translationLang = splitPath[translationIndex].lower()
|
||||||
|
elif subdomain.upper() in translation.mergedLangs:
|
||||||
|
if subdomain.upper() in translation.languageAliases:
|
||||||
|
translationLang = translation.languageAliases[subdomain.upper()]
|
||||||
|
else:
|
||||||
|
translationLang = subdomain.lower()
|
||||||
|
|
||||||
if isApiRequest:
|
if isApiRequest:
|
||||||
if "include_txt" in request.args:
|
if "include_txt" in request.args:
|
||||||
@@ -407,7 +417,7 @@ def twitfix(sub_path):
|
|||||||
requestUrlWithoutQuery = request.url
|
requestUrlWithoutQuery = request.url
|
||||||
|
|
||||||
directEmbed=False
|
directEmbed=False
|
||||||
if requestUrlWithoutQuery.startswith("https://d.vx") or requestUrlWithoutQuery.endswith(".mp4") or requestUrlWithoutQuery.endswith(".png"):
|
if subdomain=="d" or requestUrlWithoutQuery.endswith(".mp4") or requestUrlWithoutQuery.endswith(".png"):
|
||||||
directEmbed = True
|
directEmbed = True
|
||||||
# remove the .mp4 from the end of the URL
|
# remove the .mp4 from the end of the URL
|
||||||
if requestUrlWithoutQuery.endswith(".mp4") or requestUrlWithoutQuery.endswith(".png"):
|
if requestUrlWithoutQuery.endswith(".mp4") or requestUrlWithoutQuery.endswith(".png"):
|
||||||
|
|||||||
Reference in New Issue
Block a user