Node.js based forum software built for the modern web
fix: #7423 private uploads are linked to login page, for guests
Julian Lam49e3a368f8a3
diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.jsindex e03322f72e..ff797b63a7 100644--- a/public/src/client/topic/posts.js+++ b/public/src/client/topic/posts.js@@ -254,9 +254,10 @@ define('forum/topic/posts', [Posts.showBottomPostBar();posts.find('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');Posts.addBlockquoteEllipses(posts);- hidePostToolsForDeletedPosts(posts);+ hidePostToolsForDeletedPosts(posts);addNecroPostMessage();+ handlePrivateUploads(posts);};function addNecroPostMessage() {@@ -282,6 +283,27 @@ define('forum/topic/posts', [});}+ function handlePrivateUploads(posts) {+ if (app.user.uid) {+ return;+ }++ // Replace all requests for uploaded images/files with a login link+ var loginEl = document.createElement('a');+ loginEl.className = 'login-required';+ loginEl.href = config.relative_path + '/login';+ loginEl.appendChild(document.createTextNode('🔒 Log in to view'));++ posts.each(function (idx, postEl) {+ $(postEl).find('[component="post/content"] img').each(function (idx, imgEl) {+ imgEl = $(imgEl);+ if (imgEl.attr('src').startsWith(config.relative_path + config.upload_url)) {+ imgEl.replaceWith(loginEl.cloneNode(true));+ }+ });+ });+ }+Posts.onNewPostsAddedToDom = function (posts) {Posts.onTopicPageLoad(posts);