From 802849ee393a7ff7773d32404c786aec1b8ab441 Mon Sep 17 00:00:00 2001 From: Bolu123-sudo Date: Fri, 3 Oct 2025 17:47:55 -0400 Subject: [PATCH 1/2] FontSize, width, height query parameters for SVG generation (Fixes #334) --- src/api/controllers/quotesController.js | 11 ++++- src/api/services/quotesService.js | 6 ++- src/common/getTemplate.js | 64 ++++++++++++++----------- src/models/Template.js | 18 ++++++- 4 files changed, 68 insertions(+), 31 deletions(-) diff --git a/src/api/controllers/quotesController.js b/src/api/controllers/quotesController.js index 8e0e32b..83f5e0f 100644 --- a/src/api/controllers/quotesController.js +++ b/src/api/controllers/quotesController.js @@ -38,6 +38,12 @@ const quoteController = async (req, res, next) => { let quoteType = req.query.quoteType || ''; let unsplashQuery = req.query.unsplashQuery || ''; + // (Issue #334) + const toNum = (v) => (v !== undefined && v !== '' && !Number.isNaN(Number(v))) ? Number(v) : undefined; + const fontSize = toNum(req.query.fontSize); + const width = toNum(req.query.width); + const height = toNum(req.query.height); + let quoteObject = { theme, animation, @@ -48,7 +54,10 @@ const quoteController = async (req, res, next) => { quoteType, borderColor, bgSource, - unsplashQuery + unsplashQuery, + fontSize, + width, + height } let svgResponse = await quoteService.getQuote(quoteObject); diff --git a/src/api/services/quotesService.js b/src/api/services/quotesService.js index 6969190..0b3be87 100644 --- a/src/api/services/quotesService.js +++ b/src/api/services/quotesService.js @@ -15,7 +15,7 @@ getQuoteIndex = (apiResponseLength, quoteType) => { const getQuote = async (quoteObj) => { try { - let { theme, animation, layout, quotesUrl, quoteCategory, font, quoteType, borderColor, bgSource, unsplashQuery } = quoteObj; + let { theme, animation, layout, quotesUrl, quoteCategory, font, quoteType, borderColor, bgSource, unsplashQuery,fontSize, width,height } = quoteObj; let apiResponse; let { customQuotesUrl, isValidUrl } = await getValidUrl(quotesUrl); let isCustomQuote = false; @@ -58,6 +58,10 @@ const getQuote = async (quoteObj) => { template.setLayout(layout); template.bgImage = bgImageUrl; + if (Number.isFinite(fontSize)) template.fontSize = Number(fontSize); + if (Number.isFinite(width)) template.width = Number(width); + if (Number.isFinite(height)) template.height = Number(height); + let svg = cardTemplate.generateTemplate(template); return svg; } catch (error) { diff --git a/src/common/getTemplate.js b/src/common/getTemplate.js index 4917339..e84f3be 100644 --- a/src/common/getTemplate.js +++ b/src/common/getTemplate.js @@ -1,35 +1,43 @@ const getTemplate = (template) => { - const escapeHtml = require('escape-html'); - const safeUrl = escapeHtml(template.bgImage); - const backgroundImageLayer = safeUrl - ? `` - : ''; + : ''; - return ` - - - - - ${backgroundImageLayer} - -
- - ${template.structure} -
-
+ return ` + + + + + ${backgroundImageLayer} + +
+ + ${template.structure} +
+
`; }; diff --git a/src/models/Template.js b/src/models/Template.js index 4a47e47..00591d6 100644 --- a/src/models/Template.js +++ b/src/models/Template.js @@ -1,12 +1,17 @@ const layouts = require("../layouts/layout"); class Template { - constructor() {} + constructor() { + this.width = 500; + this.height = 200; + this.fontSize = 16;} setTheme(theme) { this.theme = theme; } + + setData(data) { this.quote = data.quote; this.author = data.author; @@ -38,6 +43,17 @@ class Template { setFont(font){ this.font = font; } + setFontSize(size) { + this.fontSize = size; + } + + setWidth(width) { + this.width = width; + } + + setHeight(height) { + this.height = height; + } calculateHeight(length) { let lines; From e245415373d548777d4219c4703ba6402a6fd7f8 Mon Sep 17 00:00:00 2001 From: Bolu123-sudo Date: Fri, 3 Oct 2025 17:48:01 -0400 Subject: [PATCH 2/2] FontSize, width, height query parameters for SVG generation (Fixes #334) --- .idea/.gitignore | 8 + .idea/editor.xml | 483 +++++++++++++++++++++++++++++++++ .idea/github-readme-quotes.iml | 8 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + 5 files changed, 513 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/editor.xml create mode 100644 .idea/github-readme-quotes.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 0000000..55d1bc1 --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,483 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/github-readme-quotes.iml b/.idea/github-readme-quotes.iml new file mode 100644 index 0000000..bc2cd87 --- /dev/null +++ b/.idea/github-readme-quotes.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..881fd60 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file