rubyforgood / rubyforgood/skillrx-beacon
TopicFile Sync with ActiveStorage
Open
Nobody has claimed this yet.
cross-app sync
- Dominant language
- HTML
- Stars
- 4
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating TopicFileSync and the TopicFile model, then inspect the ActiveStorage setup and existing database migrations. Define the SyncProgress model and migration from the fields in the issue, connect progress updates to each file download, and verify that an interrupted sync can resume while recording completed and failed files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- backend, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100