Skip to content

Commit 7a86f69

Browse files
committed
Initial commit
0 parents  commit 7a86f69

File tree

15 files changed

+6030
-0
lines changed

15 files changed

+6030
-0
lines changed

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Run unit tests
2+
on: [push]
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
node: ['14', '15']
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Setup node ${{ matrix.node }}
12+
uses: actions/setup-node@v1
13+
with:
14+
node-version: ${{ matrix.node }}
15+
- run: npm install --no-save
16+
- run: npm test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tsconfig.json
2+
tslint.json
3+
webpack.config.js
4+
node_modules
5+
test
6+
dist/test

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
All changes to this project will be documented in this file.
3+

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2020 api.video
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
![](https://github.com/apivideo/API_OAS_file/blob/master/apivideo_banner.png)
2+
3+
# api.video video uploader
4+
5+
Typescript library to upload videos to api.video using delegated token
6+
7+
# Usage
8+
9+
## Installation method #1: requirejs
10+
11+
If you use requirejs you can add the library as a dependency to your project with
12+
13+
```sh
14+
$ npm install --save @api.video/video-uploader
15+
```
16+
17+
You can then use the library in your script:
18+
19+
```javascript
20+
var { VideoUploader } = require('@api.video/video-uploader');
21+
22+
var uploader = new VideoUploader("#target", {
23+
file: files[0],
24+
uploadToken: "YOUR_DELEGATED_TOKEN"
25+
// ... other optional options
26+
});
27+
```
28+
29+
## Installation method #2: typescript
30+
31+
If you use Typescript you can add the library as a dependency to your project with
32+
33+
```sh
34+
$ npm install --save @api.video/video-uploader
35+
```
36+
37+
You can then use the library in your script:
38+
39+
```typescript
40+
import { VideoUploader } from '@api.video/video-uploader'
41+
42+
const uploader = new VideoUploader("#target", {
43+
file: files[0],
44+
uploadToken: "YOUR_DELEGATED_TOKEN"
45+
// ... other optional options
46+
});
47+
```
48+
49+
50+
## Simple include in a javascript project
51+
52+
Include the library in your HTML file like so:
53+
54+
```html
55+
<head>
56+
...
57+
<script src="https://unpkg.com/@api.video/video-uploader" defer></script>
58+
</head>
59+
```
60+
61+
Then, once the `window.onload` event has been trigered, create your player using `new VideoUploader()`:
62+
```html
63+
...
64+
<form>
65+
<input type="file" id="input" onchange="uploadFile(this.files)">
66+
</form>
67+
<script type="text/javascript">
68+
function uploadFile(files) {
69+
new VideoUploader({
70+
file: files[0],
71+
uploadToken: "YOUR_DELEGATED_TOKEN"
72+
}).upload();
73+
}
74+
</script>
75+
```

dist/index.js

Lines changed: 1 addition & 0 deletions
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
interface Options {
2+
file: File;
3+
uploadToken: string;
4+
chunkSize?: number;
5+
uploadEndpoint?: string;
6+
}
7+
interface UploadProgressEvent {
8+
loaded: number;
9+
total: number;
10+
}
11+
export declare class VideoUploader {
12+
private file;
13+
private chunkSize;
14+
private uploadEndpoint;
15+
private uploadToken;
16+
private currentChunk;
17+
private chunksCount;
18+
private fileSize;
19+
private fileName;
20+
private videoId?;
21+
private onProgressCallbacks;
22+
constructor(options: Options);
23+
onProgress(cb: () => UploadProgressEvent): void;
24+
upload(): Promise<any>;
25+
private validateOptions;
26+
private createFormData;
27+
private uploadCurrentChunk;
28+
}
29+
export {};

0 commit comments

Comments
 (0)