Skip to content

Commit 1f849e7

Browse files
committed
Make VideoUploadResponse consistent with nodejs client Video
1 parent e570c61 commit 1f849e7

File tree

7 files changed

+69
-53
lines changed

7 files changed

+69
-53
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/common.d.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,28 @@ export declare const DEFAULT_RETRIES = 5;
55
export declare const DEFAULT_API_HOST = "ws.api.video";
66
export declare type VideoUploadResponse = {
77
readonly videoId: string;
8-
readonly title: string;
9-
readonly description: string;
10-
readonly public: boolean;
11-
readonly panoramic: boolean;
12-
readonly mp4Support: boolean;
13-
readonly publishedAt: Date;
14-
readonly createdAt: Date;
15-
readonly uploadedAt: Date;
16-
readonly tags: readonly string[];
17-
readonly metadata: readonly {
18-
readonly key: string;
19-
readonly value: string;
8+
readonly title?: string;
9+
readonly description?: string;
10+
readonly _public?: boolean;
11+
readonly panoramic?: boolean;
12+
readonly mp4Support?: boolean;
13+
readonly publishedAt?: Date;
14+
readonly createdAt?: Date;
15+
readonly updatedAt?: Date;
16+
readonly tags?: string[];
17+
readonly metadata?: {
18+
readonly key?: string;
19+
readonly value?: string;
2020
}[];
21-
readonly source: {
22-
readonly type: string;
23-
readonly uri: string;
21+
readonly source?: {
22+
readonly type?: string;
23+
readonly uri?: string;
2424
};
25-
readonly assets: {
26-
readonly iframe: string;
27-
readonly player: string;
28-
readonly hls: string;
29-
readonly thumbnail: string;
25+
readonly assets?: {
26+
readonly iframe?: string;
27+
readonly player?: string;
28+
readonly hls?: string;
29+
readonly thumbnail?: string;
3030
};
3131
};
32+
export declare const apiResponseToVideoUploadResponse: (response: any) => VideoUploadResponse;

src/common.ts

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,41 @@ export const MAX_CHUNK_SIZE = 1024 * 1024 * 128; // 128mb
44
export const DEFAULT_RETRIES = 5;
55
export const DEFAULT_API_HOST = "ws.api.video";
66

7-
export type VideoUploadResponse = {
8-
readonly videoId: string;
9-
readonly title: string;
10-
readonly description: string;
11-
readonly public: boolean;
12-
readonly panoramic: boolean;
13-
readonly mp4Support: boolean;
14-
readonly publishedAt: Date;
15-
readonly createdAt: Date;
16-
readonly uploadedAt: Date;
17-
readonly tags: readonly string[];
18-
readonly metadata: readonly {
19-
readonly key: string;
20-
readonly value: string;
21-
}[];
22-
readonly source: {
23-
readonly type: string;
24-
readonly uri: string;
25-
};
26-
readonly assets: {
27-
readonly iframe: string;
28-
readonly player: string;
29-
readonly hls: string;
30-
readonly thumbnail: string;
31-
};
32-
};
7+
export declare type VideoUploadResponse = {
8+
readonly videoId: string;
9+
readonly title?: string;
10+
readonly description?: string;
11+
readonly _public?: boolean;
12+
readonly panoramic?: boolean;
13+
readonly mp4Support?: boolean;
14+
readonly publishedAt?: Date;
15+
readonly createdAt?: Date;
16+
readonly updatedAt?: Date;
17+
readonly tags?: string[];
18+
readonly metadata?: {
19+
readonly key?: string;
20+
readonly value?: string;
21+
}[];
22+
readonly source?: {
23+
readonly type?: string;
24+
readonly uri?: string;
25+
};
26+
readonly assets?: {
27+
readonly iframe?: string;
28+
readonly player?: string;
29+
readonly hls?: string;
30+
readonly thumbnail?: string;
31+
};
32+
};
33+
34+
export const apiResponseToVideoUploadResponse = (response: any): VideoUploadResponse => {
35+
const res = {
36+
...response,
37+
_public: response.public,
38+
publishedAt: response.publishedAt ? new Date(response.publishedAt) : undefined,
39+
createdAt: response.createdAt ? new Date(response.createdAt) : undefined,
40+
updatedAt: response.updatedAt ? new Date(response.updatedAt) : undefined,
41+
};
42+
delete res.public;
43+
return res;
44+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { VideoUploader } from "./video-uploader";
2+
13
export { UploadProgressEvent, VideoUploader, VideoUploaderOptionsWithAccessToken, VideoUploaderOptionsWithUploadToken } from "./video-uploader";
24
export { ProgressiveUploadProgressEvent, ProgressiveUploader, ProgressiveUploaderOptionsWithAccessToken, ProgressiveUploaderOptionsWithUploadToken } from './progressive-video-uploader';
35
export { VideoUploadResponse, MIN_CHUNK_SIZE, MAX_CHUNK_SIZE } from './common';

src/progressive-video-uploader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DEFAULT_API_HOST, DEFAULT_RETRIES, MIN_CHUNK_SIZE, VideoUploadResponse } from "./common";
1+
import { apiResponseToVideoUploadResponse, DEFAULT_API_HOST, DEFAULT_RETRIES, MIN_CHUNK_SIZE, VideoUploadResponse } from "./common";
22
import { PromiseQueue } from "./promise-queue";
33

44
export interface ProgressiveUploaderOptionsWithUploadToken extends Options {
@@ -136,7 +136,7 @@ export class ProgressiveUploader {
136136
}
137137
}
138138
};
139-
xhr.onload = (_) => resolve(JSON.parse(xhr.response));
139+
xhr.onload = (_) => resolve(apiResponseToVideoUploadResponse(xhr.response))
140140
xhr.upload.onprogress = (e) => this.onProgressCallbacks.forEach(cb => cb({
141141
uploadedBytes: e.loaded,
142142
totalBytes: fileSize,

src/video-uploader.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DEFAULT_API_HOST, DEFAULT_CHUNK_SIZE, DEFAULT_RETRIES, MAX_CHUNK_SIZE, MIN_CHUNK_SIZE, VideoUploadResponse } from "./common";
1+
import { apiResponseToVideoUploadResponse, DEFAULT_API_HOST, DEFAULT_CHUNK_SIZE, DEFAULT_RETRIES, MAX_CHUNK_SIZE, MIN_CHUNK_SIZE, VideoUploadResponse } from "./common";
22
import { PromiseQueue } from "./promise-queue";
33

44
export interface VideoUploaderOptionsWithUploadToken extends Options {
@@ -111,7 +111,8 @@ export class VideoUploader {
111111
retriesCount++;
112112
}
113113
}
114-
resolve(response as VideoUploadResponse);
114+
115+
resolve(apiResponseToVideoUploadResponse(response));
115116
}));
116117
}
117118

@@ -131,7 +132,7 @@ export class VideoUploader {
131132
return chunkForm;
132133
}
133134

134-
private uploadCurrentChunk(): Promise<VideoUploadResponse> {
135+
private uploadCurrentChunk(): Promise<any> {
135136
return new Promise((resolve, reject) => {
136137
const firstByte = this.currentChunk * this.chunkSize;
137138
const computedLastByte = (this.currentChunk + 1) * this.chunkSize;

test/progressive-video-uploader.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('Instanciation', () => {
77
it('throws if required param is missing', () => {
88
// @ts-ignore
99
expect(() => new ProgressiveUploader({
10-
})).to.throw("You must provide either an accessToken or an uploadToken");
10+
})).to.throw("You must provide either an accessToken, an uploadToken or an API key");
1111

1212
// @ts-ignore
1313
expect(() => new ProgressiveUploader({

0 commit comments

Comments
 (0)