From b9ad551faa7287d4d31a1033ceef90a45845f6d1 Mon Sep 17 00:00:00 2001 From: CaramelKat <32065563+caramelkat@users.noreply.github.com> Date: Tue, 31 Aug 2021 16:05:25 -0500 Subject: [PATCH] Fixed issue where uploaded images would be ignore in the admin interface --- src/services/juxt-web/routes/admin/api.js | 45 +++++++---- src/webfiles/portal/announcements.ejs | 2 +- src/webfiles/portal/community_posts.ejs.old | 85 --------------------- 3 files changed, 31 insertions(+), 101 deletions(-) delete mode 100644 src/webfiles/portal/community_posts.ejs.old diff --git a/src/services/juxt-web/routes/admin/api.js b/src/services/juxt-web/routes/admin/api.js index de128ba..b533c4a 100644 --- a/src/services/juxt-web/routes/admin/api.js +++ b/src/services/juxt-web/routes/admin/api.js @@ -133,9 +133,8 @@ router.post('/communities/:communityID/update', upload.fields([{name: 'browserIc let user = await database.getUserByPID(pid); - if(user !== null) - { - if(config.authorized_PNIDs.indexOf(user.pid) === -1) { + if(user !== null) { + if (config.authorized_PNIDs.indexOf(user.pid) === -1) { logger.audit('[' + user.user_id + ' - ' + user.pid + '] attempted to update a community and is not authorized'); throw new Error('Invalid credentials supplied'); } @@ -143,30 +142,46 @@ router.post('/communities/:communityID/update', upload.fields([{name: 'browserIc const community = await database.getCommunityByID(req.params.communityID); const files = JSON.parse(JSON.stringify(req.files)); - if(req.body.name && community.name !== req.body.name) + if (req.body.name && community.name !== req.body.name) community.name = req.body.name; - if(req.body.description && community.description !== req.body.description) + if (req.body.description && community.description !== req.body.description) community.description = req.body.description; - if(req.body.title_ids[0] !== community.title_ids[0] && req.body.title_ids[1] !== community.title_ids[1] && req.body.title_ids[2] !== community.title_ids[2] - && req.body.title_ids[0] !== '' && req.body.title_ids[1] !== '' && req.body.title_ids[2] !== '') { + if (req.body.title_ids[0] !== community.title_ids[0] && req.body.title_ids[1] !== community.title_ids[1] && req.body.title_ids[2] !== community.title_ids[2] + && req.body.title_ids[0] !== '' && req.body.title_ids[1] !== '' && req.body.title_ids[2] !== '') { community.title_id = req.body.title_ids; community.title_ids = req.body.title_ids; } - if(req.body.icon && community.icon !== req.body.icon) + if (req.body.icon && community.icon !== req.body.icon) community.icon = req.body.icon; - if(req.files.browserIcon) { - community.browser_icon = `data:image/png;base64,${await sharp(req.files.browserIcon[0].buffer).resize({ height: 128, width: 128 }).toBuffer().toString('base64')}`; - community.browser_thumbnail = `data:image/png;base64,${await sharp(req.files.browserIcon[0].buffer).resize({ height: 128, width: 128 }).toBuffer().toString('base64')}`; + if (req.files.browserIcon) { + await sharp(req.files.browserIcon[0].buffer).then(file => function () { + community.browser_icon = `data:image/png;base64,${file.resize({ + height: 128, + width: 128 + }).toBuffer().toString('base64')}` + }) + } + if (req.files.CTRbrowserHeader) { + await sharp(req.files.CTRbrowserHeader[0].buffer).then(file => function () { + community.CTR_browser_header = `data:image/png;base64,${file.resize({ + height: 220, + width: 400 + }).toBuffer().toString('base64')}` + }) } - if(req.files.CTRbrowserHeader) - community.CTR_browser_header = `data:image/png;base64,${await sharp(req.files.CTRbrowserHeader[0].buffer).resize({ height: 220, width: 400 }).toBuffer().toString('base64')}`; - if(req.files.WiiUbrowserHeader) - community.WiiU_browser_header = `data:image/png;base64,${await sharp(req.files.WiiUbrowserHeader[0].buffer).resize({ height: 328, width: 1498 }).toBuffer().toString('base64')}`; + if (req.files.WiiUbrowserHeader) { + await sharp(req.files.WiiUbrowserHeader[0].buffer).then(file => function () { + community.WiiU_browser_header = `data:image/png;base64,${file.resize({ + height: 328, + width: 1498 + }).toBuffer().toString('base64')}` + }) + } if(req.body.is_recommended) community.is_recommended = req.body.is_recommended; diff --git a/src/webfiles/portal/announcements.ejs b/src/webfiles/portal/announcements.ejs index e0bb2a0..3d92813 100644 --- a/src/webfiles/portal/announcements.ejs +++ b/src/webfiles/portal/announcements.ejs @@ -31,7 +31,7 @@
-
+

<%= community.name %>

diff --git a/src/webfiles/portal/community_posts.ejs.old b/src/webfiles/portal/community_posts.ejs.old deleted file mode 100644 index 35d24c6..0000000 --- a/src/webfiles/portal/community_posts.ejs.old +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - -
-

<%= lang.community.recent %>

-
- - -

<%= lang.community.verified %>

-
-<% newPosts.forEach(function(post) { %> - -<%if(post.screenshot !== '' && post.painting === '' && post.url === '' && post.body === '') {%> -
-

Screenshot Only:

- -
-<% } else if(post.painting !== '' && post.screenshot === '' && post.url === '') {%> -
-

Painting Only:

- -
-<% } else if(post.url !== '' && post.screenshot === '' && post.painting === '' && post.body === '') {%> -
-

Video Only:

- -
-<% } else if(post.body !== '' && post.screenshot === '' && post.painting === '' && post.url === '') {%> -
-

Text Only:

-

<%= post.body %>

-
-<% } else if(post.screenshot !== '' && post.body !== '' && post.painting === '' && post.url === '') {%> -
-

Screenshot and Body:

- -
-

<%= post.body %>

-
-
-<% } else if(post.screenshot !== '' && post.painting !== '' && post.url === '') {%> -
-

Screenshot and Painting:

- - -
-<% } else if(post.url !== '' && post.body !== '' && post.screenshot === '' && post.painting === '') {%> -
-

Video and Body:

- -
-

<%= post.body %>

-
-
-<% } else if(post.url !== '' && post.painting !== '' && post.screenshot === '' && post.body === '') {%> -
-

Video and Painting:

- - -
-<%}%> -
-
-<% }); %> -