mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 15:42:39 +00:00
Merge branch 'master' into api-tests
This commit is contained in:
@@ -67,7 +67,8 @@ const NewPage = createClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
localStorage.setItem(BREWKEY, brew.text);
|
localStorage.setItem(BREWKEY, brew.text);
|
||||||
localStorage.setItem(STYLEKEY, brew.style);
|
if(brew.style)
|
||||||
|
localStorage.setItem(STYLEKEY, brew.style);
|
||||||
localStorage.setItem(METAKEY, JSON.stringify({ 'renderer': brew.renderer, 'theme': brew.theme }));
|
localStorage.setItem(METAKEY, JSON.stringify({ 'renderer': brew.renderer, 'theme': brew.theme }));
|
||||||
},
|
},
|
||||||
componentWillUnmount : function() {
|
componentWillUnmount : function() {
|
||||||
|
|||||||
@@ -29,9 +29,10 @@ const PrintPage = createClass({
|
|||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
return {
|
||||||
brew : {
|
brew : {
|
||||||
text : this.props.brew.text || '',
|
text : this.props.brew.text || '',
|
||||||
style : this.props.brew.style || undefined,
|
style : this.props.brew.style || undefined,
|
||||||
renderer : this.props.brew.renderer || 'legacy'
|
renderer : this.props.brew.renderer || 'legacy',
|
||||||
|
theme : this.props.brew.theme || '5ePHB'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -48,7 +49,7 @@ const PrintPage = createClass({
|
|||||||
text : brewStorage,
|
text : brewStorage,
|
||||||
style : styleStorage,
|
style : styleStorage,
|
||||||
renderer : metaStorage?.renderer || 'legacy',
|
renderer : metaStorage?.renderer || 'legacy',
|
||||||
theme : metaStorage?.theme || '5ePHB'
|
theme : metaStorage?.theme || '5ePHB'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -407,7 +407,7 @@ if(isLocalEnvironment){
|
|||||||
//Render the page
|
//Render the page
|
||||||
const templateFn = require('./../client/template.js');
|
const templateFn = require('./../client/template.js');
|
||||||
app.use(asyncHandler(async (req, res, next)=>{
|
app.use(asyncHandler(async (req, res, next)=>{
|
||||||
const brew = _.defaults(req.brew, DEFAULT_BREW);
|
|
||||||
// Create configuration object
|
// Create configuration object
|
||||||
const configuration = {
|
const configuration = {
|
||||||
local : isLocalEnvironment,
|
local : isLocalEnvironment,
|
||||||
@@ -417,7 +417,7 @@ app.use(asyncHandler(async (req, res, next)=>{
|
|||||||
const props = {
|
const props = {
|
||||||
version : require('./../package.json').version,
|
version : require('./../package.json').version,
|
||||||
url : req.originalUrl,
|
url : req.originalUrl,
|
||||||
brew : brew,
|
brew : req.brew,
|
||||||
brews : req.brews,
|
brews : req.brews,
|
||||||
googleBrews : req.googleBrews,
|
googleBrews : req.googleBrews,
|
||||||
account : req.account,
|
account : req.account,
|
||||||
|
|||||||
@@ -1,30 +1,36 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
// Default brew properties in most cases
|
// Default properties for newly-created brews
|
||||||
const DEFAULT_BREW = {
|
const DEFAULT_BREW = {
|
||||||
|
title : '',
|
||||||
text : '',
|
text : '',
|
||||||
editId : null,
|
style : undefined,
|
||||||
shareId : null,
|
|
||||||
title : 'Untitled Brew',
|
|
||||||
description : '',
|
description : '',
|
||||||
|
editId : undefined,
|
||||||
|
shareId : undefined,
|
||||||
|
createdAt : undefined,
|
||||||
|
updatedAt : undefined,
|
||||||
renderer : 'V3',
|
renderer : 'V3',
|
||||||
|
theme : '5ePHB',
|
||||||
|
authors : [],
|
||||||
tags : [],
|
tags : [],
|
||||||
systems : [],
|
systems : [],
|
||||||
thumbnail : '',
|
thumbnail : '',
|
||||||
published : false,
|
published : false,
|
||||||
pageCount : 1,
|
pageCount : 1,
|
||||||
theme : '5ePHB'
|
gDrive : false,
|
||||||
|
trashed : false
|
||||||
|
|
||||||
};
|
};
|
||||||
// Default brew properties for loading
|
// Default values for older brews with missing properties
|
||||||
const DEFAULT_BREW_LOAD = {};
|
// e.g., missing "renderer" is assumed to be "legacy"
|
||||||
_.defaults(DEFAULT_BREW_LOAD,
|
const DEFAULT_BREW_LOAD = _.defaults(
|
||||||
{
|
{
|
||||||
renderer : 'legacy',
|
renderer : 'legacy',
|
||||||
published : true
|
|
||||||
},
|
},
|
||||||
DEFAULT_BREW);
|
DEFAULT_BREW);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
DEFAULT_BREW,
|
DEFAULT_BREW,
|
||||||
DEFAULT_BREW_LOAD
|
DEFAULT_BREW_LOAD
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -76,17 +76,12 @@ If you believe you should have access to this brew, ask the file owner to invite
|
|||||||
throw 'Brew not found in Homebrewery database or Google Drive';
|
throw 'Brew not found in Homebrewery database or Google Drive';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof stub?.tags === 'string') {
|
// Clean up brew: fill in missing fields with defaults / fix old invalid values
|
||||||
stub.tags = [];
|
stub.tags = stub.tags || undefined; // Clear empty strings
|
||||||
}
|
stub.renderer = stub.renderer || undefined; // Clear empty strings
|
||||||
|
stub = _.defaults(stub, DEFAULT_BREW_LOAD); // Fill in blank fields
|
||||||
|
|
||||||
// Use _.assignWith instead of _.defaults - does this need to be replicated at all other uses of _.defaults???
|
|
||||||
_.assignWith(stub, DEFAULT_BREW_LOAD, (objValue, srcValue)=>{
|
|
||||||
if(typeof objValue === 'boolean') return objValue;
|
|
||||||
return objValue || srcValue;
|
|
||||||
});
|
|
||||||
req.brew = stub;
|
req.brew = stub;
|
||||||
|
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user