From 7894d9fbec50673d3e9666b0a6890ad1ff6b7368 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Fri, 11 Oct 2024 23:35:15 -0400 Subject: [PATCH] Update app.js --- server/app.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/server/app.js b/server/app.js index a84970e2a..4be0c84e9 100644 --- a/server/app.js +++ b/server/app.js @@ -8,6 +8,7 @@ const express = require('express'); const yaml = require('js-yaml'); const app = express(); const config = require('./config.js'); +const fs = require('fs-extra'); const { homebrewApi, getBrew, getUsersBrewThemes, getCSS } = require('./homebrew.api.js'); const GoogleActions = require('./googleActions.js'); @@ -204,6 +205,23 @@ app.get('/download/:id', asyncHandler(getBrew('share')), (req, res)=>{ res.status(200).send(brew.text); }); +//Serve brew metadata +app.get('/metadata/:id', asyncHandler(getBrew('share')), (req, res)=>{ + const { brew } = req; + sanitizeBrew(brew, 'share'); + + const fields = ['title', 'pageCount', 'description', 'authors', 'lang', + 'published', 'views', 'shareId', 'createdAt', 'updatedAt', + 'lastViewed', 'thumbnail', 'tags' + ]; + + const metadata = fields.reduce((acc, field)=>{ + if(brew[field] !== undefined) acc[field] = brew[field]; + return acc; + }, {}); + res.status(200).json(metadata); +}); + //Serve brew styling app.get('/css/:id', asyncHandler(getBrew('share')), (req, res)=>{getCSS(req, res);}); @@ -429,8 +447,16 @@ if(isLocalEnvironment){ }); } +// Add Static Local Paths +app.use('/staticImages', express.static(config.get('hb_images') && fs.existsSync(config.get('hb_images')) ? config.get('hb_images') :'staticImages')); +app.use('/staticFonts', express.static(config.get('hb_fonts') && fs.existsSync(config.get('hb_fonts')) ? config.get('hb_fonts'):'staticFonts')); + //Vault Page app.get('/vault', asyncHandler(async(req, res, next)=>{ + req.ogMeta = { ...defaultMetaTags, + title : 'The Vault', + description : 'Search for Brews' + }; return next(); }));