我曾多次遇到并调试过此类问题,这很复杂,请耐心配合。
请运行以下脚本并在此处分享输出
# 用您正在调试的主题 ID 或 URL 替换此处内容
topic_id = 386983
# 1. 检查 TopicEmbed 是否存在及其内容
te = TopicEmbed.find_by(topic_id: topic_id)
puts "TopicEmbed 存在: #{te.present?}"
puts "嵌入 URL: #{te&.embed_url}"
puts "内容缓存存在: #{te&.embed_content_cache.present?}"
puts "内容缓存长度: #{te&.embed_content_cache&.length || 0}"
puts "内容 SHA1: #{te&.content_sha1}"
# 2. 检查实际缓存的内容(前 500 个字符)
puts "\n--- 缓存内容预览 ---"
puts te&.embed_content_cache&.truncate(500)
# 3. 尝试从远程 URL 获取
if te&.embed_url.present?
puts "\n--- 尝试远程获取 ---"
begin
response = TopicEmbed.find_remote(te.embed_url)
puts "远程获取成功: #{response.present?}"
puts "远程正文存在: #{response&.body.present?}"
puts "远程正文长度: #{response&.body&.length || 0}"
puts "远程标题: #{response&.title}"
puts "远程正文: #{response&.body&.truncate(500)}"
rescue => e
puts "远程获取失败: #{e.message}"
end
end
# 4. 检查 expanded_for 会返回什么
if te.present?
puts "\n--- 测试 expanded_for ---"
post = Post.find(te.post_id)
# 清除缓存以强制重新获取
Discourse.cache.delete("embed-topic:#{topic_id}")
begin
expanded = TopicEmbed.expanded_for(post)
puts "展开内容存在: #{expanded.present?}"
puts "展开内容长度: #{expanded&.length || 0}"
rescue => e
puts "expanded_for 失败: #{e.message}"
end
end
# 5. 检查相关设置
puts "\n--- 站点设置 ---"
puts "embed_truncate: #{SiteSetting.embed_truncate}"
puts "allowed_embed_selectors: #{SiteSetting.allowed_embed_selectors}"
puts "blocked_embed_selectors: #{SiteSetting.blocked_embed_selectors}"
这将显示为什么 https://tecnoblog.net/comunidade/t/governo-renova-app-da-cnh-para-baratear-obtencao-do-documento/157462?u=falco 出现故障