SlideShare a Scribd company logo
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 (18)

Perl Web Client
Perl Web ClientPerl Web Client
Perl Web Client
Flavio Poletti
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
matuura_core
 
Nubilus Perl
Nubilus PerlNubilus Perl
Nubilus Perl
Flavio Poletti
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
Flavio Poletti
 
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
XSolve
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
Giovanni Scerra ☃
 
Rxjs marble-testing
Rxjs marble-testingRxjs marble-testing
Rxjs marble-testing
Christoffer Noring
 
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
Dmitry Soshnikov
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
Peter Eisentraut
 
Rxjs vienna
Rxjs viennaRxjs vienna
Rxjs vienna
Christoffer Noring
 
V8
V8V8
V8
changehee lee
 
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
Neo4j
 
AJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleAJUG April 2011 Cascading example
AJUG April 2011 Cascading example
Christopher 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
 
Why realm?
Why realm?Why realm?
Why realm?
Leonardo Taehwan Kim
 
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
Mahmoud Samir Fayed
 
Rust ⇋ JavaScript
Rust ⇋ JavaScriptRust ⇋ JavaScript
Rust ⇋ JavaScript
Ingvar Stepanyan
 
Rxjs swetugg
Rxjs swetuggRxjs swetugg
Rxjs swetugg
Christoffer Noring
 
連邦の白いヤツ 「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 / XSolve
XSolve
 
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
Dmitry Soshnikov
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
Peter 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 Operations
Neo4j
 
AJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleAJUG April 2011 Cascading example
AJUG April 2011 Cascading example
Christopher 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 196
Mahmoud Samir Fayed
 

Similar to Dpilot Source Code With ScreenShots (20)

Pengenalan blaast platform sdk
Pengenalan blaast platform sdkPengenalan blaast platform sdk
Pengenalan blaast platform sdk
Arief Bayu Purwanto
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick 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
Rntb20200805
t k
 
Android workshop
Android workshopAndroid workshop
Android workshop
Michael Galpin
 
NodeJs
NodeJsNodeJs
NodeJs
dizabl
 
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
Viní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 2015
Fernando Daciuk
 
Reduxing like a pro
Reduxing like a proReduxing like a pro
Reduxing like a pro
Boris Dinkevich
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on Playframework
Knoldus Inc.
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
Seri Moth
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
Bruno Scopelliti
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 Edition
Jesus 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 javascript
Eldar Djafarov
 
Textile
TextileTextile
Textile
Vanessa Lošić
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
Nate Abele
 
Intro to Ember.JS 2016
Intro to Ember.JS 2016Intro to Ember.JS 2016
Intro to Ember.JS 2016
Sandino Núñez
 
Python Google Cloud Function with CORS
Python Google Cloud Function with CORSPython Google Cloud Function with CORS
Python Google Cloud Function with CORS
RapidValue
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick 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
Rntb20200805
t k
 
NodeJs
NodeJsNodeJs
NodeJs
dizabl
 
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
Viní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 2015
Fernando Daciuk
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on Playframework
Knoldus Inc.
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
Seri Moth
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 Edition
Jesus 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 javascript
Eldar Djafarov
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
Nate Abele
 
Python Google Cloud Function with CORS
Python Google Cloud Function with CORSPython Google Cloud Function with CORS
Python Google Cloud Function with CORS
RapidValue
 

Recently uploaded (20)

15 Years of Insights from a TDD Practitioner (NDC Oslo)
15 Years of Insights from a TDD Practitioner (NDC Oslo)15 Years of Insights from a TDD Practitioner (NDC Oslo)
15 Years of Insights from a TDD Practitioner (NDC Oslo)
Dennis Doomen
 
Shortcomings of EHS Software – And How to Overcome Them
Shortcomings of EHS Software – And How to Overcome ThemShortcomings of EHS Software – And How to Overcome Them
Shortcomings of EHS Software – And How to Overcome Them
TECH EHS Solution
 
20200823-Intro-to-FIRRTLllllllllllllllllll
20200823-Intro-to-FIRRTLllllllllllllllllll20200823-Intro-to-FIRRTLllllllllllllllllll
20200823-Intro-to-FIRRTLllllllllllllllllll
JonathanSong28
 
Lightworks PRO 2025.1 Crack Free Download
Lightworks PRO 2025.1 Crack Free DownloadLightworks PRO 2025.1 Crack Free Download
Lightworks PRO 2025.1 Crack Free Download
Berkeley
 
Skilling up your dev team - 8 things to consider when skilling-up your dev team
Skilling up your dev team - 8 things to consider when skilling-up your dev teamSkilling up your dev team - 8 things to consider when skilling-up your dev team
Skilling up your dev team - 8 things to consider when skilling-up your dev team
Derk-Jan de Grood
 
Introduction to QM, QA, QC, Bug's priority and severity
Introduction to QM, QA, QC, Bug's priority and severityIntroduction to QM, QA, QC, Bug's priority and severity
Introduction to QM, QA, QC, Bug's priority and severity
Arshad QA
 
Getting Started with BoxLang - CFCamp 2025.pdf
Getting Started with BoxLang - CFCamp 2025.pdfGetting Started with BoxLang - CFCamp 2025.pdf
Getting Started with BoxLang - CFCamp 2025.pdf
Ortus Solutions, Corp
 
Menu in Android (Define,Create,Inflate and Click Handler)
Menu in Android (Define,Create,Inflate and Click Handler)Menu in Android (Define,Create,Inflate and Click Handler)
Menu in Android (Define,Create,Inflate and Click Handler)
Nabin Dhakal
 
Advance Sales Commission Payments in Odoo
Advance Sales Commission Payments in OdooAdvance Sales Commission Payments in Odoo
Advance Sales Commission Payments in Odoo
AxisTechnolabs
 
Key Characteristics of High-Performing Insurance Broker Software
Key Characteristics of High-Performing Insurance Broker SoftwareKey Characteristics of High-Performing Insurance Broker Software
Key Characteristics of High-Performing Insurance Broker Software
Insurance Tech Services
 
German Marketo User Group - May 2025 survey results
German Marketo User Group - May 2025 survey resultsGerman Marketo User Group - May 2025 survey results
German Marketo User Group - May 2025 survey results
BradBedford3
 
Agentic AI Desgin Principles in five slides.pptx
Agentic AI Desgin Principles in five slides.pptxAgentic AI Desgin Principles in five slides.pptx
Agentic AI Desgin Principles in five slides.pptx
MOSIUOA WESI
 
Frontier AI Regulation: What form should it take?
Frontier AI Regulation: What form should it take?Frontier AI Regulation: What form should it take?
Frontier AI Regulation: What form should it take?
Petar Radanliev
 
Web Application Development A Comprehensive Guide for 2025.pdf
Web Application Development A Comprehensive Guide for 2025.pdfWeb Application Development A Comprehensive Guide for 2025.pdf
Web Application Development A Comprehensive Guide for 2025.pdf
Secuodsoft
 
Salesforce Experience Cloud Consulting.pdf
Salesforce Experience Cloud Consulting.pdfSalesforce Experience Cloud Consulting.pdf
Salesforce Experience Cloud Consulting.pdf
VALiNTRY360
 
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdfBoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
Ortus Solutions, Corp
 
Portland Marketo User Group: MOPs & AI - Jeff Canada - May 2025
Portland Marketo User Group: MOPs & AI - Jeff Canada - May 2025Portland Marketo User Group: MOPs & AI - Jeff Canada - May 2025
Portland Marketo User Group: MOPs & AI - Jeff Canada - May 2025
BradBedford3
 
Best Practices Salesforce Training & Documentation.pptx
Best Practices Salesforce Training & Documentation.pptxBest Practices Salesforce Training & Documentation.pptx
Best Practices Salesforce Training & Documentation.pptx
Michael Orias
 
TUG Brazil - VizQL Data Service - Nik Dutra.pdf
TUG Brazil - VizQL Data Service - Nik Dutra.pdfTUG Brazil - VizQL Data Service - Nik Dutra.pdf
TUG Brazil - VizQL Data Service - Nik Dutra.pdf
Ligia Galvão
 
CFCamp2025 - Keynote Day 1 led by Luis Majano.pdf
CFCamp2025 - Keynote Day 1 led by Luis Majano.pdfCFCamp2025 - Keynote Day 1 led by Luis Majano.pdf
CFCamp2025 - Keynote Day 1 led by Luis Majano.pdf
Ortus Solutions, Corp
 
15 Years of Insights from a TDD Practitioner (NDC Oslo)
15 Years of Insights from a TDD Practitioner (NDC Oslo)15 Years of Insights from a TDD Practitioner (NDC Oslo)
15 Years of Insights from a TDD Practitioner (NDC Oslo)
Dennis Doomen
 
Shortcomings of EHS Software – And How to Overcome Them
Shortcomings of EHS Software – And How to Overcome ThemShortcomings of EHS Software – And How to Overcome Them
Shortcomings of EHS Software – And How to Overcome Them
TECH EHS Solution
 
20200823-Intro-to-FIRRTLllllllllllllllllll
20200823-Intro-to-FIRRTLllllllllllllllllll20200823-Intro-to-FIRRTLllllllllllllllllll
20200823-Intro-to-FIRRTLllllllllllllllllll
JonathanSong28
 
Lightworks PRO 2025.1 Crack Free Download
Lightworks PRO 2025.1 Crack Free DownloadLightworks PRO 2025.1 Crack Free Download
Lightworks PRO 2025.1 Crack Free Download
Berkeley
 
Skilling up your dev team - 8 things to consider when skilling-up your dev team
Skilling up your dev team - 8 things to consider when skilling-up your dev teamSkilling up your dev team - 8 things to consider when skilling-up your dev team
Skilling up your dev team - 8 things to consider when skilling-up your dev team
Derk-Jan de Grood
 
Introduction to QM, QA, QC, Bug's priority and severity
Introduction to QM, QA, QC, Bug's priority and severityIntroduction to QM, QA, QC, Bug's priority and severity
Introduction to QM, QA, QC, Bug's priority and severity
Arshad QA
 
Getting Started with BoxLang - CFCamp 2025.pdf
Getting Started with BoxLang - CFCamp 2025.pdfGetting Started with BoxLang - CFCamp 2025.pdf
Getting Started with BoxLang - CFCamp 2025.pdf
Ortus Solutions, Corp
 
Menu in Android (Define,Create,Inflate and Click Handler)
Menu in Android (Define,Create,Inflate and Click Handler)Menu in Android (Define,Create,Inflate and Click Handler)
Menu in Android (Define,Create,Inflate and Click Handler)
Nabin Dhakal
 
Advance Sales Commission Payments in Odoo
Advance Sales Commission Payments in OdooAdvance Sales Commission Payments in Odoo
Advance Sales Commission Payments in Odoo
AxisTechnolabs
 
Key Characteristics of High-Performing Insurance Broker Software
Key Characteristics of High-Performing Insurance Broker SoftwareKey Characteristics of High-Performing Insurance Broker Software
Key Characteristics of High-Performing Insurance Broker Software
Insurance Tech Services
 
German Marketo User Group - May 2025 survey results
German Marketo User Group - May 2025 survey resultsGerman Marketo User Group - May 2025 survey results
German Marketo User Group - May 2025 survey results
BradBedford3
 
Agentic AI Desgin Principles in five slides.pptx
Agentic AI Desgin Principles in five slides.pptxAgentic AI Desgin Principles in five slides.pptx
Agentic AI Desgin Principles in five slides.pptx
MOSIUOA WESI
 
Frontier AI Regulation: What form should it take?
Frontier AI Regulation: What form should it take?Frontier AI Regulation: What form should it take?
Frontier AI Regulation: What form should it take?
Petar Radanliev
 
Web Application Development A Comprehensive Guide for 2025.pdf
Web Application Development A Comprehensive Guide for 2025.pdfWeb Application Development A Comprehensive Guide for 2025.pdf
Web Application Development A Comprehensive Guide for 2025.pdf
Secuodsoft
 
Salesforce Experience Cloud Consulting.pdf
Salesforce Experience Cloud Consulting.pdfSalesforce Experience Cloud Consulting.pdf
Salesforce Experience Cloud Consulting.pdf
VALiNTRY360
 
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdfBoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
Ortus Solutions, Corp
 
Portland Marketo User Group: MOPs & AI - Jeff Canada - May 2025
Portland Marketo User Group: MOPs & AI - Jeff Canada - May 2025Portland Marketo User Group: MOPs & AI - Jeff Canada - May 2025
Portland Marketo User Group: MOPs & AI - Jeff Canada - May 2025
BradBedford3
 
Best Practices Salesforce Training & Documentation.pptx
Best Practices Salesforce Training & Documentation.pptxBest Practices Salesforce Training & Documentation.pptx
Best Practices Salesforce Training & Documentation.pptx
Michael Orias
 
TUG Brazil - VizQL Data Service - Nik Dutra.pdf
TUG Brazil - VizQL Data Service - Nik Dutra.pdfTUG Brazil - VizQL Data Service - Nik Dutra.pdf
TUG Brazil - VizQL Data Service - Nik Dutra.pdf
Ligia Galvão
 
CFCamp2025 - Keynote Day 1 led by Luis Majano.pdf
CFCamp2025 - Keynote Day 1 led by Luis Majano.pdfCFCamp2025 - Keynote Day 1 led by Luis Majano.pdf
CFCamp2025 - Keynote Day 1 led by Luis Majano.pdf
Ortus Solutions, Corp
 

Dpilot Source Code With ScreenShots

  • 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 = '[email protected]'; $mail->Password = 'Deep@21081998'; $mail->setFrom('[email protected]', '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.