Skip to content

Image uploader for items #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ module.exports = {
"no-console": 0,
"array-callback-return": 0,
"consistent-return": 0,
"no-return-assign": 0,
"no-param-reassign": 0
}
}
49 changes: 45 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,49 @@ const { loadDatabase, searchDatabase } = require('./googleSpreadsheet');

const app = express();

const keys = require('./config/keys');

// Image uploader
const aws = require('aws-sdk');
const bodyParser = require('body-parser');
const multer = require('multer');
const multerS3 = require('multer-s3');

aws.config.update({
secretAccessKey: keys.secretAccessKey,
accessKeyId: keys.accessKeyId,
region: 'us-east-2',
});

const s3 = new aws.S3();

app.use(bodyParser.json());

const upload = multer({
storage: multerS3({
s3,
bucket: 'inventory-server-images',
key(req, file, cb) {
console.log(file);
cb(null, `${req.params.uuid}.jpg`);
},
}),
});


const recentScans = {
assigned: [],
unassigned: [],
};

const date = new Date();
const minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
const hour = date.getHours();
const dayOfWeek = date.getDay();
const week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
const scanTime = `${week[dayOfWeek]} ${hour}:${minutes}`;


app.set('view engine', 'ejs');

app.use(express.static(`${__dirname}/public`));
Expand All @@ -19,6 +57,10 @@ app.get('/favicon.ico', (req, res) => {
res.status(204);
});

app.post('/:uuid', upload.single('upl'), (req, res) => {
res.redirect(req.params.uuid);
});

app.get('/search', (req, res) => {
loadDatabase((allItems) => {
res.render('search', {
Expand All @@ -34,7 +76,7 @@ app.get('/qrlist', (req, res) => {
.filter(item => item.uuid !== '')
.filter(item => item.uuid !== undefined)
.sort((a, b) => (a.floor === b.floor ? 0 : +(a.floor > b.floor) || -1));
qrList.forEach(item => item.qr = qr.imageSync('http://url.coderbunker.com/' + item.uuid, { type: 'svg' }));
qrList.forEach(item => item.qr = qr.imageSync(`http://url.coderbunker.com/${item.uuid}`, { type: 'svg' }));
res.render('qrList', { matches: qrList });
});
});
Expand All @@ -47,15 +89,14 @@ app.get('/:uuid', (req, res) => {
loadDatabase((allItems) => {
const matches = searchDatabase(req.params, allItems);
if (matches.length === 0) {
recentScans.unassigned.push(req.params.uuid);
recentScans.unassigned.push([scanTime, req.params.uuid]);
res.render('notFound', {
item: '',
id: req.params.uuid,
});
return;
}
recentScans.assigned.push([matches[0].fixture, req.params.uuid]);
// console.log(recentScans);
recentScans.assigned.push([scanTime, matches[0].fixture, req.params.uuid]);
matches.similarItems = searchDatabase({ fixture: matches[0].fixture }, allItems)
.filter(item => item.uuid !== matches[0].uuid)
.splice(0, 3);
Expand Down
4 changes: 3 additions & 1 deletion config/keys.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module.exports = {
apiKey: 'AIzaSyAWtz7gpnbuLlsHI2benyDaUfiKlB-1aqo'
apiKey: 'AIzaSyAWtz7gpnbuLlsHI2benyDaUfiKlB-1aqo',
secretAccessKey: 'iFQiKdjAlTxz+eDRyHmruV+Ii3brutNx7E2whtUr',
accessKeyId: 'AKIAI2SCE7QGHLHDUXQQ',
};
Loading