它可以 ![]()
您能访问它正在运行的实例吗?如果可以,您能运行以下命令并告诉我结果吗:
./launcher enter app
rails c
TopicEmbed.find_by(topic_id: 157441).as_json
它可以 ![]()
您能访问它正在运行的实例吗?如果可以,您能运行以下命令并告诉我结果吗:
./launcher enter app
rails c
TopicEmbed.find_by(topic_id: 157441).as_json
discourse(prod)> TopicEmbed.find_by(topic_id: 157441).as_json
序列化 ActiveRecord 模型 (TopicEmbed) 时未指定字段是不允许的。请使用 Serializer,或向 #serializable_hash 传递 :only 选项。更多信息:``https://meta.discourse.org/t/-/314495
=>
{“id”=>56685,
“topic_id”=>157441,
“post_id”=>483289,
“embed_url”=>
“``https://tecnoblog.net/noticias/paramount-oferece-us-108-bilhoes-em-dinheiro-para-tomar-warner-da-netflix”``,
“content_sha1”=>nil,
“created_at”=>“2025-12-08T17:54:07.585Z”,
“updated_at”=>“2025-12-09T18:04:33.539Z”,
“deleted_at”=>nil,
“deleted_by_id”=>nil,
“embed_content_cache”=>“”}
discourse(prod)>
在你分享之前编辑过输出吗?我只看了 embed_url 的值是这样的:
“``https://tecnoblog.net/noticias/paramount-oferece-us-108-bilhoes-em-dinheiro-para-tomar-warner-da-netflix”``
你能否再运行一次相同的命令,但这次执行:
./launcher enter app
rails c
TopicEmbed.find_by(topic_id: 157441).embed_url
如果你分享的确实是你数据库中 embed_url 的值,那么这就是问题所在,我将向 discourse/discourse 提交一个小的拉取请求(PR),以处理像这种情况 embed_url 状态不正确(格式错误)的边缘情况。
没有!只是复制粘贴到这里了。
discourse(prod) > TopicEmbed.find_by(topic_id: 157441).embed_url
=> “https://tecnoblog.net/noticias/paramount-oferece-us-108-bilhoes-em-dinheiro-para-tomar-warner-da-netflix”
discourse(prod) >
在这里你可以看到一个使用 Embed JS 创建的主题:
https://tecnoblog.net/comunidade/t/microsoft-edge-ganha-copilot-mode-que-promete-realizar-tarefas-usando-ia-tecnoblog/157661
在这个主题中,“显示完整帖子”也无法正常工作。
所以这里所有的问题都是因为上述的拉取请求(PR)在今年一月开始移除了 TopicEmbed 中的尾部斜杠吗?我对这个更改感到矛盾。说实话,我更希望我们尊重管理员发送给我们的内容。
我认为这是我们问题的根源。
您能运行以下代码吗 @Thiago_Mobilon
url = "https://tecnoblog.net/noticias/governo-renova-app-da-cnh-para-baratear-obtencao-do-documento"
fd = FinalDestination.new(url, validate_uri: true, max_redirects: 5, follow_canonical: true)
uri = fd.resolve
puts uri
html = FinalDestination::HTTP.get(uri)
puts html.truncate(200)
fd.resolve 应该能够在 puts uri 这一行添加尾部斜杠。我担心它失败了。
discourse(prod)> url = "https://tecnoblog.net/noticias/governo-renova-app-da-cnh-para-baratear-obtencao-do-documento"
discourse(prod)>
discourse(prod)> fd = FinalDestination.new(url, validate_uri: true, max_redirects: 5, follow_canonical: true)
discourse(prod)>
discourse(prod)> uri = fd.resolve
discourse(prod)>
discourse(prod)> puts uri
discourse(prod)>
discourse(prod)> html = FinalDestination::HTTP.get(uri)
discourse(prod)>
discourse(prod)> puts html.truncate(200)
https://tecnoblog.net/noticias/governo-renova-app-da-cnh-para-baratear-obtencao-do-documento
=> nil
它确实没有遵循重定向。论坛是否与博客在同一服务器/IP空间中运行?这可能会触发我们的SSRF(服务器端请求伪造)保护。
如果是这种情况,您需要通过设置 allowed_internal_hosts 来允许它。
所以,这里整个问题的根源是因为今年一月上面的拉取请求(PR)开始从 TopicEmbed 中删除尾部斜杠?
请注意
只是顺便提一下,当我在最新版本的 Discourse 上本地运行以下两个命令时,我得到了相同的结果,即文章的 HTML 正文
# 带尾部斜杠 TopicEmbed.find_remote("https://tecnoblog.net/noticias/governo-renova-app-da-cnh-para-baratear-obtencao-do-documento/") # 不带尾部斜杠 TopicEmbed.find_remote("https://tecnoblog.net/noticias/governo-renova-app-da-cnh-para-baratear-obtencao-do-documento") # 产生相同的结果
我对这个更改感到矛盾。老实说,我更希望我们尊重管理员发送给我们的内容。
我们进行此更改的原因是 WP Discourse 嵌入和 javascript 嵌入的工作方式之间存在不一致。Javascript 嵌入一直以来都会规范化 URL。WP Discourse 嵌入通过不同的路径进入,并且(在我们进行更改之前)没有规范化 URL。这导致了一些其他的不一致。
如果是这种情况,您需要在设置
allowed_internal_hosts中允许它
您的意思是像这样吗?(它已经是这样了)
论坛和博客在同一个服务器/IP空间中运行吗?
不,它在一个专用的 VPS 上。博客的机器正在将子目录的流量(nginx)代理到 Discourse VPS。
这导致了一些其他的矛盾之处。
我的另一个问题是,当我向 API 发出 curl 请求,搜索嵌入式 URL 的主题 ID 时,我找不到它,因为有尾部斜杠。Discourse 返回一个 404 页面。
但是,如果我删除了尾部斜杠,它就会返回该值:
mobilon@Thiagos-MacBook-Pro ~ % curl 'https://tecnoblog.net/comunidade/embed/info?embed_url=https://tecnoblog.net/noticias/anatel-e-receita-apreendem-quase-meio-milhao-de-produtos-em-santa-catarina/' -H 'API-KEY: <API KEY>' -H 'API-USERNAME: <USERNAME>'
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="utf-8">
<title>未找到页面 - Tecnoblog 社区</title>
mobilon@Thiagos-MacBook-Pro ~ % curl 'https://tecnoblog.net/comunidade/embed/info?embed_url=https://tecnoblog.net/noticias/anatel-e-receita-apreendem-quase-meio-milhao-de-produtos-em-santa-catarina' -H 'API-KEY: <API KEY>' -H 'API-USERNAME: <USERNAME>'
{"topic_id":157645,"post_id":484103,"topic_slug":"anatel-e-receita-apreendem-quase-meio-milhao-de-produtos-em-santa-catarina-tecnoblog","comment_count":15}%
为了使其工作,我需要在 WordPress 中进行字符串替换,在检查之前删除永久链接的尾部斜杠,但这没有意义,规范的 URL 带有尾部斜杠……
实际上,Discourse 将永久链接规范化为一个不存在的 URL……规范化的版本应该是带有尾部斜杠的版本。
多亏了 @Thiago_Mobilon,我找到了问题并提出了一个修复方案
main ← fix-final-destination-subfolder-ignore
For subfolder installs (e.g. `example.com/forum`), `FinalDestination` was ignori…
@Thiago_Mobilon 修复已完成,请问您能更新吗?
@Thiago_Mobilon 修复已完成,请问您能更新一下吗?
可以了,谢谢 Falco!
但我仍然担心没有尾部斜杠的 URL,原因如我之前帖子中所述。我应该就此事开一个新主题吗 @angus?
Falco:
@Thiago_Mobilon the fix is in, can you please update?
It works, tks Falco!
谢谢,听到这个消息太好了。
But i’m still concerned about the URLs without the trailing slash, for the reasons mentioned in my previous post. Should i open a new topic about this @angus?
当然!这不会影响“完整帖子”功能,因为我们现在可以跟踪与论坛在同一域内的站点的重定向,但你可以就其他疑虑开启一个新主题。