Skip to content

Add carrierwave_store_patch.rb

路志远请求将add-carrierwave-upload-patch合并到main-jh

What does this MR do and why?

Issue: https://jihulab.com/gitlab-cn/internal/content-security-backend/-/issues/41

What

解决图片审核的问题。

  • Before:Issue、Epic 等上传的违规图片、视频,不会被冻结
  • After:Issue、Epic 等上传的违规图片、视频,会被冻结

Why

  • 这些违规图片使用 Carrierwave 的默认方式来上传
  • Carrierwave 会先把图片上传到腾讯云 tmp 目录,上传完毕后再 copy 到最终正式的目录,最后清理 tmp 目录
  • 腾讯云对于 copy 的文件,会跳过审核(认为审核它们的源文件就足够了)
  • 这最终导致违规图片没有被审核

How to fix

通过加一个 Patch 补丁的方式,修改 Carrierwave 默认的上传方式,把 copy 改为直接上传。

覆盖的函数是:/carrierwave/storage/fog.rb#L323

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. 在腾讯云开通 COS 服务
  2. 本地 GDK 通过配置 gitlab.yml 来启用腾讯云对象存储。文档:docs.gitlab.com/.../object_storage
  3. 尝试开闭 Feature Flag ff_direct_upload_to_final_path ,分别在 Issue 中上传图片,观察腾讯云的日志,期待看到
    • 关闭 FF 时,上传方式为 PUTObjectCopy
    • 打开 FF 时,上传方式为 PUTObject
路志远 编辑于

合并请求报告