Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
revert commas, rmv log
Browse files Browse the repository at this point in the history
  • Loading branch information
clif-os committed Sep 3, 2020
1 parent 2305c71 commit b4a1e4c
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const makeFileLocation = (file) => `${config.AWS_BUCKET_URL}/${file.Key}`;
const s3 = new AWS.S3({
accessKeyId: config.AWS_ACCESS_KEY_ID,
secretAccessKey: config.AWS_SECRET_ACCESS_KEY,
region: config.AWS_REGION,
region: config.AWS_REGION
});

const auth = basicAuth({
users: {
[config.AUTH_USERNAME]: config.AUTH_PASSWORD,
},
[config.AUTH_USERNAME]: config.AUTH_PASSWORD
}
});

const app = express();
Expand All @@ -39,7 +39,7 @@ const storage = multer.diskStorage({
filename = `${Date.now()}.webm`;
}
cb(null, filename);
},
}
});

const upload = multer({ storage });
Expand All @@ -50,7 +50,7 @@ const listGifs = async () => {
try {
const params = {
Bucket: config.AWS_BUCKET_NAME,
Prefix: GREETING_PREFIX,
Prefix: GREETING_PREFIX
};

const getAllContents = async (PrevContents = [], NextContinuationToken) => {
Expand All @@ -59,7 +59,7 @@ const listGifs = async () => {
...params,
...(NextContinuationToken
? { ContinuationToken: NextContinuationToken }
: {}),
: {})
})
.promise();
const Contents = [...PrevContents, ...result.Contents];
Expand All @@ -72,7 +72,7 @@ const listGifs = async () => {

const OrderedContents = Contents.map((file) => ({
...file,
Location: makeFileLocation(file),
Location: makeFileLocation(file)
})).reverse();

return OrderedContents;
Expand All @@ -91,12 +91,12 @@ const groupPhotoPath = 'public/group_photo.jpeg';
app.post('/getGroupPhoto', async (_, res) => {
const params = {
Bucket: config.AWS_BUCKET_NAME,
Prefix: groupPhotoPath,
Prefix: groupPhotoPath
};
const result = await s3.listObjects(params).promise();
result.Contents = result.Contents.map((file) => ({
...file,
Location: makeFileLocation(file),
Location: makeFileLocation(file)
}));
res.send(result);
});
Expand All @@ -111,15 +111,14 @@ app.post('/createGroupPhoto', async (_, res) => {
Bucket: config.AWS_BUCKET_NAME,
Body: stream,
ContentType: 'image/png',
ACL: 'public-read',
ACL: 'public-read'
};
s3.upload(params, (err, data) => {
if (err) {
console.log(err, err.stack);
} else {
console.log(`Group Photo Uploaded to s3: ${groupPhotoPath}`);
data.LastModified = Date.now();
console.log(data)
res.send(data);
}
});
Expand All @@ -137,7 +136,7 @@ const uploadGIF = async (res, filename, folderName, onSuccess) => {
Bucket: config.AWS_BUCKET_NAME,
Body: fileStream,
ContentType: 'image/gif',
ACL: 'public-read',
ACL: 'public-read'
};

await s3
Expand All @@ -160,7 +159,7 @@ app.post('/uploadUserGIF', upload.single('gif'), async (req, res) => {
if (!gif) {
res.status(400).send({
status: false,
data: 'No file is selected.',
data: 'No file is selected.'
});
} else {
const filename = gif.filename.replace('.gif', '');
Expand All @@ -172,10 +171,10 @@ app.post('/uploadGIF', ({ body }, res) => {
const { filename } = body;
uploadGIF(res, filename, 'temp', () => {
fs.unlink(`uploads/${filename}.webm`, () =>
console.log('.webm file was deleted'),
console.log('.webm file was deleted')
);
fs.unlink(`uploads/${filename}.png`, () =>
console.log('.png file was deleted'),
console.log('.png file was deleted')
);
});
});
Expand All @@ -199,10 +198,10 @@ app.post('/video2gif', upload.none(), ({ body }, res) => {
y: '(h-text_h)*.95',
shadowcolor: 'black',
shadowx: 2,
shadowy: 2,
shadowy: 2
},
inputs: 'c',
},
inputs: 'c'
}
])
.on('end', () => {
res.send(body);
Expand All @@ -220,7 +219,7 @@ app.post('/uploadBlob', upload.single('video'), ({ file }, res) => {
.screenshots({
timestamps: [0],
filename,
size: '320x240',
size: '320x240'
})
.on('end', () => {
res.send(file);
Expand All @@ -235,7 +234,7 @@ app.get('/img', (req, res) => {
const ext = filename.split('/').pop();
const head = {
'Content-Length': fileSize,
'Content-Type': `image/${ext}`,
'Content-Type': `image/${ext}`
};
res.writeHead(200, head);
fs.createReadStream(path).pipe(res);
Expand All @@ -254,7 +253,7 @@ app.get('/s3-download', async (req, res) => {
const { filename } = req.query;
const params = {
Bucket: config.AWS_BUCKET_NAME,
Key: filename,
Key: filename
};
s3.getObject(params, (err, data) => {
if (err) console.log(err, err.stack);
Expand All @@ -268,7 +267,7 @@ app.delete('/deleteObj', auth, ({ body }, res) => {
const { filename } = body;
const params = {
Bucket: config.AWS_BUCKET_NAME,
Key: filename,
Key: filename
};
s3.deleteObject(params, (err, data) => {
if (err) console.log(err, err.stack);
Expand All @@ -278,7 +277,7 @@ app.delete('/deleteObj', auth, ({ body }, res) => {

app.use(express.static(path.join(__dirname, '../client/build')));
app.get('/*', (req, res) =>
res.sendFile(path.join(__dirname, '../client/build', 'index.html')),
res.sendFile(path.join(__dirname, '../client/build', 'index.html'))
);

app.listen(app.get('port'), () => {
Expand Down

0 comments on commit b4a1e4c

Please sign in to comment.