Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var config = {};

config.port = 3000;
config.UNSCREEN_API_VIDEOS_URL = "https://api.unscreen.com/v1.0/videos";

module.exports = config;
36 changes: 30 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const bodyParser = require('body-parser');
const FormData = require('form-data');
const axios = require('axios');
const app = express();
const port = 3000;
var config = require('./config');
//const port = 3000;

const UNSCREEN_API_VIDEOS_URL = "https://api.unscreen.com/v1.0/videos";
//const UNSCREEN_API_VIDEOS_URL = "https://api.unscreen.com/v1.0/videos";

app.use(express.static('public'));
app.use(bodyParser.json());
Expand Down Expand Up @@ -38,7 +39,7 @@ app.post('/upload', (req, res) => {

axios({
method: 'post',
url: UNSCREEN_API_VIDEOS_URL,
url: config.UNSCREEN_API_VIDEOS_URL,
data: formData,
headers: headers,
'maxContentLength': Infinity,
Expand Down Expand Up @@ -92,7 +93,7 @@ function poll(url, res) {
app.get('/videos', (req, res) => {
axios({
method: 'get',
url: UNSCREEN_API_VIDEOS_URL,
url: config.UNSCREEN_API_VIDEOS_URL,
headers: { 'X-Api-Key': process.env.API_KEY },
})
.then(function (response) {
Expand All @@ -106,6 +107,29 @@ app.get('/videos', (req, res) => {
});
});

// remove a video
app.get('/delete/:id', (req, res) => {
if (req.params.id == null)
res.send(400, {status:400, message: 'invalid parameter id specified'})

axios({
method: 'delete',
url: config.UNSCREEN_API_VIDEOS_URL,
data: { id: req.params.id},
headers: { 'X-Api-Key': process.env.API_KEY },
})
.then(function (response) {
// handle success
console.log(response.data);
res.json(response.data);
})
.catch(function (error) {
// handle error
console.log(error);
});

});

app.post('/webhook', (req, res) => {
console.log('webhook');
console.log(req.body);
Expand All @@ -115,7 +139,7 @@ app.post('/webhook', (req, res) => {
}
})

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
app.listen(config.port, () => {
console.log(`Example app listening at http://localhost:${config.port}`)
})

6 changes: 6 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<br/>
<input type="submit">
</form>
<form action="/delete" method="POST" encType="multipart/form-data">
Select video id:
<input name="id" type="text">
<br/>
<input type="submit">
</form>
<br/>
<a href="/videos">Show my unscreen videos</a>
</body>
Expand Down
Binary file added samples/1.mp4
Binary file not shown.
Binary file added samples/2.mp4
Binary file not shown.
Binary file added samples/3.mp4
Binary file not shown.
3 changes: 3 additions & 0 deletions test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CQBJs7XcnJvYjSVkiywaw9H6

curl -X POST "https://api.unscreen.com/v1.0/videos" -H "X-Api-Key: CQBJs7XcnJvYjSVkiywaw9H6" -F "video_file=@samples/1.mp4"