From 9a4ab635d9a5ef89e1464e07a85ce3c4a245e8ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacio=20Nicol=C3=A1s=20Negro=20Caino?= Date: Wed, 12 Jul 2023 13:10:44 -0300 Subject: [PATCH] Feature/moments file upload progress (#41) * Add on file progress update callbacks * bump package versions * Fix comments --- packages/drops/package.json | 6 +++--- packages/moments/package.json | 4 ++-- packages/moments/src/client/MomentsClient.ts | 7 ++++++- .../moments/src/client/dtos/create/CreateInput.ts | 3 +++ packages/poaps/package.json | 6 +++--- packages/providers/package.json | 3 +-- .../src/core/PoapMomentsApi/PoapMomentsApi.ts | 7 +++++++ packages/providers/src/index.ts | 1 + packages/utils/package.json | 2 +- yarn.lock | 11 +++++------ 10 files changed, 32 insertions(+), 18 deletions(-) diff --git a/packages/drops/package.json b/packages/drops/package.json index 48e4d33b..4d4fef26 100644 --- a/packages/drops/package.json +++ b/packages/drops/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/drops", - "version": "0.0.26", + "version": "0.0.27", "description": "Drops module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -29,7 +29,7 @@ "rollup": "^3.20.2" }, "peerDependencies": { - "@poap-xyz/providers": "0.0.26", - "@poap-xyz/utils": "0.0.26" + "@poap-xyz/providers": "0.0.27", + "@poap-xyz/utils": "0.0.27" } } diff --git a/packages/moments/package.json b/packages/moments/package.json index b6e32306..cbd193e3 100644 --- a/packages/moments/package.json +++ b/packages/moments/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/moments", - "version": "0.0.26", + "version": "0.0.27", "description": "Moments module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -29,6 +29,6 @@ "rollup": "^3.20.2" }, "peerDependencies": { - "@poap-xyz/providers": "0.0.26" + "@poap-xyz/providers": "0.0.27" } } diff --git a/packages/moments/src/client/MomentsClient.ts b/packages/moments/src/client/MomentsClient.ts index c6a6e074..aa50eefe 100644 --- a/packages/moments/src/client/MomentsClient.ts +++ b/packages/moments/src/client/MomentsClient.ts @@ -31,7 +31,12 @@ export class MomentsClient { void onStepUpdate(CreateSteps.REQUESTING_MEDIA_UPLOAD_URL); const { url, key } = await this.poapMomentsApi.getSignedUrl(); void onStepUpdate(CreateSteps.UPLOADING_MEDIA); - await this.poapMomentsApi.uploadFile(input.file, url, input.fileType); + await this.poapMomentsApi.uploadFile( + input.file, + url, + input.fileType, + input.onFileUploadProgress, + ); void onStepUpdate(CreateSteps.UPLOADING_MEDIA_METADATA); // we will be adding metadata to the media in the future void onStepUpdate(CreateSteps.PROCESSING_MEDIA); diff --git a/packages/moments/src/client/dtos/create/CreateInput.ts b/packages/moments/src/client/dtos/create/CreateInput.ts index 3fff1019..21cd5839 100644 --- a/packages/moments/src/client/dtos/create/CreateInput.ts +++ b/packages/moments/src/client/dtos/create/CreateInput.ts @@ -9,6 +9,8 @@ import { CreateSteps } from './CreateSteps'; * @property {string} author - The author of the moment. * @property {string} timeOut - The amount of time to wait until media is processed. * @property {string} fileType - The type of the file. + * @property {(step: CreateSteps) => void | Promise} [onStepUpdate] - Optional callback function to be called when the step changes. + * @property {(progress: number) => void | Promise} [onFileProgress] - Optional callback function to be called when the file upload progress change - progress is a number between 0 and 1. */ export interface CreateMomentInput { dropId: number; @@ -18,4 +20,5 @@ export interface CreateMomentInput { timeOut?: number; fileType: string; onStepUpdate?: (step: CreateSteps) => void | Promise; + onFileUploadProgress?: (progress: number) => void | Promise; } diff --git a/packages/poaps/package.json b/packages/poaps/package.json index 3c95dc4a..2e41b9af 100644 --- a/packages/poaps/package.json +++ b/packages/poaps/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/poaps", - "version": "0.0.26", + "version": "0.0.27", "description": "Poaps module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -29,7 +29,7 @@ "rollup": "^3.20.2" }, "peerDependencies": { - "@poap-xyz/providers": "0.0.26", - "@poap-xyz/utils": "0.0.26" + "@poap-xyz/providers": "0.0.27", + "@poap-xyz/utils": "0.0.27" } } diff --git a/packages/providers/package.json b/packages/providers/package.json index 24afbebd..d29e330f 100644 --- a/packages/providers/package.json +++ b/packages/providers/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/providers", - "version": "0.0.26", + "version": "0.0.27", "description": "Providers module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -26,7 +26,6 @@ }, "devDependencies": { "axios-mock-adapter": "^1.21.4", - "jest-mock-extended": "^3.0.4", "rollup": "^3.20.2" }, "peerDependencies": { diff --git a/packages/providers/src/core/PoapMomentsApi/PoapMomentsApi.ts b/packages/providers/src/core/PoapMomentsApi/PoapMomentsApi.ts index fcbd63fb..d784fff4 100644 --- a/packages/providers/src/core/PoapMomentsApi/PoapMomentsApi.ts +++ b/packages/providers/src/core/PoapMomentsApi/PoapMomentsApi.ts @@ -53,17 +53,24 @@ export class PoapMomentsApi implements MomentsApiProvider { * @param {Buffer} file - The file to be uploaded as a Buffer * @param {string} fileType - The file type * @param {string} signedUrl - The signed URL for uploading the file + * @param {(progress: number) => void} [onProgress] - Optional callback function to be called when the upload progress changes - progress is a number between 0 and 1 * @returns {Promise} - A Promise that resolves when the file has been uploaded */ public async uploadFile( file: Buffer, signedUrl: string, fileType: string, + onProgress?: (progress: number) => void, ): Promise { await axios.put(signedUrl, file, { headers: { 'Content-Type': fileType, }, + onUploadProgress: (progressEvent) => { + if (onProgress) { + onProgress(progressEvent.progress || 0); + } + }, }); } diff --git a/packages/providers/src/index.ts b/packages/providers/src/index.ts index 66b20b94..91ccc87b 100644 --- a/packages/providers/src/index.ts +++ b/packages/providers/src/index.ts @@ -1,4 +1,5 @@ export { InvalidMediaFileError } from './core/PoapMomentsApi/errors/InvalidMediaFileError'; export { DropResponse } from './ports/DropApiProvider/Types/response'; +export { AuthenticationProvider } from './ports/AuthenticationProvider/AuthenticationProvider'; export * from './ports'; export * from './core'; diff --git a/packages/utils/package.json b/packages/utils/package.json index ae75cd7b..566ed052 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/utils", - "version": "0.0.26", + "version": "0.0.27", "description": "Utils module for the poap.js library", "type": "module", "main": "dist/cjs/index.cjs", diff --git a/yarn.lock b/yarn.lock index cc7b5697..fe8576d9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -872,8 +872,8 @@ __metadata: dependencies: rollup: ^3.20.2 peerDependencies: - "@poap-xyz/providers": 0.0.26 - "@poap-xyz/utils": 0.0.26 + "@poap-xyz/providers": 0.0.27 + "@poap-xyz/utils": 0.0.27 languageName: unknown linkType: soft @@ -883,7 +883,7 @@ __metadata: dependencies: rollup: ^3.20.2 peerDependencies: - "@poap-xyz/providers": 0.0.26 + "@poap-xyz/providers": 0.0.27 languageName: unknown linkType: soft @@ -893,8 +893,8 @@ __metadata: dependencies: rollup: ^3.20.2 peerDependencies: - "@poap-xyz/providers": 0.0.26 - "@poap-xyz/utils": 0.0.26 + "@poap-xyz/providers": 0.0.27 + "@poap-xyz/utils": 0.0.27 languageName: unknown linkType: soft @@ -903,7 +903,6 @@ __metadata: resolution: "@poap-xyz/providers@workspace:packages/providers" dependencies: axios-mock-adapter: ^1.21.4 - jest-mock-extended: ^3.0.4 rollup: ^3.20.2 peerDependencies: axios: ^1.3.5