mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-01 13:02:43 +00:00
Merge branch 'master' into pr/1198
This commit is contained in:
@@ -157,6 +157,7 @@ GoogleActions = {
|
||||
lastViewed : brew.lastViewed,
|
||||
views : brew.views,
|
||||
version : brew.version,
|
||||
renderer : brew.renderer,
|
||||
tags : brew.tags,
|
||||
systems : brew.systems.join() }
|
||||
},
|
||||
@@ -230,6 +231,7 @@ GoogleActions = {
|
||||
description : brew.description,
|
||||
tags : '',
|
||||
published : brew.published,
|
||||
renderer : brew.renderer,
|
||||
authors : [],
|
||||
systems : []
|
||||
};
|
||||
@@ -296,6 +298,7 @@ GoogleActions = {
|
||||
lastViewed : obj.data.properties.lastViewed,
|
||||
views : parseInt(obj.data.properties.views) || 0, //brews with no view parameter will return undefined
|
||||
version : parseInt(obj.data.properties.version) || 0,
|
||||
renderer : obj.data.properties.renderer ? obj.data.properties.renderer : 'legacy',
|
||||
|
||||
gDrive : true,
|
||||
googleId : id
|
||||
|
||||
@@ -3,6 +3,7 @@ const HomebrewModel = require('./homebrew.model.js').model;
|
||||
const router = require('express').Router();
|
||||
const zlib = require('zlib');
|
||||
const GoogleActions = require('./googleActions.js');
|
||||
const Markdown = require('../shared/naturalcrit/markdown.js');
|
||||
|
||||
// const getTopBrews = (cb) => {
|
||||
// HomebrewModel.find().sort({ views: -1 }).limit(5).exec(function(err, brews) {
|
||||
@@ -10,14 +11,12 @@ const GoogleActions = require('./googleActions.js');
|
||||
// });
|
||||
// };
|
||||
|
||||
const MAX_TITLE_LENGTH = 100;
|
||||
|
||||
const getGoodBrewTitle = (text)=>{
|
||||
const titlePos = text.indexOf('# ');
|
||||
if(titlePos !== -1) {
|
||||
const ending = text.indexOf('\n', titlePos);
|
||||
return text.substring(titlePos + 2, ending);
|
||||
} else {
|
||||
return _.find(text.split('\n'), (line)=>line);
|
||||
}
|
||||
const tokens = Markdown.marked.lexer(text);
|
||||
return (tokens.find((token)=>token.type == 'heading' || token.type == 'paragraph')?.text || 'No Title')
|
||||
.slice(0, MAX_TITLE_LENGTH);
|
||||
};
|
||||
|
||||
const newBrew = (req, res)=>{
|
||||
@@ -126,8 +125,6 @@ const newGoogleBrew = async (req, res, next)=>{
|
||||
|
||||
req.body = brew;
|
||||
|
||||
console.log(oAuth2Client);
|
||||
|
||||
const newBrew = await GoogleActions.newGoogleBrew(oAuth2Client, brew);
|
||||
|
||||
return res.status(200).send(newBrew);
|
||||
|
||||
@@ -13,6 +13,7 @@ const HomebrewSchema = mongoose.Schema({
|
||||
description : { type: String, default: '' },
|
||||
tags : { type: String, default: '' },
|
||||
systems : [String],
|
||||
renderer : { type: String, default: '' },
|
||||
authors : [String],
|
||||
published : { type: Boolean, default: false },
|
||||
|
||||
@@ -55,6 +56,8 @@ HomebrewSchema.statics.get = function(query){
|
||||
unzipped = zlib.inflateRawSync(brews[0].textBin);
|
||||
brews[0].text = unzipped.toString();
|
||||
}
|
||||
if(!brews[0].renderer)
|
||||
brews[0].renderer = 'legacy';
|
||||
return resolve(brews[0]);
|
||||
});
|
||||
});
|
||||
|
||||
31
server/static-assets.mv.js
Normal file
31
server/static-assets.mv.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const expressStaticGzip = require('express-static-gzip');
|
||||
|
||||
// Serve brotli-compressed static files if available
|
||||
const customCacheControlHandler=(response, path)=>{
|
||||
if(path.endsWith('.br')) {
|
||||
// Drop .br suffix to help mime understand the actual type of the file
|
||||
path = path.slice(0, -3);
|
||||
}
|
||||
if(path.endsWith('.js') || path.endsWith('.css')) {
|
||||
// .js and .css files are allowed to be cached up to 12 hours, but then
|
||||
// they must be revalidated to see if there are any updates
|
||||
response.setHeader('Cache-Control', 'public, max-age: 43200, must-revalidate');
|
||||
} else {
|
||||
// Everything else is cached up to a months as we don't update our images
|
||||
// or fonts frequently
|
||||
response.setHeader('Cache-Control', 'public, max-age=2592000, must-revalidate');
|
||||
}
|
||||
};
|
||||
|
||||
const init=(pathToAssets)=>{
|
||||
return expressStaticGzip(pathToAssets, {
|
||||
enableBrotli : true,
|
||||
orderPreference : ['br'],
|
||||
index : false,
|
||||
serveStatic : {
|
||||
cacheControl : false, // we are going to use custom cache-control
|
||||
setHeaders : customCacheControlHandler
|
||||
} });
|
||||
};
|
||||
|
||||
module.exports = init;
|
||||
Reference in New Issue
Block a user