Fixed issue where uploaded images would be ignore in the admin interface

This commit is contained in:
CaramelKat
2021-08-31 16:05:25 -05:00
committed by jay.poff@outlook.com
parent 9f22903db9
commit b9ad551faa
3 changed files with 31 additions and 101 deletions

View File

@@ -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;

View File

@@ -31,7 +31,7 @@
<li id="nav-bar-exit" onclick="exit()"><a href=""><%= lang.global.close %></a></li>
</menu>
<div id="main">
<div class="community-page-header" style="background-image: url('/banner/<%= community.community_id %>.png')"></div>
<div class="community-page-header" style="background-image: url('<%= cdnURL %>/banner/<%= community.community_id %>.png')"></div>
<div class="community-page-info-container" style="min-height: 150px">
<img class="community-page-info-icon" src="/icons/<%= community.community_id %>.png">
<h2 class="community-page-title"><%= community.name %></h2>

View File

@@ -1,85 +0,0 @@
<table class="community-page-posts-header">
<tbody>
<tr>
<td>
<h4 id="recent-tab" onclick="loadPosts(0)" class="community-page-posts-header-tab active"><%= lang.community.recent %></h4>
</td>
<td>
<h4 id="popular-tab" onclick="loadPosts(1)" class="community-page-posts-header-tab"><%= lang.community.popular %></h4>
</td>
<td>
<h4 id="verified-tab" onclick="loadPosts(2)" class="community-page-posts-header-tab"><%= lang.community.verified %></h4>
</td>
</tr>
</tbody>
</table>
<% newPosts.forEach(function(post) { %>
<div class="post-user-info-wrapper">
<%if(post.verified) {%>
<img class="community-page-post-user-icon verified" src="https://mii-images.cdn.<%= account_server %>/<%= post.pid %>/<% if(post.feeling_id === 1) {%>smile_open_mouth.png<%} else if(post.feeling_id === 2 ) {%>wink_left.png<%} else if(post.feeling_id === 3 ) {%>surprise_open_mouth.png<%} else if(post.feeling_id === 4 ) {%>frustrated.png<%} else if(post.feeling_id === 5 ) {%>sorrow.png<%} else {%>normal_face.png<%}%>" data-pjax="/users/show?pid=<%= post.pid %>">
<span class="community-page-verified-user-badge community-page-verified" style="" data-pjax="/users/show?pid=<%= post.pid %>"></span>
<%} else {%>
<img class="community-page-post-user-icon" src="https://mii-images.cdn.<%= account_server %>/<%= post.pid %>/<% if(post.feeling_id === 1) {%>smile_open_mouth.png<%} else if(post.feeling_id === 2 ) {%>wink_left.png<%} else if(post.feeling_id === 3 ) {%>surprise_open_mouth.png<%} else if(post.feeling_id === 4 ) {%>frustrated.png<%} else if(post.feeling_id === 5 ) {%>sorrow.png<%} else {%>normal_face.png<%}%>" data-pjax="/users/show?pid=<%= post.pid %>">
<span class="community-page-verified-user-badge community-page-verified" style="display: none;" data-pjax="/users/show?pid=<%= post.pid %>"></span>
<%}%>
<h2 class="community-page-post-username" data-pjax="/users/show?pid=<%= post.pid %>"><%= post.screen_name %></h2>
<h4 class="community-page-post-time-stamp"><%= moment(post.created_at).fromNow() %></h4>
<div class="community-page-post-yeah-button-wrapper <%if(user.likes.indexOf(post.id) !== -1){ %> selected <%}%>">
<div class="community-page-post-yeah-button" onclick="yeah(this.parentNode, <%= post.id %>)"></div>
</div>
<div id="yeah-<%= post.id %>" class="community-page-post-yeah-count"><%= post.empathy_count %> <%= lang.global.yeahs %></div>
</div>
<%if(post.screenshot !== '' && post.painting === '' && post.url === '' && post.body === '') {%>
<div class="community-page-post-wrapper">
<p>Screenshot Only:</p>
<img id="<%= post.id %>" class="community-page-post-screenshot" src="data:image/png;base64,<%= post.screenshot %>">
</div>
<% } else if(post.painting !== '' && post.screenshot === '' && post.url === '') {%>
<div class="community-page-post-wrapper">
<p>Painting Only:</p>
<img id="<%= post.id%>" class="community-page-post-painting" src="<%= post.painting_uri %>">
</div>
<% } else if(post.url !== '' && post.screenshot === '' && post.painting === '' && post.body === '') {%>
<div class="community-page-post-wrapper">
<p>Video Only:</p>
<iframe width="760" height="427.5" src="<%= post.url %>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<% } else if(post.body !== '' && post.screenshot === '' && post.painting === '' && post.url === '') {%>
<div class="community-page-post-wrapper">
<p>Text Only:</p>
<h3><%= post.body %></h3>
</div>
<% } else if(post.screenshot !== '' && post.body !== '' && post.painting === '' && post.url === '') {%>
<div class="community-page-post-wrapper">
<p>Screenshot and Body:</p>
<img id="<%= post.id %>" class="community-page-post-screenshot" src="data:image/png;base64,<%= post.screenshot %>">
<div class="community-page-post-text-overlay">
<h3><%= post.body %></h3>
</div>
</div>
<% } else if(post.screenshot !== '' && post.painting !== '' && post.url === '') {%>
<div class="community-page-post-wrapper">
<p>Screenshot and Painting:</p>
<img id="<%= post.id %>" class="community-page-post-screenshot" src="data:image/png;base64,<%= post.screenshot %>">
<img id="<%= post.id%>" class="community-page-post-painting" src="<%= post.painting_uri %>">
</div>
<% } else if(post.url !== '' && post.body !== '' && post.screenshot === '' && post.painting === '') {%>
<div class="community-page-post-wrapper">
<p>Video and Body:</p>
<iframe width="760" height="427.5" src="<%= post.url %>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<div class="community-page-post-text-overlay">
<h3><%= post.body %></h3>
</div>
</div>
<% } else if(post.url !== '' && post.painting !== '' && post.screenshot === '' && post.body === '') {%>
<div class="community-page-post-wrapper">
<p>Video and Painting:</p>
<iframe width="760" height="427.5" src="<%= post.url %>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<img id="<%= post.id%>" class="community-page-post-painting" src="<%= post.painting_uri %>">
</div>
<%}%>
<br>
<br>
<% }); %>
<img src="" onerror="wiiuBrowser.showLoadingIcon(!1)">