From f076e05f49f6e9bd74f2ad78990726b0a036d37c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 18 Mar 2025 19:46:11 +0100 Subject: [PATCH] js files --- .../editor/metadataEditor/validations.js | 12 ++++---- .../pages/errorPage/errors/errorIndex.js | 2 +- scripts/buildHomebrew.js | 8 +++--- server/admin.api.spec.js | 16 +++++------ server/app.js | 1 - server/googleActions.js | 16 +++++------ server/homebrew.api.js | 5 ++-- server/homebrew.model.js | 2 +- shared/naturalcrit/markdown.js | 28 +++++++++---------- tests/markdown/basic.test.js | 2 +- tests/markdown/non-breaking-spaces.test.js | 2 +- .../markdown/paragraph-justification.test.js | 2 +- themes/V3/5eDMG/snippets.js | 2 +- themes/V3/Journal/snippets.js | 2 +- themes/fonts/iconFonts/fontAwesome.js | 2 ++ 15 files changed, 52 insertions(+), 50 deletions(-) diff --git a/client/homebrew/editor/metadataEditor/validations.js b/client/homebrew/editor/metadataEditor/validations.js index b475783a4..858fca6c4 100644 --- a/client/homebrew/editor/metadataEditor/validations.js +++ b/client/homebrew/editor/metadataEditor/validations.js @@ -28,18 +28,18 @@ module.exports = { return new RegExp(/^([a-zA-Z]{2,3})(-[a-zA-Z]{4})?(-(?:[0-9]{3}|[a-zA-Z]{2}))?$/).test(value) === false && (value.length > 0) ? 'Invalid language code.' : null; } ], - theme: [ - (value) => { + theme : [ + (value)=>{ const URL = global.config.baseUrl.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); //Escape any regex characters const shareIDPattern = '[a-zA-Z0-9-_]{12}'; const shareURLRegex = new RegExp(`^${URL}\\/share\\/${shareIDPattern}$`); const shareIDRegex = new RegExp(`^${shareIDPattern}$`); - if (value?.length === 0) return null; - if (shareURLRegex.test(value)) return null; - if (shareIDRegex.test(value)) return null; + if(value?.length === 0) return null; + if(shareURLRegex.test(value)) return null; + if(shareIDRegex.test(value)) return null; return 'Must be a valid Share URL or a 12-character ID.'; - } + } ] }; diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index c2c49f958..9584a14b9 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -167,7 +167,7 @@ const errorIndex = (props)=>{ **Requested access:** ${props.brew.accessType} **Brew ID:** ${props.brew.brewId}`, - + // Theme Not Valid '10' : dedent` ## The selected theme is not tagged as a theme. diff --git a/scripts/buildHomebrew.js b/scripts/buildHomebrew.js index 656714d87..4d55a4176 100644 --- a/scripts/buildHomebrew.js +++ b/scripts/buildHomebrew.js @@ -10,7 +10,7 @@ import babel from '@babel/core'; import babelConfig from '../babel.config.json' with { type : 'json' }; import less from 'less'; -const isDev = !!process.argv.find((arg) => arg === '--dev'); +const isDev = !!process.argv.find((arg)=>arg === '--dev'); const babelify = async (code)=>(await babel.transformAsync(code, babelConfig)).code; @@ -53,7 +53,7 @@ fs.emptyDirSync('./build'); const themes = { Legacy: {}, V3: {} }; let themeFiles = fs.readdirSync('./themes/Legacy'); - for (let dir of themeFiles) { + for (const dir of themeFiles) { const themeData = JSON.parse(fs.readFileSync(`./themes/Legacy/${dir}/settings.json`).toString()); themeData.path = dir; themes.Legacy[dir] = (themeData); @@ -70,7 +70,7 @@ fs.emptyDirSync('./build'); } themeFiles = fs.readdirSync('./themes/V3'); - for (let dir of themeFiles) { + for (const dir of themeFiles) { const themeData = JSON.parse(fs.readFileSync(`./themes/V3/${dir}/settings.json`).toString()); themeData.path = dir; themes.V3[dir] = (themeData); @@ -113,7 +113,7 @@ fs.emptyDirSync('./build'); const stream = fs.createWriteStream(editorThemeFile, { flags: 'a' }); stream.write('[\n"default"'); - for (let themeFile of editorThemeFiles) { + for (const themeFile of editorThemeFiles) { stream.write(`,\n"${themeFile.slice(0, -4)}"`); } stream.write('\n]\n'); diff --git a/server/admin.api.spec.js b/server/admin.api.spec.js index 6a23393b1..036c238c9 100644 --- a/server/admin.api.spec.js +++ b/server/admin.api.spec.js @@ -1,6 +1,6 @@ import supertest from 'supertest'; import HBApp from './app.js'; -import {model as NotificationModel } from './notifications.model.js'; +import { model as NotificationModel } from './notifications.model.js'; // Mimic https responses to avoid being redirected all the time @@ -16,7 +16,7 @@ describe('Tests for admin api', ()=>{ const testNotifications = ['a', 'b']; jest.spyOn(NotificationModel, 'find') - .mockImplementationOnce(() => { + .mockImplementationOnce(()=>{ return { exec: jest.fn().mockResolvedValue(testNotifications) }; }); @@ -59,7 +59,7 @@ describe('Tests for admin api', ()=>{ expect(response.body).toEqual(savedNotification); }); - it('should handle error adding a notification without dismissKey', async () => { + it('should handle error adding a notification without dismissKey', async ()=>{ const inputNotification = { title : 'Test Notification', text : 'This is a test notification', @@ -75,7 +75,7 @@ describe('Tests for admin api', ()=>{ const response = await app .post('/admin/notification/add') - .set('Authorization', 'Basic ' + Buffer.from('admin:password3').toString('base64')) + .set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`) .send(inputNotification); expect(response.status).toBe(500); @@ -86,14 +86,14 @@ describe('Tests for admin api', ()=>{ const dismissKey = 'testKey'; jest.spyOn(NotificationModel, 'findOneAndDelete') - .mockImplementationOnce((key) => { + .mockImplementationOnce((key)=>{ return { exec: jest.fn().mockResolvedValue(key) }; }); const response = await app .delete(`/admin/notification/delete/${dismissKey}`) .set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`); - expect(NotificationModel.findOneAndDelete).toHaveBeenCalledWith({'dismissKey': 'testKey'}); + expect(NotificationModel.findOneAndDelete).toHaveBeenCalledWith({ 'dismissKey': 'testKey' }); expect(response.status).toBe(200); expect(response.body).toEqual({ dismissKey: 'testKey' }); }); @@ -102,14 +102,14 @@ describe('Tests for admin api', ()=>{ const dismissKey = 'testKey'; jest.spyOn(NotificationModel, 'findOneAndDelete') - .mockImplementationOnce(() => { + .mockImplementationOnce(()=>{ return { exec: jest.fn().mockResolvedValue() }; }); const response = await app .delete(`/admin/notification/delete/${dismissKey}`) .set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`); - expect(NotificationModel.findOneAndDelete).toHaveBeenCalledWith({'dismissKey': 'testKey'}); + expect(NotificationModel.findOneAndDelete).toHaveBeenCalledWith({ 'dismissKey': 'testKey' }); expect(response.status).toBe(500); expect(response.body).toEqual({ message: 'Notification not found' }); }); diff --git a/server/app.js b/server/app.js index 12fe21a1d..079f5e03c 100644 --- a/server/app.js +++ b/server/app.js @@ -11,7 +11,6 @@ const version = packageJSON.version; import _ from 'lodash'; import jwt from 'jwt-simple'; import express from 'express'; -import yaml from 'js-yaml'; import config from './config.js'; import fs from 'fs-extra'; diff --git a/server/googleActions.js b/server/googleActions.js index 2c2cbac73..0ca7556ba 100644 --- a/server/googleActions.js +++ b/server/googleActions.js @@ -27,12 +27,12 @@ if(!config.get('service_account')){ const defaultAuth = serviceAuth || config.get('google_api_key'); const retryConfig = { - retry: 3, // Number of retry attempts - retryDelay: 100, // Initial delay in milliseconds - retryDelayMultiplier: 2, // Multiplier for exponential backoff - maxRetryDelay: 32000, // Maximum delay in milliseconds - httpMethodsToRetry: ['PATCH'], // Only retry PATCH requests - statusCodesToRetry: [[429, 429]], // Only retry on 429 status code + retry : 3, // Number of retry attempts + retryDelay : 100, // Initial delay in milliseconds + retryDelayMultiplier : 2, // Multiplier for exponential backoff + maxRetryDelay : 32000, // Maximum delay in milliseconds + httpMethodsToRetry : ['PATCH'], // Only retry PATCH requests + statusCodesToRetry : [[429, 429]], // Only retry on 429 status code }; const GoogleActions = { @@ -177,8 +177,8 @@ const GoogleActions = { mimeType : 'text/plain', body : brew.text }, - headers: { - 'X-Forwarded-For': userIp, // Set the X-Forwarded-For header + headers : { + 'X-Forwarded-For' : userIp, // Set the X-Forwarded-For header }, retryConfig }) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 7bd88cbdb..af408e579 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -92,7 +92,7 @@ const api = { const accessMap = { edit : { editId: id }, share : { shareId: id }, - admin : { $or : [{ editId: id }, { shareId: id }] } + admin : { $or: [{ editId: id }, { shareId: id }] } }; // Try to find the document in the Homebrewery database -- if it doesn't exist, that's fine. @@ -181,6 +181,7 @@ const api = { `${text}`; return text; }, + getGoodBrewTitle : (text)=>{ const tokens = Markdown.marked.lexer(text); return (tokens.find((token)=>token.type === 'heading' || token.type === 'paragraph')?.text || 'No Title') @@ -294,7 +295,7 @@ const api = { currentTheme = req.brew; splitTextStyleAndMetadata(currentTheme); - if(!currentTheme.tags.some(tag => tag === "meta:theme" || tag === "meta:Theme")) + if(!currentTheme.tags.some((tag)=>tag === 'meta:theme' || tag === 'meta:Theme')) throw { brewId: req.params.id, name: 'Invalid Theme Selected', message: 'Selected theme does not have the meta:theme tag', status: 422, HBErrorCode: '10' }; themeName ??= currentTheme.title; themeAuthor ??= currentTheme.authors?.[0]; diff --git a/server/homebrew.model.js b/server/homebrew.model.js index adeac0d5d..15341f5d8 100644 --- a/server/homebrew.model.js +++ b/server/homebrew.model.js @@ -63,7 +63,7 @@ HomebrewSchema.statics.getByUser = async function(username, allowAccess=false, f const Homebrew = mongoose.model('Homebrew', HomebrewSchema); -export { +export { HomebrewSchema as schema, Homebrew as model }; diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 3334b026c..a8b877f4b 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -86,8 +86,8 @@ renderer.paragraph = function(token){ //Fix local links in the Preview iFrame to link inside the frame renderer.link = function (token) { - let {href, title, tokens} = token; - const text = this.parser.parseInline(tokens) + let { href, title, tokens } = token; + const text = this.parser.parseInline(tokens); let self = false; if(href[0] == '#') { self = true; @@ -110,7 +110,7 @@ renderer.link = function (token) { // Expose `src` attribute as `--HB_src` to make the URL accessible via CSS renderer.image = function (token) { - let {href, title, text} = token; + const { href, title, text } = token; if(href === null) return text; @@ -776,7 +776,7 @@ Marked.use({ extensions : [justifiedParagraphs, definitionListsMultiLine, defini Marked.use(mustacheInjectBlock); Marked.use(MarkedSubSuperText()); Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false }); -Marked.use(MarkedExtendedTables({interruptPatterns : tableTerminators}), MarkedGFMHeadingId({ globalSlugs: true }), +Marked.use(MarkedExtendedTables({ interruptPatterns: tableTerminators }), MarkedGFMHeadingId({ globalSlugs: true }), MarkedSmartypantsLite(), MarkedEmojis(MarkedEmojiOptions)); function cleanUrl(href) { @@ -841,12 +841,12 @@ const processStyleTags = (string)=>{ obj[key.trim()] = value.trim(); return obj; }, {}) || null; - const styles = tags?.length ? tags.reduce((styleObj, style) => { - const index = style.indexOf(':'); - const [key, value] = [style.substring(0, index), style.substring(index + 1)]; - styleObj[key.trim()] = value.replace(/"?([^"]*)"?/g, '$1').trim(); - return styleObj; - }, {}) : null; + const styles = tags?.length ? tags.reduce((styleObj, style)=>{ + const index = style.indexOf(':'); + const [key, value] = [style.substring(0, index), style.substring(index + 1)]; + styleObj[key.trim()] = value.replace(/"?([^"]*)"?/g, '$1').trim(); + return styleObj; + }, {}) : null; return { id : id, @@ -862,8 +862,8 @@ const extractHTMLStyleTags = (htmlString)=>{ const id = firstElementOnly.match(/id="([^"]*)"/)?.[1] || null; const classes = firstElementOnly.match(/class="([^"]*)"/)?.[1] || null; const styles = firstElementOnly.match(/style="([^"]*)"/)?.[1] - ?.split(';').reduce((styleObj, style) => { - if (style.trim() === '') return styleObj; + ?.split(';').reduce((styleObj, style)=>{ + if(style.trim() === '') return styleObj; const index = style.indexOf(':'); const [key, value] = [style.substring(0, index), style.substring(index + 1)]; styleObj[key.trim()] = value.trim(); @@ -873,7 +873,7 @@ const extractHTMLStyleTags = (htmlString)=>{ ?.filter((attr)=>!attr.startsWith('class="') && !attr.startsWith('style="') && !attr.startsWith('id="')) .reduce((obj, attr)=>{ const index = attr.indexOf('='); - let [key, value] = [attr.substring(0, index), attr.substring(index + 1)]; + const [key, value] = [attr.substring(0, index), attr.substring(index + 1)]; obj[key.trim()] = value.replace(/"/g, ''); return obj; }, {}) || null; @@ -886,7 +886,7 @@ const extractHTMLStyleTags = (htmlString)=>{ }; }; -const mergeHTMLTags = (originalTags, newTags) => { +const mergeHTMLTags = (originalTags, newTags)=>{ return { id : newTags.id || originalTags.id || null, classes : [originalTags.classes, newTags.classes].join(' ').trim() || null, diff --git a/tests/markdown/basic.test.js b/tests/markdown/basic.test.js index e5feec0b3..aaa2adf58 100644 --- a/tests/markdown/basic.test.js +++ b/tests/markdown/basic.test.js @@ -1,4 +1,4 @@ -/* eslint-disable max-lines */ + import Markdown from 'naturalcrit/markdown.js'; diff --git a/tests/markdown/non-breaking-spaces.test.js b/tests/markdown/non-breaking-spaces.test.js index 9dad4eb0f..c4f36554a 100644 --- a/tests/markdown/non-breaking-spaces.test.js +++ b/tests/markdown/non-breaking-spaces.test.js @@ -1,4 +1,4 @@ -/* eslint-disable max-lines */ + import Markdown from 'naturalcrit/markdown.js'; diff --git a/tests/markdown/paragraph-justification.test.js b/tests/markdown/paragraph-justification.test.js index 48b311e85..7876f5a26 100644 --- a/tests/markdown/paragraph-justification.test.js +++ b/tests/markdown/paragraph-justification.test.js @@ -1,4 +1,4 @@ -/* eslint-disable max-lines */ + import Markdown from 'naturalcrit/markdown.js'; diff --git a/themes/V3/5eDMG/snippets.js b/themes/V3/5eDMG/snippets.js index 636befb60..bad5e8e6a 100644 --- a/themes/V3/5eDMG/snippets.js +++ b/themes/V3/5eDMG/snippets.js @@ -1,4 +1,4 @@ -/* eslint-disable max-lines */ + module.exports = [ ]; diff --git a/themes/V3/Journal/snippets.js b/themes/V3/Journal/snippets.js index 636befb60..bad5e8e6a 100644 --- a/themes/V3/Journal/snippets.js +++ b/themes/V3/Journal/snippets.js @@ -1,4 +1,4 @@ -/* eslint-disable max-lines */ + module.exports = [ ]; diff --git a/themes/fonts/iconFonts/fontAwesome.js b/themes/fonts/iconFonts/fontAwesome.js index f5f89e3aa..bf11a7c92 100644 --- a/themes/fonts/iconFonts/fontAwesome.js +++ b/themes/fonts/iconFonts/fontAwesome.js @@ -1,3 +1,5 @@ +/* eslint-disable max-lines */ + const fontAwesome = { // FONT-AWESOME SOLID 'fas_0' : 'fas fa-0',