Ameba: Fix Naming/VariableNames (#4790)

Related to issue 2231
This commit is contained in:
Samantaz Fox 2024-08-13 20:26:15 +02:00
commit 88b9f17388
No known key found for this signature in database
GPG Key ID: F42821059186176E
3 changed files with 24 additions and 24 deletions

View File

@ -5,35 +5,35 @@ def text_to_parsed_content(text : String) : JSON::Any
# In first case line is just a simple node before
# check patterns inside line
# { 'text': line }
currentNodes = [] of JSON::Any
initialNode = {"text" => line}
currentNodes << (JSON.parse(initialNode.to_json))
current_nodes = [] of JSON::Any
initial_node = {"text" => line}
current_nodes << (JSON.parse(initial_node.to_json))
# For each match with url pattern, get last node and preserve
# last node before create new node with url information
# { 'text': match, 'navigationEndpoint': { 'urlEndpoint' : 'url': match } }
line.scan(/https?:\/\/[^ ]*/).each do |urlMatch|
line.scan(/https?:\/\/[^ ]*/).each do |url_match|
# Retrieve last node and update node without match
lastNode = currentNodes[currentNodes.size - 1].as_h
splittedLastNode = lastNode["text"].as_s.split(urlMatch[0])
lastNode["text"] = JSON.parse(splittedLastNode[0].to_json)
currentNodes[currentNodes.size - 1] = JSON.parse(lastNode.to_json)
last_node = current_nodes[-1].as_h
splitted_last_node = last_node["text"].as_s.split(url_match[0])
last_node["text"] = JSON.parse(splitted_last_node[0].to_json)
current_nodes[-1] = JSON.parse(last_node.to_json)
# Create new node with match and navigation infos
currentNode = {"text" => urlMatch[0], "navigationEndpoint" => {"urlEndpoint" => {"url" => urlMatch[0]}}}
currentNodes << (JSON.parse(currentNode.to_json))
current_node = {"text" => url_match[0], "navigationEndpoint" => {"urlEndpoint" => {"url" => url_match[0]}}}
current_nodes << (JSON.parse(current_node.to_json))
# If text remain after match create new simple node with text after match
afterNode = {"text" => splittedLastNode.size > 1 ? splittedLastNode[1] : ""}
currentNodes << (JSON.parse(afterNode.to_json))
after_node = {"text" => splitted_last_node.size > 1 ? splitted_last_node[1] : ""}
current_nodes << (JSON.parse(after_node.to_json))
end
# After processing of matches inside line
# Add \n at end of last node for preserve carriage return
lastNode = currentNodes[currentNodes.size - 1].as_h
lastNode["text"] = JSON.parse("#{currentNodes[currentNodes.size - 1]["text"]}\n".to_json)
currentNodes[currentNodes.size - 1] = JSON.parse(lastNode.to_json)
last_node = current_nodes[-1].as_h
last_node["text"] = JSON.parse("#{last_node["text"]}\n".to_json)
current_nodes[-1] = JSON.parse(last_node.to_json)
# Finally add final nodes to nodes returned
currentNodes.each do |node|
current_nodes.each do |node|
nodes << (node)
end
end
@ -53,8 +53,8 @@ def content_to_comment_html(content, video_id : String? = "")
text = HTML.escape(run["text"].as_s)
if navigationEndpoint = run.dig?("navigationEndpoint")
text = parse_link_endpoint(navigationEndpoint, text, video_id)
if navigation_endpoint = run.dig?("navigationEndpoint")
text = parse_link_endpoint(navigation_endpoint, text, video_id)
end
text = "<b>#{text}</b>" if run["bold"]?

View File

@ -52,9 +52,9 @@ def recode_length_seconds(time)
end
def decode_interval(string : String) : Time::Span
rawMinutes = string.try &.to_i32?
raw_minutes = string.try &.to_i32?
if !rawMinutes
if !raw_minutes
hours = /(?<hours>\d+)h/.match(string).try &.["hours"].try &.to_i32
hours ||= 0
@ -63,7 +63,7 @@ def decode_interval(string : String) : Time::Span
time = Time::Span.new(hours: hours, minutes: minutes)
else
time = Time::Span.new(minutes: rawMinutes)
time = Time::Span.new(minutes: raw_minutes)
end
return time

View File

@ -179,8 +179,8 @@ module Invidious::Routes::API::V1::Misc
begin
resolved_url = YoutubeAPI.resolve_url(url.as(String))
endpoint = resolved_url["endpoint"]
pageType = endpoint.dig?("commandMetadata", "webCommandMetadata", "webPageType").try &.as_s || ""
if pageType == "WEB_PAGE_TYPE_UNKNOWN"
page_type = endpoint.dig?("commandMetadata", "webCommandMetadata", "webPageType").try &.as_s || ""
if page_type == "WEB_PAGE_TYPE_UNKNOWN"
return error_json(400, "Unknown url")
end
@ -196,7 +196,7 @@ module Invidious::Routes::API::V1::Misc
json.field "playlistId", sub_endpoint["playlistId"].as_s if sub_endpoint["playlistId"]?
json.field "startTimeSeconds", sub_endpoint["startTimeSeconds"].as_i if sub_endpoint["startTimeSeconds"]?
json.field "params", params.try &.as_s
json.field "pageType", pageType
json.field "pageType", page_type
end
end
end