TopicFile Sync with ActiveStorage

未关闭
#26 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
rails, ruby
领域
backend, database

调研方向

首先定位 TopicFileSync 和 TopicFile 模型,然后检查 ActiveStorage 设置以及现有的数据库迁移。根据 issue 中的字段定义 SyncProgress 模型和迁移,将进度更新与每个文件下载关联起来,并验证中断的同步可以恢复,同时记录已完成和失败的文件。

由索引模型根据 Issue 内容生成。

描述

cross-app sync

Sync files and attach using ActiveStorage

  class TopicFileSync
    def sync(file_data, topic)
      topic_file = TopicFile.find_or_initialize_by(external_id: file_data["id"])

      # Skip if checksum unchanged (file hasn't changed on server)
      return topic_file if topic_file.external_checksum == file_data["checksum"]

      # Download and verify
      downloaded_path = downloader.download(file_data["id"], expected_checksum: file_data["checksum"])
      verifier.verify!(downloaded_path, file_data["checksum"])

      # Attach via ActiveStorage
      File.open(downloaded_path, "rb") do |io|
        topic_file.file.attach(
          io: io,
          filename: file_data["filename"],
          content_type: file_data["content_type"]
        )
      end

      topic_file.update!(
        topic: topic,
        filename: file_data["filename"],
        file_type: extract_file_type(file_data["content_type"]),
        file_size: file_data["size_bytes"],
        external_checksum: file_data["checksum"]
      )

      topic_file
    ensure
      FileUtils.rm_f(downloaded_path) if downloaded_path
    end
  end

Track and persist download progress for resume

  • Create SyncProgress model:
create_table :sync_progress do |t|
  t.string :manifest_version
  t.string :status  # pending, downloading, completed, failed
  t.integer :total_files
  t.integer :completed_files
  t.integer :total_bytes
  t.integer :downloaded_bytes
  t.json :pending_file_ids  # files remaining to download
  t.json :failed_file_ids   # files that failed
  t.timestamps
end
  • Update progress after each file download
  • Use for resume after interruption/restart
主要语言
HTML
星标
4
派生
0
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rubyforgood/skillrx-beacon 的其他 Issue

查看 rubyforgood/skillrx-beacon 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。