How yoke0104x/vod-hwc-shard-upload works
Project Type and Purpose
• This is an NPM client-side SDK library (“vod-hwc-shard-upload”) whose sole purpose is to provide a convenient wrapper around Huawei Cloud VOD’s REST API for large video uploads (shard/chunk upload).
• It is not a full-stack app or microservice, but a reusable module that any TypeScript/JavaScript project can import.
Main Architectural Components
A. Consumer Application
• Your code (or any downstream project) that calls new HuaweiVodUploader(...) and uploader.upload(...).
B. SDK Entry Point
• src/index.ts exports the HuaweiVodUploader class.
C. Core Uploader Module
• HuaweiVodUploader (in src/HuaweiVodUploader.ts):
1. Configuration & Initialization
– Accepts projectId, region, token, bufferSize, etc.
2. Upload Workflow Orchestrator (Facade)
– Manages lifecycle: start session → shard file → upload shards in loop → finalize.
3. Shard Generator
– Reads file from disk/stream, slices into buffers of bufferSize.
4. HTTP Client
– Sends REST calls to Huawei Cloud VOD endpoints:
• CreateUploadSession
• UploadShard (per chunk)
• CompleteUploadSession
5. Progress Emitter
– Calls back onProgress with aggregated progress data after each shard.
D. External Dependencies & Services
• Huawei Cloud VOD API (REST).
• Node.js built-ins (fs, stream, etc.) or browser equivalents.
E. Build & Packaging
• rollup.config.ts bundles source into distributable formats (ESM/CJS).
• tsconfig.json controls TypeScript compilation.
F. CI/CD
• .github/workflows/node.js.yml runs lint/tests/build on each push.
Relationships & Data Flows
• Consumer → (calls) → HuaweiVodUploader.upload()
• HuaweiVodUploader → (initializes) → REST “CreateUploadSession”
• HuaweiVodUploader → (reads + chunks file) → Shard Generator
• Shard Generator → (passes buffers) → HTTP Client
• HTTP Client → (POST each shard) → REST “UploadShard” → (receives) → SDK
• After last shard, SDK → (calls) → REST “CompleteUploadSession”
• SDK → (reports) → onProgress / final Promise resolution → Consumer
Architectural Patterns & Principles
• Facade Pattern: HuaweiVodUploader hides complexity of sharding and all API calls behind a simple interface.
• Single Responsibility: separate chunking logic, HTTP logic, and orchestration.
• Streaming & Buffering: process large files in chunks to avoid memory overload.
• Promise-based async flow with callback hooks for extensibility.