Skip to content

Commit 88b140d

Browse files
committed
improvements
1 parent 5c71a8b commit 88b140d

18 files changed

+322
-9
lines changed

.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
"ecmaFeatures": {
1212
"experimentalObjectRestSpread": true
1313
}
14+
},
15+
"rules": {
16+
"no-console": "off"
1417
}
1518
}

db/development.sqlite

40 KB
Binary file not shown.

examples/squirrel.html

133 KB
Binary file not shown.

examples/squirrel.jpg

133 KB
Loading

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@
88
"dependencies": {
99
"bcrypt": "^1.0.3",
1010
"body-parser": "~1.17.1",
11+
"chalk": "^2.1.0",
12+
"commander": "^2.11.0",
1113
"connect-flash": "^0.1.1",
1214
"connect-sqlite3": "^0.9.10",
1315
"cookie-parser": "~1.4.3",
1416
"cookie-session": "^1.3.1",
1517
"cors": "^2.8.4",
1618
"debug": "~2.6.3",
19+
"dist-exiftool": "^10.53.0",
1720
"ejs": "~2.5.6",
1821
"ejs-mate": "^2.3.0",
1922
"express": "~4.15.2",
2023
"express-session": "^1.15.5",
2124
"faker": "^4.1.0",
25+
"helmet": "^3.8.1",
26+
"helmet-csp": "^2.5.1",
2227
"lodash": "^4.17.4",
2328
"morgan": "~1.8.1",
29+
"node-exiftool": "2.2.0",
2430
"nodemon": "^1.11.0",
2531
"sequelize": "^4.7.5",
2632
"serve-favicon": "~2.4.2",

public/images/squirrel.html

133 KB
Binary file not shown.

scripts/exif-read.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const chalk = require('chalk');
2+
const program = require('commander');
3+
const packageJson = require('../package.json');
4+
5+
const exiftool = require('node-exiftool')
6+
const exiftoolBin = require('dist-exiftool')
7+
const ep = new exiftool.ExiftoolProcess(exiftoolBin);
8+
9+
program
10+
.version(packageJson.version)
11+
.arguments('<image>', 'read exif comment data from an image')
12+
.action(function (image) {
13+
if (!image) {
14+
console.error(chalk.bgRed.white('No image specified'));
15+
program.help();
16+
process.exit(1);
17+
} else {
18+
extractExifData(image);
19+
}
20+
})
21+
.parse(process.argv);
22+
23+
function extractExifData(image) {
24+
ep
25+
.open()
26+
// .then((pid) => console.log('Started exiftool process %s', pid))
27+
.then(() => ep.readMetadata(image, ['comment']))
28+
.then((allExif) => {
29+
let [ { Comment: comment } ] = allExif.data;
30+
console.log(comment);
31+
}, (err) => {
32+
console.error(err);
33+
})
34+
.then(() => ep.close());
35+
// .then(() => console.log('Process has closed'));
36+
}

scripts/exif-write.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const chalk = require('chalk');
2+
const program = require('commander');
3+
const packageJson = require('../package.json');
4+
const fs = require('fs');
5+
const exiftool = require('node-exiftool')
6+
const exiftoolBin = require('dist-exiftool')
7+
const ep = new exiftool.ExiftoolProcess(exiftoolBin);
8+
9+
program
10+
.version(packageJson.version)
11+
.arguments('<image> <datafile>', 'read exif comment data from an image')
12+
.action(function (image, datafile) {
13+
let newMetaData = fs.readFileSync(datafile).toString();
14+
writeExifData(image, newMetaData);
15+
})
16+
.parse(process.argv);
17+
18+
19+
20+
function writeExifData(image, comment) {
21+
ep
22+
.open()
23+
// .then((pid) => console.log('Started exiftool process %s', pid))
24+
.then(() => ep.readMetadata(image, ['comment']))
25+
.then((allExif) => {
26+
let [ { Comment: comment } ] = allExif.data || {};
27+
console.log(chalk.yellow('------------- EXISTING DATA -------------'));
28+
console.log(comment);
29+
}, (err) => {
30+
console.error(err);
31+
process.exit(1);
32+
})
33+
.then(() => ep.writeMetadata(image, {
34+
all: '',
35+
comment
36+
}, ['overwrite_original']))
37+
.then(() => ep.readMetadata(image, ['comment']))
38+
.then((allExif) => {
39+
let [ { Comment: comment } ] = allExif.data || {};
40+
console.log(chalk.yellow('------------- UPDATED DATA -------------'));
41+
console.log(comment);
42+
}, (err) => {
43+
console.error(err);
44+
process.exit(1);
45+
})
46+
.then(() => ep.close())
47+
.catch(console.error)
48+
49+
}

scripts/exif.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const program = require('commander');
2+
const packageJson = require('../package.json');
3+
4+
program
5+
.version(packageJson.version)
6+
.command('read <image>', 'read exif comment data from an image')
7+
.command('write <image> <datafile>', 'update exif comment data in an image')
8+
.parse(process.argv);
9+
10+

server/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ app.use(session({
4646
saveUninitialized: true,
4747
resave: 'true',
4848
secret: 'secret'
49-
}))
49+
}));
50+
51+
app.use(function(req, res, next) {
52+
res.setHeader('X-Frame-Options', 'DENY');
53+
next();
54+
});
5055

5156
app.use(flashMiddleware);
5257
app.use(express.static(path.join(__dirname, '..', 'public')));

server/routes/transfers.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ router.get('/', function(req, res/*, next*/) {
3535
});
3636
});
3737

38-
router.post('/', function(req, res) {
38+
router.all('/perform', function(req, res) {
3939
bounceOutIfLoggedOut(req, res, () => {
40-
41-
let { accountFrom, accountTo, amount } = req.body;
40+
let { accountFrom, accountTo, amount } = Object.assign(Object.assign({}, req.body), req.query);
4241
amount = parseFloat(amount);
4342
if (!accountFrom || !accountTo) {
4443
errorAndReload(req, res, 'Must specify accounts to transfer from and to');

server/routes/user.js

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ router.get('/:username', function(req, res, next) {
88
bounceOutIfLoggedOut(req, res, () => {
99
Db.query("SELECT id, username, createdAt FROM users WHERE username = '" + username + "';").spread((results) => {
1010
res.render('user', {title: 'User', user: results[0] });
11+
})
12+
.catch(() => {
13+
req.session.sessionFlash = {
14+
type: 'danger',
15+
message: `No user found: ${username}`
16+
}
17+
res.redirect('/accounts');
1118
});
1219
});
1320
});

server/utils/auth.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function logout(req) {
1515

1616
function bounceOutIfLoggedOut(req, res, callback, fallbackPath = '/') {
1717
if (isAuthenticated(req)) {
18-
callback();
18+
return callback();
1919
} else {
2020
req.session.sessionFlash = {
2121
type: 'danger',

server/views/main-layout.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
<body>
1010
<%- body -%>
1111
</body>
12-
</html>
12+
</html>

server/views/navbar-layout.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="mui--appbar-height"></div>
77
<% if (sessionFlash) { %>
88
<div class='mui-panel alert alert-<%= sessionFlash.type %>'>
9-
<%= sessionFlash.message %>
9+
<%- sessionFlash.message %>
1010
</div>
1111
<% } %>
1212
<div class="mui-container">

server/views/transfers.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ul>
1212
<div class="mui-tabs__pane mui--is-active">
1313
<div class="spacer-t-20"></div>
14-
<form class="mui-form" action='/transfers' method='post'>
14+
<form class="mui-form" action='/transfers/perform' method='post'>
1515
<legend>Begin a Funds Transfer</legend>
1616
<div class="spacer-t-20"></div>
1717
<div class="mui-textfield">

tocopy.sql

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT * FROM courses
2+
WHERE owner = 'bholt'
3+
AND name = 'Complete Intro to React, v47' OR 'a'='a';

0 commit comments

Comments
 (0)