mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-04-11.git
synced 2024-08-15 00:43:26 +00:00
Fix comments where link has no host
This commit is contained in:
parent
fe5286a210
commit
2c6f8022e6
2 changed files with 44 additions and 37 deletions
|
@ -1964,43 +1964,7 @@ get "/api/v1/comments/:id" do |env|
|
||||||
content_html = HTML.escape(content_html)
|
content_html = HTML.escape(content_html)
|
||||||
end
|
end
|
||||||
|
|
||||||
content_html ||= node_comment["contentText"]["runs"].as_a.map do |run|
|
content_html ||= content_to_comment_html(node_comment["contentText"]["runs"].as_a)
|
||||||
text = HTML.escape(run["text"].as_s)
|
|
||||||
|
|
||||||
if run["text"] == "\n"
|
|
||||||
text = "<br>"
|
|
||||||
end
|
|
||||||
|
|
||||||
if run["bold"]?
|
|
||||||
text = "<b>#{text}</b>"
|
|
||||||
end
|
|
||||||
|
|
||||||
if run["italics"]?
|
|
||||||
text = "<i>#{text}</i>"
|
|
||||||
end
|
|
||||||
|
|
||||||
if run["navigationEndpoint"]?
|
|
||||||
url = run["navigationEndpoint"]["urlEndpoint"]?.try &.["url"].as_s
|
|
||||||
if url
|
|
||||||
url = URI.parse(url)
|
|
||||||
|
|
||||||
if {"m.youtube.com", "www.youtube.com", "youtu.be"}.includes? url.host
|
|
||||||
if url.path == "/redirect"
|
|
||||||
url = HTTP::Params.parse(url.query.not_nil!)["q"]
|
|
||||||
else
|
|
||||||
url = url.full_path
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
url = run["navigationEndpoint"]["commandMetadata"]?.try &.["webCommandMetadata"]["url"].as_s
|
|
||||||
end
|
|
||||||
|
|
||||||
text = %(<a href="#{url}">#{text}</a>)
|
|
||||||
end
|
|
||||||
|
|
||||||
text
|
|
||||||
end.join.rchop('\ufeff')
|
|
||||||
|
|
||||||
content_html, content = html_to_content(content_html)
|
content_html, content = html_to_content(content_html)
|
||||||
|
|
||||||
author = node_comment["authorText"]?.try &.["simpleText"]
|
author = node_comment["authorText"]?.try &.["simpleText"]
|
||||||
|
|
|
@ -242,3 +242,46 @@ def fill_links(html, scheme, host)
|
||||||
|
|
||||||
return html
|
return html
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def content_to_comment_html(content)
|
||||||
|
comment_html = content.map do |run|
|
||||||
|
text = HTML.escape(run["text"].as_s)
|
||||||
|
|
||||||
|
if run["text"] == "\n"
|
||||||
|
text = "<br>"
|
||||||
|
end
|
||||||
|
|
||||||
|
if run["bold"]?
|
||||||
|
text = "<b>#{text}</b>"
|
||||||
|
end
|
||||||
|
|
||||||
|
if run["italics"]?
|
||||||
|
text = "<i>#{text}</i>"
|
||||||
|
end
|
||||||
|
|
||||||
|
if run["navigationEndpoint"]?
|
||||||
|
url = run["navigationEndpoint"]["urlEndpoint"]?.try &.["url"].as_s
|
||||||
|
if url
|
||||||
|
url = URI.parse(url)
|
||||||
|
|
||||||
|
puts url.path
|
||||||
|
puts url.host
|
||||||
|
if !url.host || {"m.youtube.com", "www.youtube.com", "youtu.be"}.includes? url.host
|
||||||
|
if url.path == "/redirect"
|
||||||
|
url = HTTP::Params.parse(url.query.not_nil!)["q"]
|
||||||
|
else
|
||||||
|
url = url.full_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
url = run["navigationEndpoint"]["commandMetadata"]?.try &.["webCommandMetadata"]["url"].as_s
|
||||||
|
end
|
||||||
|
|
||||||
|
text = %(<a href="#{url}">#{text}</a>)
|
||||||
|
end
|
||||||
|
|
||||||
|
text
|
||||||
|
end.join.rchop('\ufeff')
|
||||||
|
|
||||||
|
return comment_html
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue