Skip to content

Commit

Permalink
fix: createDirectUpload collectionId (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-online authored Oct 17, 2023
1 parent 72a39ae commit 259d596
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ tests/test.1080.mp4
tests/test.jpg

coverage/
.env
Empty file modified .husky/commit-msg
100644 → 100755
Empty file.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 5 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>
) {
const all: BunnyCdnStreamVideo[] = [];
let nextPage = true;
Expand Down Expand Up @@ -569,7 +569,7 @@ export class BunnyCdnStream {
* await stream.createDirectUpload({ title: "My Video" })
* ```
*/
public async createDirectUpload(data: { title: string; collection?: string }, expirationDate?: Date): Promise<BunnyCdnStream.CreateDirectUpload> {
public async createDirectUpload(data: { title: string; collectionId?: string }, expirationDate?: Date): Promise<BunnyCdnStream.CreateDirectUpload> {
// create a video
const expirationTimestamp = (expirationDate || new Date(Date.now() + 60000)).getTime();
const video = await this.createVideo(data);
Expand All @@ -587,7 +587,7 @@ export class BunnyCdnStream {
metadata: {
filetype: '',
title: data.title,
collection: data.collection
collection: data.collectionId
}
};
}
Expand Down Expand Up @@ -623,7 +623,7 @@ export class BunnyCdnStream {
}
}

private getOptions() {
private getOptions(): AxiosRequestConfig & { headers: AxiosHeaders } {
return {
...this.axiosOptions,
headers: new AxiosHeaders(this.axiosOptions.headers)
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 13 additions & 3 deletions tests/Bunny.test.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 () => {
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 259d596

Please sign in to comment.