diff --git a/server/homebrew.api.js b/server/homebrew.api.js index f20e97d4c..c8e4996cb 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -306,31 +306,6 @@ const api = { res.setHeader('Content-Type', 'application/json'); return res.status(200).send(returnObj); }, - //Return CSS for a brew theme, with @include endpoint for its parent theme if any - getBrewThemeCSS : async (req, res)=>{ - const brew = req.brew; - splitTextStyleAndMetadata(brew); - res.setHeader('Content-Type', 'text/css'); - let rendererPath = ''; - if(isStaticTheme(req.brew.renderer, req.brew.theme)) //Check if parent is staticBrew - rendererPath = `${_.upperFirst(req.brew.renderer)}/`; - - const parentThemeImport = `@import url(\"/css/${rendererPath}${req.brew.theme}\");\n\n`; - const themeLocationComment = `/* From Brew: ${req.protocol}://${req.get('host')}/share/${req.brew.shareId} */\n\n`; - return res.status(200).send(`${parentThemeImport}${themeLocationComment}${req.brew.style}`); - }, - //Return CSS for a static theme, with @include endpoint for its parent theme if any - getStaticThemeCSS : async(req, res)=>{ - if(!isStaticTheme(req.params.renderer, req.params.id)) - res.status(404).send(`Invalid Theme - Renderer: ${req.params.renderer}, Name: ${req.params.id}`); - else { - res.setHeader('Content-Type', 'text/css'); - res.setHeader('Cache-Control', 'public, max-age: 43200, must-revalidate'); - const themeParent = Themes[req.params.renderer][req.params.id].baseTheme; - const parentThemeImport = themeParent ? `@import url(\"/css/${req.params.renderer}/${themeParent}\");\n/* Static Theme ${Themes[req.params.renderer][themeParent].name} */\n` : ''; - return res.status(200).send(`${parentThemeImport}@import url(\"/themes/${req.params.renderer}/${req.params.id}/style.css\");\n/* Static Theme ${Themes[req.params.renderer][req.params.id].name} */\n`); - } - }, updateBrew : async (req, res)=>{ // Initialize brew from request and body, destructure query params, and set the initial value for the after-save method const brewFromClient = api.excludePropsFromUpdate(req.body); diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 90ee4dfa3..273900ee2 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -696,65 +696,6 @@ brew`); }); }); - describe('getBrewThemeWithStaticParent', ()=>{ - it('should collect parent theme and brew style - returning as css with static parent imported.', async ()=>{ - const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew })); - model.get = jest.fn(()=>toBrewPromise({ title: 'test brew', renderer: 'V3', theme: '5eDMG', shareId: 'iAmAUserTheme', style: 'I Have a style!' })); - const fn = api.getBrew('share', true); - const req = { brew: {}, get: ()=>{return 'localhost';}, protocol: 'https' }; - const next = jest.fn(); - await fn(req, null, next); - - api.getBrewThemeCSS(req, res); - const sent = res.send.mock.calls[0][0]; - expect(sent).toBe(`@import url("/css/V3/5eDMG");\n\n/* From Brew: https://localhost/share/iAmAUserTheme */\n\nI Have a style!`); - expect(res.status).toHaveBeenCalledWith(200); - }); - }); - - describe('getBrewThemeWithUserParent', ()=>{ - it('should collect parent theme and brew style - returning as css with user-theme parent imported.', async ()=>{ - const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew })); - model.get = jest.fn(()=>toBrewPromise({ title: 'test brew', renderer: 'V3', shareId: 'iAmAUserTheme', theme: 'IamATheme', style: 'I Have a style!' })); - const fn = api.getBrew('share', true); - const req = { brew: {}, get: ()=>{return 'localhost';}, protocol: 'https' }; - const next = jest.fn(); - await fn(req, null, next); - - api.getBrewThemeCSS(req, res); - const sent = res.send.mock.calls[0][0]; - expect(sent).toBe(`@import url("/css/IamATheme");\n\n/* From Brew: https://localhost/share/iAmAUserTheme */\n\nI Have a style!`); - expect(res.status).toHaveBeenCalledWith(200); - }); - }); - - describe('getStaticThemeCSS', ()=>{ - it('should return an import of the theme including a parent.', async ()=>{ - const req = { - params : { - renderer : 'V3', - id : '5eDMG' - } - }; - api.getStaticThemeCSS(req, res); - const sent = res.send.mock.calls[0][0]; - expect(sent).toBe('@import url("/css/V3/5ePHB");\n/* Static Theme 5e PHB */\n@import url("/themes/V3/5eDMG/style.css");\n/* Static Theme 5e DMG */\n'); - expect(res.status).toHaveBeenCalledWith(200); - }); - it('should fail for an invalid static theme.', async()=>{ - const req = { - params : { - renderer : 'V3', - id : '5eDMGGGG' - } - }; - api.getStaticThemeCSS(req, res); - const sent = res.send.mock.calls[0][0]; - expect(sent).toBe('Invalid Theme - Renderer: V3, Name: 5eDMGGGG'); - expect(res.status).toHaveBeenCalledWith(404); - }); - }); - describe('deleteBrew', ()=>{ it('should handle case where fetching the brew returns an error', async ()=>{ api.getBrew = jest.fn(()=>async ()=>{ throw { message: 'err', HBErrorCode: '02' }; });