Skip to content

refactor(utils): migrate uploads and uploadsSHA1Worker from Flow to T… - #4846

Open
bonchevskyi wants to merge 1 commit into
box:masterfrom
bonchevskyi:refactor/flow-to-ts-utils-uploads
Open

bonchevskyi wants to merge 1 commit into
box:masterfrom
bonchevskyi:refactor/flow-to-ts-utils-uploads

Conversation

@bonchevskyi

@bonchevskyi bonchevskyi commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR migrates upload-related utilities in src/utils from Flow (.js) to TypeScript (.ts), disjoint from other utils migration PRs.

Migrated utilities

  • uploads
  • uploadsSHA1Worker

Components / API modules touched (consumers)

  • src/api/uploads/MultiputUpload.js — imports uploadsSHA1Worker (import path unchanged; bundler resolves .ts)

Changes

  • Renamed uploads and uploadsSHA1Worker to .ts and added matching .js.flow stubs for remaining Flow importers
  • Preserved Rusha/asm worker implementation in uploadsSHA1Worker.ts with existing @ts-nocheck / eslint disable (behavior unchanged)

Contract

  • Declared Flow contract and runtime behavior preserved (exports, signatures, and upload helper logic unchanged relative to the previous .js sources)

Related

  • Disjoint from other utils migration PRs:
    • Batch 1: Browser, Cache, LocalStore, TokenService
    • Batch 2: webcrypto, error, file, function, flatten, fuzzySearch, domPolyfill, getFileSize, validators
    • Batch 3: base64, comparator, download, env, hex, keys, parseCSV, parseEmails, performance, relativeTime, sleep, storybook, url
    • Batch 4 (dom-theme): createTheme, dom, iframe, sorter

Summary by CodeRabbit

  • New Features
    • Improved file and folder upload handling, including support for package files and drag-and-drop items.
    • Added support for preserving upload options across selected files and transferred items.
    • Added more reliable upload identifiers based on file details, folder context, and upload time.
    • Added resumable multi-part upload support where browser security and capability requirements are met.
    • Improved upload integrity checks with background SHA-1 processing for file parts.
    • Added safer date, timestamp, JSON, and retry-delay handling for uploads.

@bonchevskyi
bonchevskyi requested a review from a team as a code owner September 18, 2026 14:24
@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 4eb1d13a-1694-47f9-b2e4-98588fa93ba1

📥 Commits

Reviewing files that changed from the base of the PR and between a4ca178 and 52b9df5.

📒 Files selected for processing (5)
  • src/utils/__tests__/uploads.test.ts
  • src/utils/uploads.js.flow
  • src/utils/uploads.ts
  • src/utils/uploadsSHA1Worker.js.flow
  • src/utils/uploadsSHA1Worker.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


Walkthrough

The PR adds upload utilities for input normalization, transfer-item handling, identifiers, and capability checks. It also adds a SHA-1 web worker and updates upload ID tests to pass root folder IDs as strings.

Changes

Upload handling

Layer / File(s) Summary
Upload utility contracts
src/utils/uploads.ts
Adds option normalization, date and JSON helpers, timestamp formatting, retry-delay calculation, and exports.
Transfer processing and identifiers
src/utils/uploads.ts, src/utils/__tests__/uploads.test.ts
Adds transfer-item extraction, folder and package detection, API-option preservation, ID generation, multiput checks, and updated root folder test inputs.
SHA-1 upload worker
src/utils/uploadsSHA1Worker.ts
Adds a Rusha-based worker that validates part order, returns processed parts, reports completion or errors, and revokes its ObjectURL on termination.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant MainThread
  participant createWorker
  participant Worker
  participant Rusha
  MainThread->>createWorker: createWorker()
  createWorker->>Worker: Instantiate worker from Blob ObjectURL
  MainThread->>Worker: Send ordered file part
  Worker->>Rusha: Append part contents
  Rusha-->>Worker: Update SHA-1 state
  Worker-->>MainThread: partDone with transferred contents
  Worker-->>MainThread: done with final SHA-1
Loading

Suggested reviewers: greg-in-a-box

Merge Risk: ⚪ Minimal · up to 52b9d

The migrated upload worker resolves correctly in the configured build and test environments, and no concrete current-head regression remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the migration of the uploads utilities from Flow to TypeScript. It matches the primary change described in the pull request.
Description check ✅ Passed The description provides a clear summary, lists the migrated utilities, identifies affected consumers, documents implementation details, and states that behavior and contracts are preserved. It satisf…
Docstring Coverage ✅ Passed Docstring coverage is 95.65% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 3 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

Comment @coderabbitai help to get the list of available commands.

@greg-in-a-box greg-in-a-box left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Straightforward Flow → TypeScript migration of uploads and uploadsSHA1Worker, consistent with the other utils migration batches.

What looks good

  • Export surface matches master; runtime logic is preserved (Flow casts → TS assertions, docs trimmed).
  • .js.flow stubs via rename match the established migration pattern for remaining Flow importers.
  • uploadsSHA1Worker correctly keeps the Rusha/asm worker under @ts-nocheck / eslint-disable with no behavioral change.
  • Test updates for getFileId(file, '0') and rootFolderId: '0' align the tests with the existing string contract (production callers already pass rootFolderId).
  • isMultiputSupported return is explicitly boolean (!!); same truthiness for callers.

Nits (non-blocking)

  • CI (lint_test_build) was still in progress at review time — worth confirming green before merge.

Verdict: Approve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants