diff --git a/.gitignore b/.gitignore index c135f3d6..500ee09a 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ tests/test.1080.mp4 tests/test.jpg coverage/ +.env diff --git a/.husky/commit-msg b/.husky/commit-msg old mode 100644 new mode 100755 diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/package.json b/package.json index b7c00c85..ef141587 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@typescript-eslint/eslint-plugin": "^6.3.0", "@typescript-eslint/parser": "^6.3.0", "@vitest/coverage-c8": "^0.31.4", + "dotenv": "^16.3.1", "eslint": "^8.42.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^4.2.1", diff --git a/src/index.ts b/src/index.ts index e3513786..689b42e5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -280,7 +280,7 @@ export class BunnyCdnStream { orderBy?: string; itemsPerPage?: number; } = {}, - stop?: (videos: BunnyCdnStreamVideo[], page: number, totalPages: number) => boolean + stop?: (videos: BunnyCdnStreamVideo[], page: number, totalPages: number) => boolean | Promise ) { const all: BunnyCdnStreamVideo[] = []; let nextPage = true; @@ -569,7 +569,7 @@ export class BunnyCdnStream { * await stream.createDirectUpload({ title: "My Video" }) * ``` */ - public async createDirectUpload(data: { title: string; collection?: string }, expirationDate?: Date): Promise { + public async createDirectUpload(data: { title: string; collectionId?: string }, expirationDate?: Date): Promise { // create a video const expirationTimestamp = (expirationDate || new Date(Date.now() + 60000)).getTime(); const video = await this.createVideo(data); @@ -587,7 +587,7 @@ export class BunnyCdnStream { metadata: { filetype: '', title: data.title, - collection: data.collection + collection: data.collectionId } }; } @@ -623,7 +623,7 @@ export class BunnyCdnStream { } } - private getOptions() { + private getOptions(): AxiosRequestConfig & { headers: AxiosHeaders } { return { ...this.axiosOptions, headers: new AxiosHeaders(this.axiosOptions.headers) @@ -727,9 +727,7 @@ export namespace BunnyCdnStream { engagementScore: number; } - export interface VideoHeatmapResponse { - // TODO: incorrect on bunny's docs, to be discovered - } + export interface VideoHeatmapResponse {} export interface ListVideosResponse { totalItems: number; diff --git a/tests/Bunny.test.ts b/tests/Bunny.test.ts index b9b0fa7c..a6255411 100644 --- a/tests/Bunny.test.ts +++ b/tests/Bunny.test.ts @@ -1,7 +1,10 @@ +import { config } from 'dotenv'; import { createReadStream, readFileSync } from 'fs'; import { resolve } from 'path'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; import { BunnyCdnStream, BunnyCdnStreamVideo } from '../src'; + +config(); describe('BunnyCdnStream', () => { let stream: BunnyCdnStream; @@ -87,10 +90,17 @@ describe('BunnyCdnStream', () => { width: 0 }); - const videos = await stream.listVideos(); - expect(videos.items).toHaveLength(1); + await new Promise((r) => { + const interval = setInterval(async () => { + const videos = await stream.listVideos(); + if (videos.items.length > 0) { + clearInterval(interval); + r(0); + } + }, 1000); + }); }, - { timeout: 60000 } + { timeout: 30000 } ); test('GIVEN library w/ video THEN can get video', async () => { diff --git a/yarn.lock b/yarn.lock index f02b840b..60deee80 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3084,6 +3084,7 @@ __metadata: "@typescript-eslint/parser": ^6.3.0 "@vitest/coverage-c8": ^0.31.4 axios: ^1.4.0 + dotenv: ^16.3.1 eslint: ^8.42.0 eslint-config-prettier: ^9.0.0 eslint-plugin-prettier: ^4.2.1 @@ -4012,6 +4013,13 @@ __metadata: languageName: node linkType: hard +"dotenv@npm:^16.3.1": + version: 16.3.1 + resolution: "dotenv@npm:16.3.1" + checksum: 15d75e7279018f4bafd0ee9706593dd14455ddb71b3bcba9c52574460b7ccaf67d5cf8b2c08a5af1a9da6db36c956a04a1192b101ee102a3e0cf8817bbcf3dfd + languageName: node + linkType: hard + "eastasianwidth@npm:^0.2.0": version: 0.2.0 resolution: "eastasianwidth@npm:0.2.0"