Skip to content

Commit 7a8363b

Browse files
Merge pull request #16 from apivideo/add-api-token-auth-method
Add api token auth method
2 parents b9c48da + 1f849e7 commit 7a8363b

13 files changed

+130
-67
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
All changes to this project will be documented in this file.
33

4+
## [1.0.5] - 2022-03-24
5+
- Fix date attributes types
6+
- Add authentication using an API key
7+
48
## [1.0.4] - 2022-03-23
59
- Export `VideoUploadResponse` type
610

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- [Options](#options)
2222
- [Using a delegated upload token (recommended):](#using-a-delegated-upload-token-recommended)
2323
- [Using an access token (discouraged):](#using-an-access-token-discouraged)
24+
- [Using an API key (**strongly** discouraged):](#using-an-api-key-strongly-discouraged)
2425
- [Common options](#common-options)
2526
- [Example](#example)
2627
- [Methods](#methods)
@@ -161,6 +162,18 @@ Using delegated upload tokens for authentication is best options when uploading
161162
| _common options (see bellow)_ | | | |
162163

163164

165+
#### Using an API key (**strongly** discouraged):
166+
167+
**Warning**: be aware that exposing your API key client-side can lead to huge security issues. Use this method only if you know what you're doing :).
168+
169+
170+
| Option name | Mandatory | Type | Description |
171+
| ----------------------------: | --------- | ------ | ----------------------- |
172+
| API Key | **yes** | string | your api.video API key |
173+
| videoId | **yes** | string | id of an existing video |
174+
| _common options (see bellow)_ | | | |
175+
176+
164177
#### Common options
165178

166179

@@ -262,10 +275,10 @@ Using delegated upload tokens for authentication is best options when uploading
262275
#### Common options
263276

264277

265-
| Option name | Mandatory | Type | Description |
266-
| ----------: | --------- | ------ | -------------------------------------------------------------------------- |
267-
| apiHost | no | string | api.video host (default: ws.api.video) |
268-
| retries | no | number | number of retries when an API call fails (default: 5) |
278+
| Option name | Mandatory | Type | Description |
279+
| ----------: | --------- | ------ | ----------------------------------------------------- |
280+
| apiHost | no | string | api.video host (default: ws.api.video) |
281+
| retries | no | number | number of retries when an API call fails (default: 5) |
269282

270283

271284
### Example

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: string;
14-
readonly createdAt: string;
15-
readonly uploadedAt: string;
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;

dist/src/progressive-video-uploader.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export interface ProgressiveUploaderOptionsWithAccessToken extends Options {
77
accessToken: string;
88
videoId: string;
99
}
10+
export interface ProgressiveUploaderOptionsWithApiKey extends Options {
11+
apiKey: string;
12+
videoId: string;
13+
}
1014
interface Options {
1115
apiHost?: string;
1216
retries?: number;
@@ -29,7 +33,7 @@ export declare class ProgressiveUploader {
2933
private currentPartBlobs;
3034
private currentPartBlobsSize;
3135
private queue;
32-
constructor(options: ProgressiveUploaderOptionsWithAccessToken | ProgressiveUploaderOptionsWithUploadToken);
36+
constructor(options: ProgressiveUploaderOptionsWithAccessToken | ProgressiveUploaderOptionsWithUploadToken | ProgressiveUploaderOptionsWithApiKey);
3337
onProgress(cb: (e: ProgressiveProgressEvent) => void): void;
3438
uploadPart(file: Blob): Promise<void>;
3539
uploadLastPart(file: Blob): Promise<VideoUploadResponse>;

dist/src/video-uploader.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export interface VideoUploaderOptionsWithAccessToken extends Options {
77
accessToken: string;
88
videoId: string;
99
}
10+
export interface VideoUploaderOptionsWithApiKey extends Options {
11+
apiKey: string;
12+
videoId: string;
13+
}
1014
interface Options {
1115
file: File;
1216
chunkSize?: number;
@@ -34,7 +38,7 @@ export declare class VideoUploader {
3438
private onProgressCallbacks;
3539
private headers;
3640
private queue;
37-
constructor(options: VideoUploaderOptionsWithAccessToken | VideoUploaderOptionsWithUploadToken);
41+
constructor(options: VideoUploaderOptionsWithAccessToken | VideoUploaderOptionsWithUploadToken | VideoUploaderOptionsWithApiKey);
3842
onProgress(cb: (e: UploadProgressEvent) => void): void;
3943
upload(): Promise<VideoUploadResponse>;
4044
private sleep;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@api.video/video-uploader",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "api.video video uploader",
55
"repository": {
66
"type": "git",

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: string;
15-
readonly createdAt: string;
16-
readonly uploadedAt: string;
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';

0 commit comments

Comments
 (0)