SlideShare a Scribd company logo
1 of 24
Appendix-I (Program Code)
File.js // Collecting data from the users
(sender)
import _ from 'lodash'
class File {
constructor(app) {
this.app = app;
this.model = {
name: null, originalName: null, mimeType: null, size: null,
etag: null,
created: new Date(),
} }
initWithObject(object){
this.model.name = _.get(object, 'key');
this.model.originalName = _.get(object, 'originalname');
this.model.mimeType = _.get(object, 'mimetype');
this.model.size = _.get(object, 'size');
this.model.etag= _.get(object, 'etag');
this.model.created = new Date();
return this;
} toJSON(){
return this.model;
} save(callback) {
const db = this.app.get('db');
db.collection('files').insertOne(this.model, (err, result) => {
return callback(err, result);
});}
}
export default File;
--------------------------------------------------------------------------------------------------------------------
Archiver.js // Download all the files as a zip file
import archiver from 'archiver'
import _ from 'lodash'
import path from 'path'
import S3 from './s3'
export default class FileArchiver{
constructor(app, files = [], response){
this.app = app; this.files = files; this.response = response; }
download(){
const app = this.app;
const files = this.files;
//const uploadDir = app.get('storageDir');
const zip = archiver('zip'); const response = this.response;
response.attachment('download.zip');
zip.pipe(response); const s3Downloader = new S3(app, response);
_.each(files, (file) => {
const fileObject = s3Downloader.getObject(file);
zip.append(fileObject, {name: _.get(file, 'originalName')});
});
zip.finalize();
return this;
}}
--------------------------------------------------------------------------------------------------------------------
Config.js // Sending Notification Alert through Email
import {accessKeyId,secretAccessKey} from './s3-config.json'
export const smtp = {
host: 'smtp.sendgrid.net',
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: 'apikey', // generated ethereal user
pass: 'SG.HXUZZppORTSHzQuQwC-5EA.OgpSmEJnvXwo2qBGX-
ujkk7OqB1hSw2Kwlxal9abLUI' // generated ethereal password
}}
export const url = 'http://localhost:3001';
export const s3Config = {
accessKeyId: 'AKIAI7PBFWK7ZNHYIGQA',
secretAccessKey: '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'}
export const S3Region = 'us-east-1' export const s3Bucket = 'fileapp0'
--------------------------------------------------------------------------------------------------------------------
Database.js // Connecting the database through Mongodb
import {MongoClient} from 'mongodb';
const url ='mongodb://localhost:27017/fileapp';
export const connect=(callback)=>{
MongoClient.connect(url, (err, db) => {
return callback(err, db);
}); };
--------------------------------------------------------------------------------------------------------------------
Index.js // Monitor for the file present in package.JSON
import http from 'http';
import express from 'express';
import {connect} from "./database";
import AppRouter from './router'
import multer from 'multer'
import path from 'path';
import nodemailer from 'nodemailer';
import {smtp, s3Config, S3Region, s3Bucket} from './config'
// Amazon S3 Setup
import AWS from 'aws-sdk'
import multerS3 from 'multer-s3'
AWS.config.update(s3Config);
AWS.config.region = S3Region ;
const s3 = new AWS.S3();
// setup Email
let email = nodemailer.createTransport(smtp);
//File Storage Config
const storageDir = path.join(__dirname,'..', 'storage');
// const upload = multer({ storage: storageConfig })
const upload = multer({
storage: multerS3({
s3: s3,
bucket: s3Bucket,
metadata: function (req, file, cb) {
cb(null, {fieldName: file.fieldname}); },
key: function (req, file, cb) {
const filename = `${Date.now().toString()}-${file.originalname}`;
cb(null, filename)
} }) })
//End File Storage Config
const PORT = 3000;
const app = express();
app.server = http.createServer(app);
app.use(morgan('dev'));
app.use(cors({
exposedHeaders: "*"}));
app.set('root', __dirname);
app.set('storageDir',storageDir);
app.upload = upload;
app.email = email;
app.s3 = s3;
//Connect to database
connect((err,db)=> {
if (err) {
console.log("An error connecting to the database");
throw(err); }
app.set('db',db);
//init router
new AppRouter(app);
app.server.listen(process.env.PORT || PORT, () => {
console.log(`App is running on port ${app.server.address().port}`); });
});
export default app;
--------------------------------------------------------------------------------------------------------------------
Router.js // JS library that provide an API for handling routes
import {version} from '../package.json'
import path from 'path'
import _ from 'lodash'
import {ObjectID} from 'mongodb'
import File from './models/file'
import Post from './models/post'
import FileArchiver from './archiver'
import Email from './email'
import S3 from './s3'
class AppRouter {
constructor(app) {
this.app = app;
this.setupRouters();
}
setupRouters() {
const app = this.app;
const uploadDir = app.get('storageDir');
const upload = app.upload;
const db = app.get('db');
//root routing
app.get('/', (req, res, next) => {
return res.status(200).json({
version: version
}); });
//Upload Routing
app.post('/api/upload', upload.array('files'), (req, res, next) => {
const files = _.get(req, 'files', []);
console.log("files objects from s3 multer", files);
let fileModels = [];
_.each(files, (fileObject) => {
const newFile = new File(app).initWithObject(fileObject).toJSON();
fileModels.push(newFile);
});
if (fileModels.length) { //check for empty file
db.collection('files').insertMany(fileModels, (err, result) => {
if (err) {
return res.status(503).json({
error: {
message: "Unable to save your file",
} }); }
let post = new Post(app).initWithObject({
from: _.get(req,'body.from'),
to: _.get(req,'body.to'),
message: _.get(req,'body.message'),
phone: _.get(req,'body.phone'),
files: result.insertedIds,
}).toJSON();
//let save post objects to posts collection.
db.collection('posts').insertOne(post,(err,result)=>{
if(err){
return res.status(503).json({error:{message:"Your upload could not be saved"}});
}
//implement email sending to user with download link.
//send email
const sendEmail = new Email(app).sendDownloadLink(post, (err, info) => {
});
// callback to react app with post detail.
return res.json(post);
}); });
} else {
return res.status(503).json({
error: {message: "files upload is required"}
}); } });
// Download file from S3 service
const file = _.get(result, '[0]');
const downloader = new S3(app, res);
// return downloader.download(file); Proxy download from s3 service
// Download Directly from S3
const downloadUrl = downloader.getDownloadUrl(file);
return res.redirect(downloadUrl); }); });
//routing for post detail/api/posts/:id
app.get('/api/posts/:id',(req,res,next)=>{
const postId=_.get(req,'params.id');
this.getPostById(postId, (err, result) => {
if(err){
return res.status(404).json({error:{message: 'File not found.'}});
}
return res.json(result); }) });
// Routing download zip files.
app.get('/api/posts/:id/download', (req, res, next) => {
const id = _.get(req, 'params.id', null);
this.getPostById(id, (err, result) => {
if (err) {
return res.status(404).json({error: {message: 'File not found.'}});
}
const files = _.get(result, 'files', []);
const archiver = new FileArchiver(app, files, res).download();
return archiver; }) }); }
getPostById(id, callback = () => {}){
const app= this.app;
const db = app.get('db');
let postObjectId=null;
try{
postObjectId=new ObjectID(id);
}
catch (err){
return callback(err, null);
}
db.collection('posts').find({_id:postObjectId}).limit(1).toArray((err,results)=>{
let result =_.get(results,'[0]');
if(err || !result){
return callback(err ? err: new Error("File not found"));
}
const fileIds=_.get(result,'files',[]);
db.collection('files').find({_id:{$in: fileIds}}).toArray((err,files)=>{
if(err || !files || !files.length){
return callback(err ? err: new Error("File not found"));
}
result.files=files;
return callback(null, result);
}); }) }} export default AppRouter;
----------------------------------------------------------------------------------------------------------------------
S3.js // Connecting the S3 with Dpliot for Cloud Application
import _ from 'lodash'
import {s3Bucket} from './config'
export default class S3{
constructor(app, response){
this.app = app;
this.response = response;
}
getObject(file){
const s3 = this.app.s3; const options ={
Bucket: s3Bucket,
Key: _.get(file, 'name')
};
return s3.getObject(options).createReadStream(); }
download(file){
const s3 = this.app.s3;
const response = this.response;
// get Object from S3 service
const filename = _.get(file, 'originalName');
response.attachment(filename);
const options ={
Bucket: s3Bucket,
Key: _.get(file, 'name')
};
const fileObject = s3.getObject(options).createReadStream();
fileObject.pipe(response); }
getDownloadUrl(file){
const s3 = this.app.s3;
const options ={
Bucket: s3Bucket,
Key: _.get(file, 'name'),
Expires: 3600, // one hour expires. };
const url = s3.getSignedUrl('getObject', options);
return url; }}
--------------------------------------------------------------------------------------------------------------------
Header.js // Designing Dashboard through React
import React,{Component} from 'react'
class Header extends Component {
render() {
return (
<div className={'app-header'}>
<div className={'app-site-info'}>
<h1><i className={'icon-paper-plane'} /> Dpilot</h1>
<div className={'site-title'}>SHARE YOUR FILE.</div>
<div className={'site-slogan'}>SECURE ! SAFE ! FREE !</div>
</div>
</div>) }}export default Header;
----------------------------------------------------------------------------------------------------------------------
Home-form.js // Container collecting the credentials of the user as a form
import React, {Component} from 'react'
import _ from 'lodash'
import classNames from 'classnames'
import {upload} from '../helpers/upload'
import PropTypes from 'prop-types'
class HomeForm extends Component{
constructor(props){ super(props); this.state = { form: {
files: [],
to: '', from: '', phone: '', message: ''
}, errors:{
to: null, from: null, phone:null, message: null, files:
null,
} };
this._onTextChange = this._onTextChange.bind(this);
this._onSubmit = this._onSubmit.bind(this);
this._formValidation = this._formValidation.bind(this);
this._onFileAdded = this._onFileAdded.bind(this);
this._onFileRemove = this._onFileRemove.bind(this)
}
_isEmail(emailAddress) {
const emailRegex =
/^(([^<>()[].,;:s@"]+(.[^<>()[].,;:s@"]+)*)|(".+"))@(([^<>()[].,;:s@"]+.)+[^<>()[].,;:s@"]{2,
})$/i;
return emailRegex.test(emailAddress);
}
_isPhone(phoneNumber){
const phoneRegex = /^(?([0-9]{3}))?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
return phoneRegex.test(phoneNumber);
}
_formValidation(fields = [], callback = () => {}){
let {form, errors} = this.state;
_onSubmit(event){
event.preventDefault();
this._formValidation(['from', 'to','phone','files'], (isValid) => {
if(isValid){
//the form is valid and ready to submit.
const data = this.state.form;
if(this.props.onUploadBegin){
this.props.onUploadBegin(data);
}
upload(data, (event) => {
if(this.props.onUploadEvent){
this.props.onUploadEvent(event);
} }) } }); }
_onTextChange(event){
let{form} = this.state;
const fieldName = event.target.name;
const fieldValue = event.target.value;
form[fieldName] = fieldValue;
this.setState({form: form});
}
render(){
const {form,errors}= this.state;
const {files} = form;
return(
<div className={'app-card'}> <form onSubmit={this._onSubmit}>
<div className={'app-card-header'}> <div className={'app-card-header-inner'}>
{
files.length ? <div className={'app-files-selected'}>
{ files.map((file, index) => {
return (
<div key= {index} className={'app-files-selected-item'}>
<div className={'filename'}>{file.name}</div>
<div className={'file-action'}>
<button onClick={() => this._onFileRemove(index)}
type={'button'} className={'app-file-remove'}>X
</button> </div> </div> ) }) } </div> : null }
<div className={classNames('app-file-select-zone',{'error':_.get(errors,'files')})}>
<label htmlFor={'input-file'}>
<input onChange={this._onFileAdded} id={'input-file'} type="file"
multiple={true} />
{ files.length ? <span className={'app-upload-description text-
uppercase'}>Add more files</span> : <span>
<span className={'app-upload-icon'}><i className={'icon-picture-
o'} /> </span>
<span className={'app-upload-description'}>Drag and drop your files
here.</span>
</span> } </label>
</div> </div> </div>
<div className={classNames('app-form-item',{'error':_.get(errors,'phone')})}>
<label htmlFor={'phone'}>Receiver's Contact Number</label>
<input value={_.get(form, 'phone' )} onChange={this._onTextChange}
name={'phone'} placeholder={_.get(errors,'phone') ? _.get(errors,'phone'):'Your Contact Number'}
type={'text'} id={'phone'} maxLength={'10'}/>
</div>
<div className={'app-form-item'}>
<label htmlFor={'message'}>Message</label>
<textarea value= {_.get(form, 'message', '')} onChange={this._onTextChange}
name={'message'} placeholder={'Add a note (optional)'} id={'message'}/>
</div>
<div className={'app-form-actions'}>
<button type={'submit'} className={'app-button primary'}>Send</button>
</div> </div> </div> </form> </div>
) }}
HomeForm.propTypes = {
onUploadBegin: PropTypes.func,
onUploadEvent: PropTypes.func
};
export default HomeForm;
--------------------------------------------------------------------------------------------------------------------
Home-upload-sent.js // Container confirming the files sent to the receiver
import React,{Component} from 'react'
import PropTypes from 'prop-types'
import _ from 'lodash'
import {history} from "../history";
class HomeUploadSent extends Component{
constructor(props){
super(props);
}
render(){
const {data}=this.props;
console.log( "Data",data);
const to=_.get(data,'to');
const postId=_.get(data,'_id');
return(
<div className={'app-card app-card-upload-sent'}>
<div className={'app-card-content'}>
<div className={'app-card-content-inner'}>
<div className={'app-home-uploading'}>
<div className={'app-home-upload-sent-icon'}>
<i className={'icon-paper-plane'} />
</div>
<div className={'app-upload-sent-message app-text-center'}>
<h2>Files Sent! </h2>
<p>We have sent an email to {to} with a download link.The link will expire in 30
days</p> </div>
<div className={'app-upload-sent-actions app-form-actions'}>
<button onClick={()=>{
history.push( `/share/${postId}`)
}} className={'app-button primary'} type={'button '}>View File </button>
<button onClick={()=>{
if(this.props.onSendAnotherFile){
this.props.onSendAnotherFile(true); }
}} className={'app-button'} type={'button'}> Send Another File </button>
</div> </div> </div> </div> </div> ) }}
HomeUploadSent.propTypes={
data: PropTypes.object,
onSendAnotherFile: PropTypes.func }
export default HomeUploadSent;
----------------------------------------------------------------------------------------------------------------------
Upload.js //Container confirming the status of the uploaded files
import axios from 'axios'
import {apiUrl} from "../config";
import _ from 'lodash'
export const upload = (form, callback = () => {}) => {
const url = `${apiUrl}/upload`;
let files = _.get(form, 'files', []);
let data = new FormData();
_.each(files, (file) => {
data.append('files', file);
}); // upload successful.
axios.post(url, data, config).then((response) => {
return callback({
type: 'success',
payload: response.data
}) }).catch((err) => {
return callback({
type: 'error',
payload: err
}) }); };
----------------------------------------------------------------------------------------------------------------------
GoogleConfig.php // Checking the Google Configuration of the user.
<?php
session_start();
require_once "GoogleAPI/vendor/autoload.php";
$gClient = new Google_Client();
$gClient->setClientId("643208222747-
snjv039ocno2kjcfvpfebvorn6ojovnk.apps.googleusercontent.com");
$gClient->setClientSecret("SHtRqIGKQFhQLY1A78g2hzdu");
$gClient->setApplicationName("CPI Login Tutorial");
$gClient->setRedirectUri("http://localhost/test/g-callback.php");
$gClient->addScope("https://www.googleapis.com/auth/plus.login
https://www.googleapis.com/auth/userinfo.email");?>
----------------------------------------------------------------------------------------------------------------------
Connect.php // Connect to DB
<?php
$connection=mysqli_connect('localhost','root','');
if(!$connection){
echo"failed";}
$dbSelect=mysqli_select_db($connection,'demo');
if(!$dbSelect){
echo"failed selection";
die(mysqli_error($connection)); }?>
----------------------------------------------------------------------------------------------------------------------
gCallback.php //Google Callback
<?php
require_once "config.php";
if (isset($_SESSION['access_token']))
$gClient->setAccessToken($_SESSION['access_token']);
else if (isset($_GET['code'])) {
$token = $gClient->fetchAccessTokenWithAuthCode($_GET['code']);
$_SESSION['access_token'] = $token;
} else {
header('Location: index11.php');
exit(); }
$oAuth = new Google_Service_Oauth2($gClient);
$userData = $oAuth->userinfo_v2_me->get();
$_SESSION['id'] = $userData['id'];
$_SESSION['email'] = $userData['email'];
$_SESSION['gender'] = $userData['gender'];
$_SESSION['picture'] = $userData['picture'];
$_SESSION['familyName'] = $userData['familyName'];
$_SESSION['givenName'] = $userData['givenName'];
header('Location: http://www.facebook.com');
exit();
?>
----------------------------------------------------------------------------------------------------------------------
Login.php // Accepting the credentials for logging in of the user.
<?php
if(isset($_POST["submit"])){
require_once('connect.php');
if(isset($_POST) & !empty($_POST)){
$uname=$_POST['username'];
$password=$_POST['password'];
$sql="SELECT * FROM usermanagement WHERE username='".$uname."' AND
password='".$password."'";
$result=mysqli_query($connection,$sql);
if(mysqli_num_rows($result)==1){
header("Location: http://www.google.com");
exit();
}else
{ $message="we r done "; } } }
?>
<?php
if(isset($_POST["recover"])){
require_once('connect.php');
if(isset($_POST) & !empty($_POST)){
$email=$_POST["eemail"];
$data="SELECT * FROM usermanagement WHERE email='".$email."'";
$rresult=mysqli_query($connection,$data);
if(mysqli_num_rows($rresult)==1){
$row= mysqli_fetch_assoc($rresult);
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'sharma.deepanshu97@gmail.com';
$mail->Password = 'Deep@21081998';
$mail->setFrom('sharma.deepanshu97@gmail.com', 'Deepanshu Shamra');
$mail->addAddress( $row["email"]);
$mail->Subject = 'Password:Dpilot';
$mail->Body = "Your Password to access Dpilot is:" .$row["password"];
if ($mail->send())
$mess= "A mail containting password of your account is sent to you.";
else
$mess="something went wrong";
}else{
$mess="Please enter the registered email";
}}} ?>
<html>
<head>
<title>Dpilot Login/Signup </title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="fp.css">
<link rel="stylesheet" type="text/css" href="recover_style.css">
<body> <div class="loginbox"> <img src="sampleD.png" class="avatar">
<h1 > Login Here</h1> <form method="post" action="#"> <p>Username</p>
<input type="text" name="username" placeholder ="Enter Username" value="<?php
if(isset($uname) and!empty($uname)) {echo $uname;}?>" required>
<p>Password</p>
<input type="password" name="password" placeholder="Enter Password"value="" required >
<div> <?php if(isset($message) and!empty($message)){echo $message;} ?> </div>
<input type="submit" name="submit" value="Login">
<a href="dex.php" class="link">Dont Have an Account?</a><br>
<a class="link1" href="#modal" class="modal-open" id="modal-open">Lost Your
Password?</a></form>
<div class="modal" id="modal"> <div class="modal-content">
<a href="" class="modal-close">&times;</a> <div class="lloginbox">
<img src="sampleD.png" class="aavatar"> <h1 > Password Recovery</h1>
<form action="index11.php#modal" method="post">
<p id="ww">Registered Email</p>
<input type="text" name="eemail" placeholder="Enter Email">
<input type="submit" name="recover" value="Recover Password">
<div> <?php if(isset($mess) and!empty($mess)){echo $mess;} ?> </div>
</form> </div> </div> </div> </div>
</body> </head> </html>
----------------------------------------------------------------------------------------------------------------------
Signup.php // Accepting the credentials for signing up of the new user.
<?php
require_once('connect.php');
if(isset($_POST) & !empty($_POST)){
$username= $_POST['username'];
$email= $_POST['email'];
$password= $_POST['password'];
$repassword= $_POST['password2'];
if(!$username OR !$email OR !$password)
{ $message="Please Fill All the details";}
else{
if($password==$repassword){
{$sql="INSERT INTO usermanagement (username,email,password) VALUES
('$username','$email','$password')";
$result=mysqli_query($connection,$sql);
header("Location: http://www.google.com");
}
if($result){
$message="success";
}else
$message="Username already exist";}
else
$message="Password doesnot match";
}}?>
<?php
require_once "config.php";
if (isset($_SESSION['access_token'])) {
header('Location: https://056e1c1a.ngrok.io/test/dex.php');
exit(); }
$loginURL = $gClient->createAuthUrl();?>
<?php
require_once "Fconfig.php";
if (isset($_SESSION['access_token'])) {
header(' Location: https://056e1c1a.ngrok.io/test/logout.php');
exit(); }
$redirectURL = " https://056e1c1a.ngrok.io/test/f-callback.php";
$permissions = ['email'];
$FloginURL = $helper->getLoginUrl($redirectURL, $permissions);
?> <html>
<head> <title> Dpilot Signup </title>
<link rel="stylesheet" type="text/css" href="styl.css">
</head>
<body>
<div id="login-box">
<div id="left-box">
<form class="form-signin" method="post" >
<h1>Sign Up</h1>
<div id="al"> <?php if(isset($message) and!empty($message)){echo $message;} ?>
</div>
<input type="text" name="username" placeholder="Username" value="<?php if(isset($result)
and!empty($result)){if($result) echo "";}else if(isset($username) and!empty($username)) {echo
$username;} ?>" required/>
<input type="text" name="email" placeholder="Email" value="<?php if(isset($result)
and!empty($result)){if($result) echo "";}else if(isset($email) and!empty($email)) {echo $email;}
?>" required/>
<input type="password" name="password" placeholder="Password" />
<input type="password" name="password2" placeholder="Retype Password"/>
<input type="submit" name="signup-button" value="Sign Up"/>
</form></div>
<div class="right-box">
<span class="SignInWith">Sign In With<br/>Social Network</span>
<button class="social-fb" onclick="window.location = '<?php echo $FloginURL ?>';">Login
With Facebook</button> </body> </html>
----------------------------------------------------------------------------------------------------------------------
Fconnfig.php // Facebook config
<?php
require_once "Facebook/autoload.php";
$FB = new FacebookFacebook([
'app_id' => '193686724665067',
'app_secret' => '7b3a1ca8596b1c1edf3509ee8c46bfeb',
'default_graph_version' => 'v2.10'
]); $helper = $FB->getRedirectLoginHelper(); ?>
----------------------------------------------------------------------------------------------------------------------
fCallback.php // Facebook callback
<?php
require_once "Fconfig.php";
header('Location: https://056e1c1a.ngrok.io/test/logout.php');
exit();
?
Appendix-II (Sample Output)
Welcome Landing page and users will get a short description of what is Dpilot
Landing Page with a quote
Landing Page: Steps to use Dpilot
Landing Page : What we offer extra
Landing Page: Reviews
Landing Page: Above is the Contact form and providing follow us option
Login Screen: Users can Login using the username and password set by users only.
Signup Screen: Users can sign through Google account i.e. Gmail and Facebook
Password Recovery Screen
Dashboard: Front screen where users can select the files, filling up the credentials with a message.
Uploading screen with a status bar
Confirmation of the file send
Viewing and downloading screen
Mail received by the receiver through Dpilot webapp
Fig 25: Storage of files on the Amazon cloud
Database of the uploading files by the users of Dpilot Webapp
Downloading the files in zip format
Extracting the files
Bot: BOT is the additional feature of Dpilot name as “CabinCrew”.
Bot: Providing a user-friendly environment.

More Related Content

What's hot

連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」matuura_core
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolveXSolve
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQLPeter Eisentraut
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsNeo4j
 
AJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleAJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleChristopher Curtin
 
Event sourcing w PHP (by Piotr Kacała)
Event sourcing w PHP (by Piotr Kacała)Event sourcing w PHP (by Piotr Kacała)
Event sourcing w PHP (by Piotr Kacała)GOG.com dev team
 
The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196Mahmoud Samir Fayed
 

What's hot (18)

Perl Web Client
Perl Web ClientPerl Web Client
Perl Web Client
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
 
Nubilus Perl
Nubilus PerlNubilus Perl
Nubilus Perl
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
 
Rxjs marble-testing
Rxjs marble-testingRxjs marble-testing
Rxjs marble-testing
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
 
Rxjs vienna
Rxjs viennaRxjs vienna
Rxjs vienna
 
V8
V8V8
V8
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and Operations
 
AJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleAJUG April 2011 Cascading example
AJUG April 2011 Cascading example
 
Event sourcing w PHP (by Piotr Kacała)
Event sourcing w PHP (by Piotr Kacała)Event sourcing w PHP (by Piotr Kacała)
Event sourcing w PHP (by Piotr Kacała)
 
Why realm?
Why realm?Why realm?
Why realm?
 
The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196
 
Rust ⇋ JavaScript
Rust ⇋ JavaScriptRust ⇋ JavaScript
Rust ⇋ JavaScript
 
Rxjs swetugg
Rxjs swetuggRxjs swetugg
Rxjs swetugg
 

Similar to Dpilot - Source Code with Snapshots

前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说Ting Lv
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
 
Incremental Type Safety in React Apollo
Incremental Type Safety in React Apollo Incremental Type Safety in React Apollo
Incremental Type Safety in React Apollo Evans Hauser
 
Rntb20200805
Rntb20200805Rntb20200805
Rntb20200805t k
 
NodeJs
NodeJsNodeJs
NodeJsdizabl
 
Nodejs do teste de unidade ao de integração
Nodejs  do teste de unidade ao de integraçãoNodejs  do teste de unidade ao de integração
Nodejs do teste de unidade ao de integraçãoVinícius Pretto da Silva
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015Fernando Daciuk
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on PlayframeworkKnoldus Inc.
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionJesus Manuel Olivas
 
node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascriptEldar Djafarov
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium AppsNate Abele
 
Python Google Cloud Function with CORS
Python Google Cloud Function with CORSPython Google Cloud Function with CORS
Python Google Cloud Function with CORSRapidValue
 

Similar to Dpilot - Source Code with Snapshots (20)

Pengenalan blaast platform sdk
Pengenalan blaast platform sdkPengenalan blaast platform sdk
Pengenalan blaast platform sdk
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
Incremental Type Safety in React Apollo
Incremental Type Safety in React Apollo Incremental Type Safety in React Apollo
Incremental Type Safety in React Apollo
 
Rntb20200805
Rntb20200805Rntb20200805
Rntb20200805
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
NodeJs
NodeJsNodeJs
NodeJs
 
Nodejs do teste de unidade ao de integração
Nodejs  do teste de unidade ao de integraçãoNodejs  do teste de unidade ao de integração
Nodejs do teste de unidade ao de integração
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
 
Reduxing like a pro
Reduxing like a proReduxing like a pro
Reduxing like a pro
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on Playframework
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 Edition
 
node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascript
 
Textile
TextileTextile
Textile
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 
Intro to Ember.JS 2016
Intro to Ember.JS 2016Intro to Ember.JS 2016
Intro to Ember.JS 2016
 
Python Google Cloud Function with CORS
Python Google Cloud Function with CORSPython Google Cloud Function with CORS
Python Google Cloud Function with CORS
 

Recently uploaded

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 

Recently uploaded (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 

Dpilot - Source Code with Snapshots

  • 1. Appendix-I (Program Code) File.js // Collecting data from the users (sender) import _ from 'lodash' class File { constructor(app) { this.app = app; this.model = { name: null, originalName: null, mimeType: null, size: null, etag: null, created: new Date(), } } initWithObject(object){ this.model.name = _.get(object, 'key'); this.model.originalName = _.get(object, 'originalname'); this.model.mimeType = _.get(object, 'mimetype'); this.model.size = _.get(object, 'size'); this.model.etag= _.get(object, 'etag'); this.model.created = new Date(); return this; } toJSON(){ return this.model; } save(callback) { const db = this.app.get('db'); db.collection('files').insertOne(this.model, (err, result) => { return callback(err, result); });} } export default File; -------------------------------------------------------------------------------------------------------------------- Archiver.js // Download all the files as a zip file import archiver from 'archiver' import _ from 'lodash' import path from 'path' import S3 from './s3' export default class FileArchiver{
  • 2. constructor(app, files = [], response){ this.app = app; this.files = files; this.response = response; } download(){ const app = this.app; const files = this.files; //const uploadDir = app.get('storageDir'); const zip = archiver('zip'); const response = this.response; response.attachment('download.zip'); zip.pipe(response); const s3Downloader = new S3(app, response); _.each(files, (file) => { const fileObject = s3Downloader.getObject(file); zip.append(fileObject, {name: _.get(file, 'originalName')}); }); zip.finalize(); return this; }} -------------------------------------------------------------------------------------------------------------------- Config.js // Sending Notification Alert through Email import {accessKeyId,secretAccessKey} from './s3-config.json' export const smtp = { host: 'smtp.sendgrid.net', port: 587, secure: false, // true for 465, false for other ports auth: { user: 'apikey', // generated ethereal user pass: 'SG.HXUZZppORTSHzQuQwC-5EA.OgpSmEJnvXwo2qBGX- ujkk7OqB1hSw2Kwlxal9abLUI' // generated ethereal password }} export const url = 'http://localhost:3001'; export const s3Config = { accessKeyId: 'AKIAI7PBFWK7ZNHYIGQA', secretAccessKey: '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'} export const S3Region = 'us-east-1' export const s3Bucket = 'fileapp0' -------------------------------------------------------------------------------------------------------------------- Database.js // Connecting the database through Mongodb import {MongoClient} from 'mongodb'; const url ='mongodb://localhost:27017/fileapp'; export const connect=(callback)=>{ MongoClient.connect(url, (err, db) => {
  • 3. return callback(err, db); }); }; -------------------------------------------------------------------------------------------------------------------- Index.js // Monitor for the file present in package.JSON import http from 'http'; import express from 'express'; import {connect} from "./database"; import AppRouter from './router' import multer from 'multer' import path from 'path'; import nodemailer from 'nodemailer'; import {smtp, s3Config, S3Region, s3Bucket} from './config' // Amazon S3 Setup import AWS from 'aws-sdk' import multerS3 from 'multer-s3' AWS.config.update(s3Config); AWS.config.region = S3Region ; const s3 = new AWS.S3(); // setup Email let email = nodemailer.createTransport(smtp); //File Storage Config const storageDir = path.join(__dirname,'..', 'storage'); // const upload = multer({ storage: storageConfig }) const upload = multer({ storage: multerS3({ s3: s3, bucket: s3Bucket, metadata: function (req, file, cb) { cb(null, {fieldName: file.fieldname}); }, key: function (req, file, cb) { const filename = `${Date.now().toString()}-${file.originalname}`; cb(null, filename) } }) }) //End File Storage Config const PORT = 3000; const app = express(); app.server = http.createServer(app); app.use(morgan('dev'));
  • 4. app.use(cors({ exposedHeaders: "*"})); app.set('root', __dirname); app.set('storageDir',storageDir); app.upload = upload; app.email = email; app.s3 = s3; //Connect to database connect((err,db)=> { if (err) { console.log("An error connecting to the database"); throw(err); } app.set('db',db); //init router new AppRouter(app); app.server.listen(process.env.PORT || PORT, () => { console.log(`App is running on port ${app.server.address().port}`); }); }); export default app; -------------------------------------------------------------------------------------------------------------------- Router.js // JS library that provide an API for handling routes import {version} from '../package.json' import path from 'path' import _ from 'lodash' import {ObjectID} from 'mongodb' import File from './models/file' import Post from './models/post' import FileArchiver from './archiver' import Email from './email' import S3 from './s3' class AppRouter { constructor(app) { this.app = app; this.setupRouters(); } setupRouters() { const app = this.app; const uploadDir = app.get('storageDir');
  • 5. const upload = app.upload; const db = app.get('db'); //root routing app.get('/', (req, res, next) => { return res.status(200).json({ version: version }); }); //Upload Routing app.post('/api/upload', upload.array('files'), (req, res, next) => { const files = _.get(req, 'files', []); console.log("files objects from s3 multer", files); let fileModels = []; _.each(files, (fileObject) => { const newFile = new File(app).initWithObject(fileObject).toJSON(); fileModels.push(newFile); }); if (fileModels.length) { //check for empty file db.collection('files').insertMany(fileModels, (err, result) => { if (err) { return res.status(503).json({ error: { message: "Unable to save your file", } }); } let post = new Post(app).initWithObject({ from: _.get(req,'body.from'), to: _.get(req,'body.to'), message: _.get(req,'body.message'), phone: _.get(req,'body.phone'), files: result.insertedIds, }).toJSON(); //let save post objects to posts collection. db.collection('posts').insertOne(post,(err,result)=>{ if(err){ return res.status(503).json({error:{message:"Your upload could not be saved"}}); } //implement email sending to user with download link. //send email const sendEmail = new Email(app).sendDownloadLink(post, (err, info) => { });
  • 6. // callback to react app with post detail. return res.json(post); }); }); } else { return res.status(503).json({ error: {message: "files upload is required"} }); } }); // Download file from S3 service const file = _.get(result, '[0]'); const downloader = new S3(app, res); // return downloader.download(file); Proxy download from s3 service // Download Directly from S3 const downloadUrl = downloader.getDownloadUrl(file); return res.redirect(downloadUrl); }); }); //routing for post detail/api/posts/:id app.get('/api/posts/:id',(req,res,next)=>{ const postId=_.get(req,'params.id'); this.getPostById(postId, (err, result) => { if(err){ return res.status(404).json({error:{message: 'File not found.'}}); } return res.json(result); }) }); // Routing download zip files. app.get('/api/posts/:id/download', (req, res, next) => { const id = _.get(req, 'params.id', null); this.getPostById(id, (err, result) => { if (err) { return res.status(404).json({error: {message: 'File not found.'}}); } const files = _.get(result, 'files', []); const archiver = new FileArchiver(app, files, res).download(); return archiver; }) }); } getPostById(id, callback = () => {}){ const app= this.app; const db = app.get('db'); let postObjectId=null; try{ postObjectId=new ObjectID(id); }
  • 7. catch (err){ return callback(err, null); } db.collection('posts').find({_id:postObjectId}).limit(1).toArray((err,results)=>{ let result =_.get(results,'[0]'); if(err || !result){ return callback(err ? err: new Error("File not found")); } const fileIds=_.get(result,'files',[]); db.collection('files').find({_id:{$in: fileIds}}).toArray((err,files)=>{ if(err || !files || !files.length){ return callback(err ? err: new Error("File not found")); } result.files=files; return callback(null, result); }); }) }} export default AppRouter; ---------------------------------------------------------------------------------------------------------------------- S3.js // Connecting the S3 with Dpliot for Cloud Application import _ from 'lodash' import {s3Bucket} from './config' export default class S3{ constructor(app, response){ this.app = app; this.response = response; } getObject(file){ const s3 = this.app.s3; const options ={ Bucket: s3Bucket, Key: _.get(file, 'name') }; return s3.getObject(options).createReadStream(); } download(file){ const s3 = this.app.s3; const response = this.response; // get Object from S3 service const filename = _.get(file, 'originalName'); response.attachment(filename); const options ={
  • 8. Bucket: s3Bucket, Key: _.get(file, 'name') }; const fileObject = s3.getObject(options).createReadStream(); fileObject.pipe(response); } getDownloadUrl(file){ const s3 = this.app.s3; const options ={ Bucket: s3Bucket, Key: _.get(file, 'name'), Expires: 3600, // one hour expires. }; const url = s3.getSignedUrl('getObject', options); return url; }} -------------------------------------------------------------------------------------------------------------------- Header.js // Designing Dashboard through React import React,{Component} from 'react' class Header extends Component { render() { return ( <div className={'app-header'}> <div className={'app-site-info'}> <h1><i className={'icon-paper-plane'} /> Dpilot</h1> <div className={'site-title'}>SHARE YOUR FILE.</div> <div className={'site-slogan'}>SECURE ! SAFE ! FREE !</div> </div> </div>) }}export default Header; ---------------------------------------------------------------------------------------------------------------------- Home-form.js // Container collecting the credentials of the user as a form import React, {Component} from 'react' import _ from 'lodash' import classNames from 'classnames' import {upload} from '../helpers/upload' import PropTypes from 'prop-types' class HomeForm extends Component{ constructor(props){ super(props); this.state = { form: { files: [], to: '', from: '', phone: '', message: '' }, errors:{
  • 9. to: null, from: null, phone:null, message: null, files: null, } }; this._onTextChange = this._onTextChange.bind(this); this._onSubmit = this._onSubmit.bind(this); this._formValidation = this._formValidation.bind(this); this._onFileAdded = this._onFileAdded.bind(this); this._onFileRemove = this._onFileRemove.bind(this) } _isEmail(emailAddress) { const emailRegex = /^(([^<>()[].,;:s@"]+(.[^<>()[].,;:s@"]+)*)|(".+"))@(([^<>()[].,;:s@"]+.)+[^<>()[].,;:s@"]{2, })$/i; return emailRegex.test(emailAddress); } _isPhone(phoneNumber){ const phoneRegex = /^(?([0-9]{3}))?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/; return phoneRegex.test(phoneNumber); } _formValidation(fields = [], callback = () => {}){ let {form, errors} = this.state; _onSubmit(event){ event.preventDefault(); this._formValidation(['from', 'to','phone','files'], (isValid) => { if(isValid){ //the form is valid and ready to submit. const data = this.state.form; if(this.props.onUploadBegin){ this.props.onUploadBegin(data); } upload(data, (event) => { if(this.props.onUploadEvent){ this.props.onUploadEvent(event); } }) } }); } _onTextChange(event){ let{form} = this.state; const fieldName = event.target.name; const fieldValue = event.target.value; form[fieldName] = fieldValue;
  • 10. this.setState({form: form}); } render(){ const {form,errors}= this.state; const {files} = form; return( <div className={'app-card'}> <form onSubmit={this._onSubmit}> <div className={'app-card-header'}> <div className={'app-card-header-inner'}> { files.length ? <div className={'app-files-selected'}> { files.map((file, index) => { return ( <div key= {index} className={'app-files-selected-item'}> <div className={'filename'}>{file.name}</div> <div className={'file-action'}> <button onClick={() => this._onFileRemove(index)} type={'button'} className={'app-file-remove'}>X </button> </div> </div> ) }) } </div> : null } <div className={classNames('app-file-select-zone',{'error':_.get(errors,'files')})}> <label htmlFor={'input-file'}> <input onChange={this._onFileAdded} id={'input-file'} type="file" multiple={true} /> { files.length ? <span className={'app-upload-description text- uppercase'}>Add more files</span> : <span> <span className={'app-upload-icon'}><i className={'icon-picture- o'} /> </span> <span className={'app-upload-description'}>Drag and drop your files here.</span> </span> } </label> </div> </div> </div> <div className={classNames('app-form-item',{'error':_.get(errors,'phone')})}> <label htmlFor={'phone'}>Receiver's Contact Number</label> <input value={_.get(form, 'phone' )} onChange={this._onTextChange} name={'phone'} placeholder={_.get(errors,'phone') ? _.get(errors,'phone'):'Your Contact Number'} type={'text'} id={'phone'} maxLength={'10'}/> </div> <div className={'app-form-item'}> <label htmlFor={'message'}>Message</label> <textarea value= {_.get(form, 'message', '')} onChange={this._onTextChange} name={'message'} placeholder={'Add a note (optional)'} id={'message'}/>
  • 11. </div> <div className={'app-form-actions'}> <button type={'submit'} className={'app-button primary'}>Send</button> </div> </div> </div> </form> </div> ) }} HomeForm.propTypes = { onUploadBegin: PropTypes.func, onUploadEvent: PropTypes.func }; export default HomeForm; -------------------------------------------------------------------------------------------------------------------- Home-upload-sent.js // Container confirming the files sent to the receiver import React,{Component} from 'react' import PropTypes from 'prop-types' import _ from 'lodash' import {history} from "../history"; class HomeUploadSent extends Component{ constructor(props){ super(props); } render(){ const {data}=this.props; console.log( "Data",data); const to=_.get(data,'to'); const postId=_.get(data,'_id'); return( <div className={'app-card app-card-upload-sent'}> <div className={'app-card-content'}> <div className={'app-card-content-inner'}> <div className={'app-home-uploading'}> <div className={'app-home-upload-sent-icon'}> <i className={'icon-paper-plane'} /> </div> <div className={'app-upload-sent-message app-text-center'}> <h2>Files Sent! </h2> <p>We have sent an email to {to} with a download link.The link will expire in 30 days</p> </div> <div className={'app-upload-sent-actions app-form-actions'}> <button onClick={()=>{
  • 12. history.push( `/share/${postId}`) }} className={'app-button primary'} type={'button '}>View File </button> <button onClick={()=>{ if(this.props.onSendAnotherFile){ this.props.onSendAnotherFile(true); } }} className={'app-button'} type={'button'}> Send Another File </button> </div> </div> </div> </div> </div> ) }} HomeUploadSent.propTypes={ data: PropTypes.object, onSendAnotherFile: PropTypes.func } export default HomeUploadSent; ---------------------------------------------------------------------------------------------------------------------- Upload.js //Container confirming the status of the uploaded files import axios from 'axios' import {apiUrl} from "../config"; import _ from 'lodash' export const upload = (form, callback = () => {}) => { const url = `${apiUrl}/upload`; let files = _.get(form, 'files', []); let data = new FormData(); _.each(files, (file) => { data.append('files', file); }); // upload successful. axios.post(url, data, config).then((response) => { return callback({ type: 'success', payload: response.data }) }).catch((err) => { return callback({ type: 'error', payload: err }) }); }; ---------------------------------------------------------------------------------------------------------------------- GoogleConfig.php // Checking the Google Configuration of the user. <?php session_start(); require_once "GoogleAPI/vendor/autoload.php"; $gClient = new Google_Client();
  • 13. $gClient->setClientId("643208222747- snjv039ocno2kjcfvpfebvorn6ojovnk.apps.googleusercontent.com"); $gClient->setClientSecret("SHtRqIGKQFhQLY1A78g2hzdu"); $gClient->setApplicationName("CPI Login Tutorial"); $gClient->setRedirectUri("http://localhost/test/g-callback.php"); $gClient->addScope("https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email");?> ---------------------------------------------------------------------------------------------------------------------- Connect.php // Connect to DB <?php $connection=mysqli_connect('localhost','root',''); if(!$connection){ echo"failed";} $dbSelect=mysqli_select_db($connection,'demo'); if(!$dbSelect){ echo"failed selection"; die(mysqli_error($connection)); }?> ---------------------------------------------------------------------------------------------------------------------- gCallback.php //Google Callback <?php require_once "config.php"; if (isset($_SESSION['access_token'])) $gClient->setAccessToken($_SESSION['access_token']); else if (isset($_GET['code'])) { $token = $gClient->fetchAccessTokenWithAuthCode($_GET['code']); $_SESSION['access_token'] = $token; } else { header('Location: index11.php'); exit(); } $oAuth = new Google_Service_Oauth2($gClient); $userData = $oAuth->userinfo_v2_me->get(); $_SESSION['id'] = $userData['id']; $_SESSION['email'] = $userData['email']; $_SESSION['gender'] = $userData['gender']; $_SESSION['picture'] = $userData['picture']; $_SESSION['familyName'] = $userData['familyName']; $_SESSION['givenName'] = $userData['givenName']; header('Location: http://www.facebook.com');
  • 14. exit(); ?> ---------------------------------------------------------------------------------------------------------------------- Login.php // Accepting the credentials for logging in of the user. <?php if(isset($_POST["submit"])){ require_once('connect.php'); if(isset($_POST) & !empty($_POST)){ $uname=$_POST['username']; $password=$_POST['password']; $sql="SELECT * FROM usermanagement WHERE username='".$uname."' AND password='".$password."'"; $result=mysqli_query($connection,$sql); if(mysqli_num_rows($result)==1){ header("Location: http://www.google.com"); exit(); }else { $message="we r done "; } } } ?> <?php if(isset($_POST["recover"])){ require_once('connect.php'); if(isset($_POST) & !empty($_POST)){ $email=$_POST["eemail"]; $data="SELECT * FROM usermanagement WHERE email='".$email."'"; $rresult=mysqli_query($connection,$data); if(mysqli_num_rows($rresult)==1){ $row= mysqli_fetch_assoc($rresult); require 'phpmailer/PHPMailerAutoload.php'; $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = "smtp.gmail.com"; $mail->SMTPSecure = "ssl"; $mail->Port = 465; $mail->SMTPAuth = true; $mail->Username = 'sharma.deepanshu97@gmail.com'; $mail->Password = 'Deep@21081998'; $mail->setFrom('sharma.deepanshu97@gmail.com', 'Deepanshu Shamra');
  • 15. $mail->addAddress( $row["email"]); $mail->Subject = 'Password:Dpilot'; $mail->Body = "Your Password to access Dpilot is:" .$row["password"]; if ($mail->send()) $mess= "A mail containting password of your account is sent to you."; else $mess="something went wrong"; }else{ $mess="Please enter the registered email"; }}} ?> <html> <head> <title>Dpilot Login/Signup </title> <link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" type="text/css" href="fp.css"> <link rel="stylesheet" type="text/css" href="recover_style.css"> <body> <div class="loginbox"> <img src="sampleD.png" class="avatar"> <h1 > Login Here</h1> <form method="post" action="#"> <p>Username</p> <input type="text" name="username" placeholder ="Enter Username" value="<?php if(isset($uname) and!empty($uname)) {echo $uname;}?>" required> <p>Password</p> <input type="password" name="password" placeholder="Enter Password"value="" required > <div> <?php if(isset($message) and!empty($message)){echo $message;} ?> </div> <input type="submit" name="submit" value="Login"> <a href="dex.php" class="link">Dont Have an Account?</a><br> <a class="link1" href="#modal" class="modal-open" id="modal-open">Lost Your Password?</a></form> <div class="modal" id="modal"> <div class="modal-content"> <a href="" class="modal-close">&times;</a> <div class="lloginbox"> <img src="sampleD.png" class="aavatar"> <h1 > Password Recovery</h1> <form action="index11.php#modal" method="post"> <p id="ww">Registered Email</p> <input type="text" name="eemail" placeholder="Enter Email"> <input type="submit" name="recover" value="Recover Password"> <div> <?php if(isset($mess) and!empty($mess)){echo $mess;} ?> </div> </form> </div> </div> </div> </div> </body> </head> </html> ---------------------------------------------------------------------------------------------------------------------- Signup.php // Accepting the credentials for signing up of the new user.
  • 16. <?php require_once('connect.php'); if(isset($_POST) & !empty($_POST)){ $username= $_POST['username']; $email= $_POST['email']; $password= $_POST['password']; $repassword= $_POST['password2']; if(!$username OR !$email OR !$password) { $message="Please Fill All the details";} else{ if($password==$repassword){ {$sql="INSERT INTO usermanagement (username,email,password) VALUES ('$username','$email','$password')"; $result=mysqli_query($connection,$sql); header("Location: http://www.google.com"); } if($result){ $message="success"; }else $message="Username already exist";} else $message="Password doesnot match"; }}?> <?php require_once "config.php"; if (isset($_SESSION['access_token'])) { header('Location: https://056e1c1a.ngrok.io/test/dex.php'); exit(); } $loginURL = $gClient->createAuthUrl();?> <?php require_once "Fconfig.php"; if (isset($_SESSION['access_token'])) { header(' Location: https://056e1c1a.ngrok.io/test/logout.php'); exit(); } $redirectURL = " https://056e1c1a.ngrok.io/test/f-callback.php"; $permissions = ['email']; $FloginURL = $helper->getLoginUrl($redirectURL, $permissions); ?> <html> <head> <title> Dpilot Signup </title>
  • 17. <link rel="stylesheet" type="text/css" href="styl.css"> </head> <body> <div id="login-box"> <div id="left-box"> <form class="form-signin" method="post" > <h1>Sign Up</h1> <div id="al"> <?php if(isset($message) and!empty($message)){echo $message;} ?> </div> <input type="text" name="username" placeholder="Username" value="<?php if(isset($result) and!empty($result)){if($result) echo "";}else if(isset($username) and!empty($username)) {echo $username;} ?>" required/> <input type="text" name="email" placeholder="Email" value="<?php if(isset($result) and!empty($result)){if($result) echo "";}else if(isset($email) and!empty($email)) {echo $email;} ?>" required/> <input type="password" name="password" placeholder="Password" /> <input type="password" name="password2" placeholder="Retype Password"/> <input type="submit" name="signup-button" value="Sign Up"/> </form></div> <div class="right-box"> <span class="SignInWith">Sign In With<br/>Social Network</span> <button class="social-fb" onclick="window.location = '<?php echo $FloginURL ?>';">Login With Facebook</button> </body> </html> ---------------------------------------------------------------------------------------------------------------------- Fconnfig.php // Facebook config <?php require_once "Facebook/autoload.php"; $FB = new FacebookFacebook([ 'app_id' => '193686724665067', 'app_secret' => '7b3a1ca8596b1c1edf3509ee8c46bfeb', 'default_graph_version' => 'v2.10' ]); $helper = $FB->getRedirectLoginHelper(); ?> ---------------------------------------------------------------------------------------------------------------------- fCallback.php // Facebook callback <?php require_once "Fconfig.php"; header('Location: https://056e1c1a.ngrok.io/test/logout.php'); exit(); ?
  • 18. Appendix-II (Sample Output) Welcome Landing page and users will get a short description of what is Dpilot Landing Page with a quote Landing Page: Steps to use Dpilot
  • 19. Landing Page : What we offer extra Landing Page: Reviews Landing Page: Above is the Contact form and providing follow us option
  • 20. Login Screen: Users can Login using the username and password set by users only. Signup Screen: Users can sign through Google account i.e. Gmail and Facebook Password Recovery Screen
  • 21. Dashboard: Front screen where users can select the files, filling up the credentials with a message. Uploading screen with a status bar Confirmation of the file send
  • 22. Viewing and downloading screen Mail received by the receiver through Dpilot webapp Fig 25: Storage of files on the Amazon cloud
  • 23. Database of the uploading files by the users of Dpilot Webapp Downloading the files in zip format Extracting the files
  • 24. Bot: BOT is the additional feature of Dpilot name as “CabinCrew”. Bot: Providing a user-friendly environment.