mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-15 17:02:38 +00:00
Apply asyncHandler to getBrewFromId
This commit is contained in:
10
server.js
10
server.js
@@ -11,22 +11,20 @@ const sanitizeFilename = require('sanitize-filename');
|
|||||||
const asyncHandler = require('express-async-handler');
|
const asyncHandler = require('express-async-handler');
|
||||||
|
|
||||||
//Get the brew object from the HB database or Google Drive
|
//Get the brew object from the HB database or Google Drive
|
||||||
const getBrewFromId = async (id, accessType)=>{
|
const getBrewFromId = asyncHandler(async (id, accessType)=>{
|
||||||
if(accessType !== 'edit' && accessType !== 'share')
|
if(accessType !== 'edit' && accessType !== 'share')
|
||||||
throw ('Invalid Access Type when getting brew');
|
throw ('Invalid Access Type when getting brew');
|
||||||
let brew;
|
let brew;
|
||||||
if(id.length > 12) {
|
if(id.length > 12) {
|
||||||
const googleId = id.slice(0, -12);
|
const googleId = id.slice(0, -12);
|
||||||
id = id.slice(-12);
|
id = id.slice(-12);
|
||||||
brew = await GoogleActions.readFileMetadata(config.get('google_api_key'), googleId, id, accessType)
|
brew = await GoogleActions.readFileMetadata(config.get('google_api_key'), googleId, id, accessType);
|
||||||
.catch((err)=>{throw err;});
|
|
||||||
} else {
|
} else {
|
||||||
brew = await HomebrewModel.get(accessType == 'edit' ? { editId: id } : { shareId: id })
|
brew = await HomebrewModel.get(accessType == 'edit' ? { editId: id } : { shareId: id });
|
||||||
.catch((err)=>{throw err;});
|
|
||||||
brew.sanatize(true);
|
brew.sanatize(true);
|
||||||
}
|
}
|
||||||
return brew;
|
return brew;
|
||||||
};
|
});
|
||||||
|
|
||||||
app.use('/', serveCompressedStaticAssets(`${__dirname}/build`));
|
app.use('/', serveCompressedStaticAssets(`${__dirname}/build`));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user