Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Moments] Rename medias to media #124

Merged
merged 2 commits into from
Jun 7, 2024
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
4 changes: 2 additions & 2 deletions examples/moments/backend/src/methods/create_moment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MomentsClient, CreateMomentInput } from '@poap-xyz/moments';
import { CreateMomentInput, MomentsClient } from '@poap-xyz/moments';
import fs from 'fs';
import mime from 'mime';

Expand All @@ -18,7 +18,7 @@ export const create_moment = async (client: MomentsClient): Promise<void> => {
*/
tokenId: 6568008,
author: '0x82AB2941Cf555CED5ad7Ed232a5B5f6083815FBC',
medias: [
media: [
{
fileBinary: fileBuffer,
fileType: mimeType,
Expand Down
6 changes: 3 additions & 3 deletions packages/drops/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/drops",
"version": "0.3.0",
"version": "0.4.0",
"description": "Drops module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down Expand Up @@ -29,7 +29,7 @@
"node": ">=18"
},
"dependencies": {
"@poap-xyz/providers": "0.3.0",
"@poap-xyz/utils": "0.3.0"
"@poap-xyz/providers": "0.4.0",
"@poap-xyz/utils": "0.4.0"
}
}
22 changes: 11 additions & 11 deletions packages/moments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ yarn add @poap-xyz/moments @poap-xyz/utils @poap-xyz/providers axio
## Usage

```javascript
import { MomentsClient, CreateMomentInput, Moment } from '@poap-xyz/moments';
import { PoapCompass, PoapMomentsApi, AuthenticationProviderHttp } from '@poap-xyz/providers';
import {MomentsClient, CreateMomentInput, Moment} from '@poap-xyz/moments';
import {PoapCompass, PoapMomentsApi, AuthenticationProviderHttp} from '@poap-xyz/providers';
import fs from 'fs';

// Set up the PoapMomentsApi with proper authentication
Expand All @@ -47,7 +47,7 @@ const client = new MomentsClient(
const input: CreateMomentInput = {
dropId: 110148,
tokenId: 6568008, // Optional: The Token ID related to the moment
medias: [{
media: [{
fileBinary: await fs.promises.readFile('src/assets/poap.png'),
fileType: 'image/png',
}],
Expand All @@ -63,16 +63,16 @@ const input: CreateMomentInput = {
};
const moment: Moment = await client.createMoment(input);
```
Explanations for each step:

| Step Name | Explanation |
|-------------------------|----------------------------------------------------------|
| `UPLOADING_MEDIA` | The process of uploading media assets. |
| `PROCESSING_MEDIA` | The media assets are being processed after upload. |
| `PROCESSING_MEDIA_ERROR`| An error occurred during the media processing phase. |
| `UPLOADING_MOMENT` | The process of uploading the moment's data. |
| `FINISHED` | The entire operation of creating the moment is complete. |
Explanations for each step:

| Step Name | Explanation |
|--------------------------|----------------------------------------------------------|
| `UPLOADING_MEDIA` | The process of uploading media assets. |
| `PROCESSING_MEDIA` | The media assets are being processed after upload. |
| `PROCESSING_MEDIA_ERROR` | An error occurred during the media processing phase. |
| `UPLOADING_MOMENT` | The process of uploading the moment's data. |
| `FINISHED` | The entire operation of creating the moment is complete. |

## Documentation

Expand Down
6 changes: 3 additions & 3 deletions packages/moments/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/moments",
"version": "0.3.0",
"version": "0.4.0",
"description": "Moments module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -26,8 +26,8 @@
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"@poap-xyz/providers": "0.3.0",
"@poap-xyz/utils": "0.3.0",
"@poap-xyz/providers": "0.4.0",
"@poap-xyz/utils": "0.4.0",
"uuid": "^9.0.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/moments/src/client/MomentsClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('MomentsClient', () => {
const inputs: CreateMomentInput = {
dropId: DROP_ID,
tokenId: TOKEN_ID,
medias: MEDIAS_TO_CREATE,
media: MEDIAS_TO_CREATE,
author: AUTHOR,
onStepUpdate,
description: DESCRIPTION,
Expand Down
10 changes: 5 additions & 5 deletions packages/moments/src/client/MomentsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export class MomentsClient {

public async createMoment(input: CreateMomentInput): Promise<Moment> {
let mediaKeys: string[] = [];
if (input.medias && input.medias.length > 0) {
if (input.media && input.media.length > 0) {
mediaKeys = await this.uploadMedias(
input.medias,
input.media,
input.onStepUpdate,
input.onFileUploadProgress,
input.timeOut,
Expand Down Expand Up @@ -71,17 +71,17 @@ export class MomentsClient {
}

private async uploadMedias(
medias: CreateMedia[],
mediaArray: CreateMedia[],
onStepUpdate?: (step: CreateSteps) => void | Promise<void>,
onFileUploadProgress?: (progress: number) => void | Promise<void>,
timeOut?: number,
): Promise<string[]> {
void onStepUpdate?.(CreateSteps.UPLOADING_MEDIA);
const mediaKeys: string[] = [];
const progressPerMedia = 1 / medias.length;
const progressPerMedia = 1 / mediaArray.length;
let progress = 0;

for (const media of medias) {
for (const media of mediaArray) {
const mediaOnFileUploadProgress = (mediaProgress: number): void => {
const totalProgress = progressPerMedia * mediaProgress + progress;
void onFileUploadProgress?.(totalProgress);
Expand Down
4 changes: 2 additions & 2 deletions packages/moments/src/client/dtos/create/CreateInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { CreateMedia } from './CreateMedia';
* @property {string} timeOut - The amount of time to wait until media is processed.
* @property {(step: CreateSteps) => void | Promise<void>} [onStepUpdate] - Optional callback function to be called when the step changes.
* @property {(progress: number) => void | Promise<void>} [onFileProgress] - Optional callback function to be called when the file upload progress change - progress is a number between 0 and 1.
* @property {CreateMedia[]} medias - The media to be uploaded.
* @property {CreateMedia[]} media - The media to be uploaded.
*/
export interface CreateMomentInput {
author: string;
Expand All @@ -21,5 +21,5 @@ export interface CreateMomentInput {
timeOut?: number;
onStepUpdate?: (step: CreateSteps) => void | Promise<void>;
onFileUploadProgress?: (progress: number) => void | Promise<void>;
medias?: CreateMedia[];
media?: CreateMedia[];
}
6 changes: 3 additions & 3 deletions packages/poaps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/poaps",
"version": "0.3.0",
"version": "0.4.0",
"description": "Poaps module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -26,8 +26,8 @@
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"@poap-xyz/providers": "0.3.0",
"@poap-xyz/utils": "0.3.0"
"@poap-xyz/providers": "0.4.0",
"@poap-xyz/utils": "0.4.0"
},
"engines": {
"node": ">=18"
Expand Down
4 changes: 2 additions & 2 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/providers",
"version": "0.3.0",
"version": "0.4.0",
"description": "Providers module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -26,7 +26,7 @@
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"@poap-xyz/utils": "0.3.0",
"@poap-xyz/utils": "0.4.0",
"axios": "^1.6.8",
"lodash.chunk": "^4.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/utils",
"version": "0.3.0",
"version": "0.4.0",
"description": "Utils module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@poap-xyz/drops@workspace:packages/drops"
dependencies:
"@poap-xyz/providers": 0.3.0
"@poap-xyz/utils": 0.3.0
"@poap-xyz/providers": 0.4.0
"@poap-xyz/utils": 0.4.0
languageName: unknown
linkType: soft

Expand All @@ -901,8 +901,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@poap-xyz/moments@workspace:packages/moments"
dependencies:
"@poap-xyz/providers": 0.3.0
"@poap-xyz/utils": 0.3.0
"@poap-xyz/providers": 0.4.0
"@poap-xyz/utils": 0.4.0
"@types/uuid": ^9.0.2
uuid: ^9.0.0
languageName: unknown
Expand All @@ -912,24 +912,24 @@ __metadata:
version: 0.0.0-use.local
resolution: "@poap-xyz/poaps@workspace:packages/poaps"
dependencies:
"@poap-xyz/providers": 0.3.0
"@poap-xyz/utils": 0.3.0
"@poap-xyz/providers": 0.4.0
"@poap-xyz/utils": 0.4.0
languageName: unknown
linkType: soft

"@poap-xyz/providers@*, @poap-xyz/providers@0.3.0, @poap-xyz/providers@workspace:packages/providers":
"@poap-xyz/providers@*, @poap-xyz/providers@0.4.0, @poap-xyz/providers@workspace:packages/providers":
version: 0.0.0-use.local
resolution: "@poap-xyz/providers@workspace:packages/providers"
dependencies:
"@poap-xyz/utils": 0.3.0
"@poap-xyz/utils": 0.4.0
axios: ^1.6.8
axios-mock-adapter: ^1.21.4
jest-fetch-mock: ^3.0.3
lodash.chunk: ^4.2.0
languageName: unknown
linkType: soft

"@poap-xyz/utils@*, @poap-xyz/utils@0.3.0, @poap-xyz/utils@workspace:packages/utils":
"@poap-xyz/utils@*, @poap-xyz/utils@0.4.0, @poap-xyz/utils@workspace:packages/utils":
version: 0.0.0-use.local
resolution: "@poap-xyz/utils@workspace:packages/utils"
languageName: unknown
Expand Down