# 处理来自配置错误的网站的损坏的 onebox 图片

**URL:** <https://meta.discourse.org/t/handling-of-broken-onebox-images-from-malconfigured-sites/199079>\
**Category:** Feature\
**Created:** [2021年八月3日 21:20 UTC](https://meta.discourse.org/t/handling-of-broken-onebox-images-from-malconfigured-sites/199079 "2021-08-03T21:20:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TallTrees](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/talltrees/32/208620_2.png) [@TallTrees](https://meta.discourse.org/u/TallTrees)\
**Post date:** [2021年八月3日 21:20 UTC](https://meta.discourse.org/t/handling-of-broken-onebox-images-from-malconfigured-sites/199079/1 "2021-08-03T21:20:51Z")

</div>

我注意到有很多配置不当的网站，它们似乎采用了各种方法来阻止图片的“热链接”，但在嵌入数据中却仍然返回了这些图片的链接，例如：

> **[Pavilion hire - Horniman Museum and Gardens](https://www.horniman.ac.uk/space/pavilion-hire/)**
>
> Our bright and airy Pavilion is a contemporary venue which includes a large outside terrace overlooking the Gardens.

> **[Facilities for Hire](http://www.foresthillmethodistchurch.org/facilities-for-hire-lettings-policy/)**
>
> Forest Hill Methodist Church and Centre

通过 [http://debug.iframely.com/](http://debug.iframely.com/) 检查后，我真心认为这本身并不是 Discourse 的问题，但看起来确实不太美观。

一个想法是，在生成帖子时，onebox 的创建过程可以获取图片，然后要么存储缩略图以供后续使用，要么如果无法获取，则表现得像没有指定图片一样。

存储图片副本将相当稳健且具有前瞻性，我认为这应属于版权法中的“合理使用”范畴（原始网站不会因重复使用从元数据中获取的 130x90 缩略图而受损，尽管我不是法律专家）。

如果不行，我曾尝试编写一个组件来捕获图片的错误事件，然后添加一个类将其或其包装器设置为 `display:none`。但我尚未成功，因为我在 `decorateCookedElement()` 中陷入了困境……我不确定自己是否找对了地方。

那么，是否只有我频繁遇到 onebox 中图片损坏的问题？其他人有解决方法吗？

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2021年八月3日 21:23 UTC](https://meta.discourse.org/t/handling-of-broken-onebox-images-from-malconfigured-sites/199079/2 "2021-08-03T21:23:16Z")

</div>

> [@TallTrees](#):
>
> 有一个想法是，在帖子渲染时获取单盒（onebox）所需的图片，并存储缩略图以便后续调用，

我们不是已经这样做了吗？再检查一下你的帖子！

显然不是在渲染时进行，因为你不希望将网络请求放在这条关键路径上。但我们会将其加入队列，并在后台下载单盒图片。

如果启用了“将远程图片下载到本地”（默认值为 true），我们会等待“编辑宽限期”（默认为 300 秒）后再进行下载。

---

<div class="post-metadata">

**Author:** ![TallTrees](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/talltrees/32/208620_2.png) [@TallTrees](https://meta.discourse.org/u/TallTrees)\
**Post date:** [2021年八月3日 21:55 UTC](https://meta.discourse.org/t/handling-of-broken-onebox-images-from-malconfigured-sites/199079/3 "2021-08-03T21:55:56Z")

</div>

太棒了！

我之前在查看“单个帖子设置”，所以没注意到“将远程图片下载到本地”这一选项，它之前是禁用的。

我已经启用该选项，并重新生成了部分帖子的 HTML。希望这能整理好一些问题。

感谢你的提示 ❤

---

<div class="post-metadata">

**Author:** ![diakopter](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@diakopter](https://meta.discourse.org/u/diakopter)\
**Post date:** [2021年八月3日 22:15 UTC](https://meta.discourse.org/t/handling-of-broken-onebox-images-from-malconfigured-sites/199079/4 "2021-08-03T22:15:28Z")

</div>

谢谢！我刚才还在另一个话题里问到了这件事。

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2021年八月3日 22:58 UTC](https://meta.discourse.org/t/handling-of-broken-onebox-images-from-malconfigured-sites/199079/5 "2021-08-03T22:58:54Z")

</div>

> [@TallTrees](#):
>
> 我一直在查看“单个盒子”设置，所以没注意到“将远程图片下载到本地”选项，该选项此前处于禁用状态。

在更改默认设置时，务必谨慎并仔细考虑其后果。我们出厂预设了最优选项，偏离这些设置可能会带来意想不到的后果。

---

<div class="post-metadata">

**Author:** ![TallTrees](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/talltrees/32/208620_2.png) [@TallTrees](https://meta.discourse.org/u/TallTrees)\
**Post date:** [2021年八月4日 07:09 UTC](https://meta.discourse.org/t/handling-of-broken-onebox-images-from-malconfigured-sites/199079/6 "2021-08-04T07:09:46Z")

</div>

说得有道理。我通常都使用默认设置，但在这个情况下，该设置似乎是由前任管理员修改的——我不确定具体原因。

希望这个设置现在也能让 Instagram 单盒中的图片保持持久显示。

再次感谢，向 Discourse 致以满满的爱 ❤

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2022年一月17日 22:14 UTC](https://meta.discourse.org/t/handling-of-broken-onebox-images-from-malconfigured-sites/199079/7 "2022-01-17T22:14:22Z")

</div>

是的，现在 onebox 在无法 onebox 时提供了更好的反馈，它会尽力解释原因。
