Skip to content

Commit 347ef3c

Browse files
committed
Add App
* First Commit * Add clone of existing (private) repo that performs similar functionality.
0 parents  commit 347ef3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1890
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.example.env

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
NODE_CONFIG_DIR=./config/env
2+
APP_SECRET=abcdefghijklmnopqrstuvwxyz1234567890
3+
POSTGRES_DATABASE=app_name_database
4+
POSTGRES_USERNAME=app_name_database_user
5+
POSTGRES_PASSWORD=password123
6+
POSTGRES_HOST=localhost
7+
POSTGRES_PORT=1234
8+
AWS_ACCESS_KEY_ID=123ABC
9+
AWS_SECRET_ACCESS_KEY=123ABC
10+
AWS_STORY_CREATION_USER_ACCESS_KEY_ID=123ABC
11+
AWS_STORY_CREATION_USER_SECRET_ACCESS_KEY=123ABC
12+
S3_INPUT_BUCKET=input-bucket
13+
S3_OUTPUT_BUCKET=output-bucket

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
10+
pids
11+
logs
12+
results
13+
14+
bundle.js
15+
npm-debug.log
16+
node_modules
17+
18+
npm-debug.log.*
19+
20+
.env
21+
22+
tmp/*

.ruby-version

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

.sequelizerc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var path = require("path")
2+
3+
module.exports = {
4+
"config" : path.resolve("config", "database.js"),
5+
"migrations-path" : path.resolve("db", "migrate"),
6+
"models-path" : path.resolve("api", "models")
7+
}

20140521165539_reset.txt

Whitespace-only changes.

Procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web: node app.js
2+
webDebug: node-debug app.js

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Node/AWS Elastic Transcoding App
2+
3+
This repository contains a working node application that provides an API for creating user-associated video transcodes using several components of the AWS ecosystem.
4+
5+
The application itself does not handle the actual uploading of files to AWS, as this application is intended to work in tandem with another application that would do that part of the process, such as a mobile application. However, this application does handle the administrative work around this kind of task, such as providing temporary AWS access tokens to its client application, communication with the AWS pipeline via SNS (to listen for transcoder events such as completion), and persisting transcoded video file information for a user. The application also contains the AWS Lambda files one would need to add to their AWS account in order to perform the work on Amazon's end, with documentation.
6+
7+
This repository also includes an example `.html` file where you can play with the API and AWS to test the application itself.
8+
9+
This repository makes heavy use of its Wiki for documentation, so please look there for further documentation.
10+
11+
## The Application
12+
13+
The basic concept for this application is that the application has users and that those users want to upload video files from the client application (web, mobile, or both) to be associated with their accounts. We call these video files "Stories". For each upload, the last video file the user uploaded without error will become their "Primary Story".
14+
15+
This application provides an API that works along a client application as a service and persistence layer for storing user and transcoded video information. This application oversees the lifecycle of video uploads as they move from the client application, through AWS, and back to the persistence layer provided herein.
16+
17+
18+
19+

api/controllers/api/v1/sessions.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Actions ======================================================================
2+
function login(req, res, next) {
3+
var models = req.app.get("models"),
4+
username = req.body.username,
5+
password = req.body.password;
6+
7+
models.User.findOne({ where : { $or : [{ username : username }, { email : username }] } }).then(function(user) {
8+
if (!user || !user.validPassword(password)) {
9+
return res.send(422, { status: 422, message : "Incorrect username or password." });
10+
}
11+
12+
req.app.render("user", { data : user }, function(err, userJson) {
13+
if (err) {
14+
throw(err);
15+
}
16+
17+
userJson.authToken = user.generateJWTToken();
18+
19+
return res.send(200, {
20+
user : userJson
21+
});
22+
});
23+
}).catch(function(err) {
24+
console.log(err);
25+
next(err);
26+
});
27+
}
28+
29+
function destroy(req, res) {
30+
req.logout();
31+
32+
return res.send(200, { message : "Token destroyed." });
33+
}
34+
35+
36+
// Exports ======================================================================
37+
module.exports = function(app) {
38+
app.post("/api/v1/login", login);
39+
app.get("/api/v1/logout", destroy);
40+
}

api/controllers/api/v1/stories.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
var path = require("path"),
2+
StoriesSearchService = require(path.resolve("api/services/api/v1/stories_search_service"));
3+
4+
5+
// Actions ======================================================================
6+
function index(req, res, next) {
7+
var models = req.app.get("models");
8+
9+
// TODO: Improve and servicify.
10+
var userId = isNaN(req.query.userId) ? null : req.query.userId;
11+
var username = req.query.username && String(req.query.username);
12+
13+
models.User.findOne({ where : { $or : [{ id : userId }, { username : username }]}}).then(function(user) {
14+
if (!user) {
15+
return res.send(404, { status : 404, message : "No user found for the received parameters." });
16+
}
17+
18+
// TODO/Dev Note: This service stuff is temporary and sloppy with this userId manipulation. Fix this but do it at the right time.
19+
req.query.userId = user.id;
20+
21+
var searchService = new StoriesSearchService(req);
22+
23+
searchService.search().then(function (responseBody) {
24+
return res.send(200, responseBody);
25+
}).catch(function(err) {
26+
throw(err);
27+
});
28+
}).catch(function(err) {
29+
console.log(err);
30+
next(err);
31+
});
32+
}
33+
34+
function primaryStory(req, res, next) {
35+
var models = req.app.get("models");
36+
37+
// TODO: Improve and servicify.
38+
var userId = isNaN(req.query.userId) ? null : req.query.userId;
39+
var username = req.query.username && String(req.query.username);
40+
41+
models.User.findOne({ where : { $or : [{ id : userId }, { username : username }]}}).then(function(user) {
42+
if (!user) {
43+
return res.send(404, { status : 404, message : "No user found for the received parameters." });
44+
}
45+
46+
user.primaryStory().then(function (primaryStory) {
47+
if (primaryStory) {
48+
req.app.render("story", { data : primaryStory }, function(err, storyJson) {
49+
if (err) {
50+
throw(err);
51+
}
52+
53+
return res.send(200, {
54+
story : storyJson
55+
});
56+
});
57+
} else {
58+
return res.send(200, {
59+
story : null
60+
});
61+
}
62+
}).catch(function(err) {
63+
throw(err);
64+
});
65+
66+
67+
}).catch(function(err) {
68+
console.log(err);
69+
next(err);
70+
});
71+
}
72+
73+
74+
// Exports ======================================================================
75+
module.exports = function(app, passport) {
76+
app.get("/api/v1/stories", index)
77+
app.get("/api/v1/stories/primary_story", primaryStory);
78+
}

0 commit comments

Comments
 (0)