Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/config/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export const DEFAULT_CONSOLE_BASE_URL = 'https://console.cloud.capawesome.io';
export const MANIFEST_JSON_FILE_NAME = 'capawesome-live-update-manifest.json'; // Do NOT change this!
export const MAX_CONCURRENT_FILE_UPLOADS = 20;
export const MAX_CONCURRENT_PART_UPLOADS = 4;
export const MULTIPART_UPLOAD_THRESHOLD_IN_BYTES = 10 * 1024 * 1024; // 10 MB
export const UPLOAD_PART_SIZE_IN_BYTES = 10 * 1024 * 1024; // 10 MB. 5 MB is the minimum part size except for the last part.
9 changes: 4 additions & 5 deletions src/services/app-build-sources.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MAX_CONCURRENT_PART_UPLOADS } from '@/config/index.js';
import { MAX_CONCURRENT_PART_UPLOADS, UPLOAD_PART_SIZE_IN_BYTES } from '@/config/index.js';
import authorizationService from '@/services/authorization-service.js';
import { AppBuildSourceDto, CreateAppBuildSourceDto } from '@/types/app-build-source.js';
import httpClient, { HttpClient } from '@/utils/http-client.js';
Expand Down Expand Up @@ -110,17 +110,16 @@ class AppBuildSourcesServiceImpl implements AppBuildSourcesService {
onProgress?: (currentPart: number, totalParts: number) => void,
): Promise<AppBuildSourceUploadPartDto[]> {
const uploadedParts: AppBuildSourceUploadPartDto[] = [];
const partSize = 10 * 1024 * 1024; // 10 MB
const totalParts = Math.ceil(dto.buffer.byteLength / partSize);
const totalParts = Math.ceil(dto.buffer.byteLength / UPLOAD_PART_SIZE_IN_BYTES);
let partNumber = 0;
const uploadNextPart = async () => {
if (partNumber >= totalParts) {
return;
}
partNumber++;
onProgress?.(partNumber, totalParts);
const start = (partNumber - 1) * partSize;
const end = Math.min(start + partSize, dto.buffer.byteLength);
const start = (partNumber - 1) * UPLOAD_PART_SIZE_IN_BYTES;
const end = Math.min(start + UPLOAD_PART_SIZE_IN_BYTES, dto.buffer.byteLength);
const partBuffer = dto.buffer.subarray(start, end);

const uploadedPart = await this.createUploadPart({
Expand Down
15 changes: 9 additions & 6 deletions src/services/app-bundle-files.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { MAX_CONCURRENT_PART_UPLOADS } from '@/config/index.js';
import {
MAX_CONCURRENT_PART_UPLOADS,
MULTIPART_UPLOAD_THRESHOLD_IN_BYTES,
UPLOAD_PART_SIZE_IN_BYTES,
} from '@/config/index.js';
import authorizationService from '@/services/authorization-service.js';
import { AppBundleFileDto, CreateAppBundleFileDto } from '@/types/app-bundle-file.js';
import httpClient, { HttpClient } from '@/utils/http-client.js';
Expand All @@ -23,7 +27,7 @@ class AppBundleFilesServiceImpl implements AppBundleFilesService {
onProgress?: (currentPart: number, totalParts: number) => void,
): Promise<AppBundleFileDto> {
const sizeInBytes = dto.buffer.byteLength;
const useMultipartUpload = sizeInBytes >= 50 * 1024 * 1024; // 50 MB
const useMultipartUpload = sizeInBytes >= MULTIPART_UPLOAD_THRESHOLD_IN_BYTES;
const formData = new FormData();
Comment thread
robingenz marked this conversation as resolved.
formData.append('checksum', dto.checksum);
if (!useMultipartUpload) {
Expand Down Expand Up @@ -117,17 +121,16 @@ class AppBundleFilesServiceImpl implements AppBundleFilesService {
onProgress?: (currentPart: number, totalParts: number) => void,
): Promise<AppBundleFileUploadPartDto[]> {
const uploadedParts: AppBundleFileUploadPartDto[] = [];
const partSize = 10 * 1024 * 1024; // 10 MB. 5 MB is the minimum part size except for the last part.
const totalParts = Math.ceil(dto.buffer.byteLength / partSize);
const totalParts = Math.ceil(dto.buffer.byteLength / UPLOAD_PART_SIZE_IN_BYTES);
let partNumber = 0;
const uploadNextPart = async () => {
if (partNumber >= totalParts) {
return;
}
partNumber++;
onProgress?.(partNumber, totalParts);
const start = (partNumber - 1) * partSize;
const end = Math.min(start + partSize, dto.buffer.byteLength);
const start = (partNumber - 1) * UPLOAD_PART_SIZE_IN_BYTES;
const end = Math.min(start + UPLOAD_PART_SIZE_IN_BYTES, dto.buffer.byteLength);
const partBuffer = dto.buffer.subarray(start, end);

const uploadedPart = await this.createUploadPart({
Expand Down
Loading