0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-29 11:12:39 +00:00

Separate "style" and "metadata" panels

This commit is contained in:
Trevor Buckner
2021-06-05 15:58:31 -04:00
parent 1bc0964aff
commit e67fadef02
15 changed files with 340 additions and 219 deletions

View File

@@ -19,14 +19,24 @@ const getGoodBrewTitle = (text)=>{
.slice(0, MAX_TITLE_LENGTH);
};
const mergeBrewText = (text, style)=>{
text = `\`\`\`css\n` +
`${style}\n` +
`\`\`\`\n\n` +
`${text}`;
return text;
};
const newBrew = (req, res)=>{
const brew = req.body;
brew.authors = (req.account) ? [req.account.username] : [];
if(!brew.title) {
brew.title = getGoodBrewTitle(brew.text);
}
brew.authors = (req.account) ? [req.account.username] : [];
brew.text = mergeBrewText(brew.text, brew.style);
delete brew.editId;
delete brew.shareId;
delete brew.googleId;
@@ -53,8 +63,10 @@ const updateBrew = (req, res)=>{
HomebrewModel.get({ editId: req.params.id })
.then((brew)=>{
brew = _.merge(brew, req.body);
brew.text = mergeBrewText(brew.text, brew.style);
// Compress brew text to binary before saving
brew.textBin = zlib.deflateRawSync(req.body.text);
brew.textBin = zlib.deflateRawSync(brew.text);
// Delete the non-binary text field since it's not needed anymore
brew.text = undefined;
brew.updatedAt = new Date();
@@ -113,12 +125,14 @@ const newGoogleBrew = async (req, res, next)=>{
try { oAuth2Client = GoogleActions.authCheck(req.account, res); } catch (err) { return res.status(err.status).send(err.message); }
const brew = req.body;
brew.authors = (req.account) ? [req.account.username] : [];
if(!brew.title) {
brew.title = getGoodBrewTitle(brew.text);
}
brew.authors = (req.account) ? [req.account.username] : [];
brew.text = mergeBrewText(brew.text, brew.style);
delete brew.editId;
delete brew.shareId;
delete brew.googleId;
@@ -135,7 +149,10 @@ const updateGoogleBrew = async (req, res, next)=>{
try { oAuth2Client = GoogleActions.authCheck(req.account, res); } catch (err) { return res.status(err.status).send(err.message); }
const updatedBrew = await GoogleActions.updateGoogleBrew(oAuth2Client, req.body);
const brew = req.body;
brew.text = mergeBrewText(brew.text, brew.style);
const updatedBrew = await GoogleActions.updateGoogleBrew(oAuth2Client, brew);
return res.status(200).send(updatedBrew);
};