Skip to content

Commit 84c979a

Browse files
Merge pull request #3 from apivideo/delegated-upload-video-id
Allow delegated upload on existing video
2 parents 9f33b64 + 3e23c0f commit 84c979a

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ The upload library is instanciated using an `options` object. Options to provide
8686
Using delegated upload tokens for authentication is best options when uploading from the client side. To know more about delegated upload token, read the dedicated article on api.video's blog: [Delegated Uploads](https://api.video/blog/tutorials/delegated-uploads).
8787

8888

89-
| Option name | Mandatory | Type | Description |
90-
| ----------------------------: | --------- | ------ | ----------------- |
91-
| uploadToken | **yes** | string | your upload token |
92-
| _common options (see bellow)_ | | | |
89+
| Option name | Mandatory | Type | Description |
90+
| ----------------------------: | --------- | ------ | ----------------------- |
91+
| uploadToken | **yes** | string | your upload token |
92+
| videoId | no | string | id of an existing video |
93+
| _common options (see bellow)_ | | | |
9394

9495
### Using an access token (discouraged):
9596

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/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
interface OptionsWithUploadToken extends Options {
22
uploadToken: string;
3+
videoId?: string;
34
}
45
interface OptionsWithAccessToken extends Options {
56
accessToken: string;

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": "0.0.2",
3+
"version": "0.0.3",
44
"description": "api.video video uploader",
55
"repository": {
66
"type": "git",

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
interface OptionsWithUploadToken extends Options {
22
uploadToken: string;
3+
videoId?: string;
34
}
45
interface OptionsWithAccessToken extends Options {
56
accessToken: string;
@@ -47,6 +48,9 @@ export class VideoUploader {
4748

4849
if (options.hasOwnProperty("uploadToken")) {
4950
const optionsWithUploadToken = options as OptionsWithUploadToken;
51+
if (optionsWithUploadToken.videoId) {
52+
this.videoId = optionsWithUploadToken.videoId;
53+
}
5054
this.uploadEndpoint = `https://${apiHost}/upload?token=${optionsWithUploadToken.uploadToken}`;
5155

5256
} else if (options.hasOwnProperty("accessToken")) {

test/index.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@ describe('Access token auth', () => {
7878
});
7979
});
8080

81+
describe('Delegated upload', () => {
82+
beforeEach(() => mock.setup());
83+
afterEach(() => mock.teardown());
84+
85+
it('videoId is transmitted', (done) => {
86+
const videoId = "9876";
87+
const uploadToken = "1234";
88+
89+
const uploader = new VideoUploader({
90+
file: new File([new ArrayBuffer(2000)], "filename"),
91+
uploadToken,
92+
videoId,
93+
});
94+
95+
mock.post(`https://ws.api.video/upload?token=${uploadToken}`, (req, res) => {
96+
expect(req.body().getAll("videoId")).to.be.eql([videoId]);
97+
return res.status(201).body('{}');
98+
});
99+
100+
uploader.upload().then(() => done());
101+
});
102+
});
103+
81104
describe('Progress listener', () => {
82105
beforeEach(() => mock.setup());
83106
afterEach(() => mock.teardown());

0 commit comments

Comments
 (0)