diff options
Diffstat (limited to 'src/main/java/com/juick')
22 files changed, 93 insertions, 65 deletions
diff --git a/src/main/java/com/juick/API.java b/src/main/java/com/juick/API.java index fdfc4977..dbe00ad9 100644 --- a/src/main/java/com/juick/API.java +++ b/src/main/java/com/juick/API.java @@ -25,7 +25,7 @@ import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @EnableAutoConfiguration(exclude = { MailSenderAutoConfiguration.class }) -@ComponentScan(basePackages = {"com.juick.server", "com.juick.service"}) +@ComponentScan(basePackages = {"com.juick.server", "com.juick.service", "com.juick.www"}) public class API { public static void main(String[] args) { SpringApplication.run(API.class, args); diff --git a/src/main/java/com/juick/server/CommandsManager.java b/src/main/java/com/juick/server/CommandsManager.java index 494094eb..8029c301 100644 --- a/src/main/java/com/juick/server/CommandsManager.java +++ b/src/main/java/com/juick/server/CommandsManager.java @@ -26,7 +26,7 @@ import com.juick.model.TagStats; import com.juick.server.api.SystemActivity; import com.juick.server.helpers.annotation.UserCommand; import com.juick.server.util.HttpUtils; -import com.juick.server.www.WebApp; +import com.juick.www.WebApp; import com.juick.service.*; import com.juick.service.activities.DeleteMessageEvent; import com.juick.service.component.*; diff --git a/src/main/java/com/juick/server/EmailManager.java b/src/main/java/com/juick/server/EmailManager.java index 768dd8de..0782f858 100644 --- a/src/main/java/com/juick/server/EmailManager.java +++ b/src/main/java/com/juick/server/EmailManager.java @@ -23,7 +23,7 @@ import com.juick.model.Message; import com.juick.model.User; import com.juick.server.api.SystemActivity; import com.juick.server.util.HttpBadRequestException; -import com.juick.server.www.WebApp; +import com.juick.www.WebApp; import com.juick.service.EmailService; import com.juick.service.MessagesService; import com.juick.service.UserService; diff --git a/src/main/java/com/juick/server/XMPPManager.java b/src/main/java/com/juick/server/XMPPManager.java index dd2eaaf2..af6fe022 100644 --- a/src/main/java/com/juick/server/XMPPManager.java +++ b/src/main/java/com/juick/server/XMPPManager.java @@ -21,7 +21,7 @@ import com.juick.model.User; import com.juick.formatters.PlainTextFormatter; import com.juick.model.CommandResult; import com.juick.server.api.SystemActivity; -import com.juick.server.www.WebApp; +import com.juick.www.WebApp; import com.juick.server.xmpp.iq.MessageQuery; import com.juick.service.MessagesService; import com.juick.service.PMQueriesService; diff --git a/src/main/java/com/juick/server/api/Messages.java b/src/main/java/com/juick/server/api/Messages.java index ffe55d3f..5e0743dd 100644 --- a/src/main/java/com/juick/server/api/Messages.java +++ b/src/main/java/com/juick/server/api/Messages.java @@ -21,7 +21,7 @@ import com.juick.model.Message; import com.juick.model.Tag; import com.juick.model.User; import com.juick.server.Utils; -import com.juick.server.www.WebApp; +import com.juick.www.WebApp; import com.juick.model.CommandResult; import com.juick.server.util.HttpBadRequestException; import com.juick.service.MessagesService; diff --git a/src/main/java/com/juick/server/api/PM.java b/src/main/java/com/juick/server/api/PM.java index d5860057..a37cc85e 100644 --- a/src/main/java/com/juick/server/api/PM.java +++ b/src/main/java/com/juick/server/api/PM.java @@ -25,7 +25,7 @@ import com.juick.model.PrivateChats; import com.juick.server.util.HttpBadRequestException; import com.juick.server.util.HttpForbiddenException; import com.juick.server.util.WebUtils; -import com.juick.server.www.WebApp; +import com.juick.www.WebApp; import com.juick.service.PMQueriesService; import com.juick.service.UserService; import com.juick.service.component.SystemEvent; diff --git a/src/main/java/com/juick/server/api/Users.java b/src/main/java/com/juick/server/api/Users.java index 531883fc..84ac5174 100644 --- a/src/main/java/com/juick/server/api/Users.java +++ b/src/main/java/com/juick/server/api/Users.java @@ -20,12 +20,11 @@ package com.juick.server.api; import com.juick.model.User; import com.juick.model.AnonymousUser; import com.juick.model.ApplicationStatus; -import com.juick.server.EmailManager; import com.juick.server.util.HttpBadRequestException; import com.juick.server.util.HttpNotFoundException; import com.juick.server.util.HttpUtils; import com.juick.server.util.WebUtils; -import com.juick.server.www.WebApp; +import com.juick.www.WebApp; import com.juick.service.*; import com.juick.service.component.MailVerificationEvent; import com.juick.service.security.annotation.Visitor; diff --git a/src/main/java/com/juick/server/api/activity/Profile.java b/src/main/java/com/juick/server/api/activity/Profile.java index f17b70c6..bbe3c0af 100644 --- a/src/main/java/com/juick/server/api/activity/Profile.java +++ b/src/main/java/com/juick/server/api/activity/Profile.java @@ -41,7 +41,7 @@ import com.juick.server.api.activity.model.objects.OrderedCollection; import com.juick.server.api.activity.model.objects.OrderedCollectionPage; import com.juick.server.api.activity.model.objects.Person; import com.juick.server.util.HttpNotFoundException; -import com.juick.server.www.WebApp; +import com.juick.www.WebApp; import com.juick.service.MessagesService; import com.juick.service.UserService; import com.juick.service.activities.AnnounceEvent; diff --git a/src/main/java/com/juick/server/api/rss/MessagesView.java b/src/main/java/com/juick/server/api/rss/MessagesView.java index e7bc1bb3..a03dd723 100644 --- a/src/main/java/com/juick/server/api/rss/MessagesView.java +++ b/src/main/java/com/juick/server/api/rss/MessagesView.java @@ -21,7 +21,7 @@ import com.juick.model.Message; import com.juick.model.User; import com.juick.server.api.rss.extension.JuickModule; import com.juick.server.api.rss.extension.JuickModuleImpl; -import com.juick.server.www.WebApp; +import com.juick.www.WebApp; import com.juick.util.MessageUtils; import com.rometools.modules.atom.modules.AtomLinkModule; import com.rometools.modules.atom.modules.AtomLinkModuleImpl; diff --git a/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java b/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java index 0ac90a52..e8733e35 100644 --- a/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java +++ b/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java @@ -17,7 +17,7 @@ package com.juick.server.configuration; -import com.juick.server.www.HelpService; +import com.juick.www.HelpService; import com.juick.service.TagService; import com.juick.service.UserService; import com.mitchellbosecke.pebble.PebbleEngine; diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index e2b5e2b1..e3b7482b 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -19,7 +19,7 @@ package com.juick.service; import com.juick.model.*; import com.juick.model.User; -import com.juick.server.www.WebApp; +import com.juick.www.WebApp; import com.juick.util.MessageUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; diff --git a/src/main/java/com/juick/server/www/HelpService.java b/src/main/java/com/juick/www/HelpService.java index 5f785970..9d3c3f16 100644 --- a/src/main/java/com/juick/server/www/HelpService.java +++ b/src/main/java/com/juick/www/HelpService.java @@ -15,7 +15,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package com.juick.server.www; +package com.juick.www; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; diff --git a/src/main/java/com/juick/server/www/VaryHandler.java b/src/main/java/com/juick/www/VaryHandler.java index 7d70fc34..fb5f7665 100644 --- a/src/main/java/com/juick/server/www/VaryHandler.java +++ b/src/main/java/com/juick/www/VaryHandler.java @@ -15,7 +15,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package com.juick.server.www; +package com.juick.www; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ModelAttribute; diff --git a/src/main/java/com/juick/server/www/WebApp.java b/src/main/java/com/juick/www/WebApp.java index bf013c3b..a0675e6d 100644 --- a/src/main/java/com/juick/server/www/WebApp.java +++ b/src/main/java/com/juick/www/WebApp.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package com.juick.server.www; +package com.juick.www; import com.juick.model.Message; import com.juick.model.Tag; diff --git a/src/main/java/com/juick/www/ad/SapeService.java b/src/main/java/com/juick/www/ad/SapeService.java new file mode 100644 index 00000000..9d58f8b4 --- /dev/null +++ b/src/main/java/com/juick/www/ad/SapeService.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2008-2020, Juick + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package com.juick.www.ad; + +import com.juick.model.User; +import com.juick.service.security.annotation.Visitor; +import com.juick.www.controllers.MessagesWWW; +import org.apache.commons.lang3.StringUtils; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +import org.springframework.web.util.UriComponents; +import ru.sape.Sape; + +import javax.inject.Inject; +import java.net.URI; + +@ControllerAdvice(assignableTypes = MessagesWWW.class) +@ConditionalOnProperty("sape_user") +public class SapeService { + + private final Sape sape; + + @Inject + public SapeService(Sape sape) { + this.sape = sape; + } + + @ModelAttribute + public void addSapeLinks( + @Visitor User visitor, + @CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie, + @RequestParam(required = false, defaultValue = "0") int before, + @RequestParam(name = "show", required = false) String paramShow, + @RequestParam(name = "search", required = false) String paramSearch, + @RequestParam(name = "to", required = false, defaultValue = "0") Long paramTo, + ModelMap model) { + UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequest().build(); + URI requestURI = builder.toUri(); + var showAdv = paramShow == null && before == 0 && paramSearch == null + && visitor.isAnonymous(); + model.addAttribute("showAdv", showAdv); + if (showAdv) { + String links = sape.getPageLinks(requestURI, sapeCookie).render(); + model.addAttribute("links", links); + } + } +} diff --git a/src/main/java/com/juick/server/www/controllers/Help.java b/src/main/java/com/juick/www/controllers/Help.java index 8bb9aecd..d2796def 100644 --- a/src/main/java/com/juick/server/www/controllers/Help.java +++ b/src/main/java/com/juick/www/controllers/Help.java @@ -15,12 +15,12 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package com.juick.server.www.controllers; +package com.juick.www.controllers; import com.juick.model.User; import com.juick.server.util.HttpNotFoundException; -import com.juick.server.www.HelpService; -import com.juick.server.www.WebApp; +import com.juick.www.HelpService; +import com.juick.www.WebApp; import com.juick.service.MessagesService; import com.juick.service.security.annotation.Visitor; import org.commonmark.parser.Parser; diff --git a/src/main/java/com/juick/server/www/controllers/Login.java b/src/main/java/com/juick/www/controllers/Login.java index e6d6904c..8bc8e340 100644 --- a/src/main/java/com/juick/server/www/controllers/Login.java +++ b/src/main/java/com/juick/www/controllers/Login.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package com.juick.server.www.controllers; +package com.juick.www.controllers; import com.juick.model.User; import com.juick.service.UserService; diff --git a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java b/src/main/java/com/juick/www/controllers/MessagesWWW.java index a7e4c127..4b0bb17f 100644 --- a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java +++ b/src/main/java/com/juick/www/controllers/MessagesWWW.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package com.juick.server.www.controllers; +package com.juick.www.controllers; import com.juick.model.Message; import com.juick.model.Tag; @@ -24,7 +24,7 @@ import com.juick.server.Utils; import com.juick.server.util.HttpForbiddenException; import com.juick.server.util.HttpNotFoundException; import com.juick.server.util.WebUtils; -import com.juick.server.www.WebApp; +import com.juick.www.WebApp; import com.juick.service.*; import com.juick.service.security.annotation.Visitor; import com.juick.util.MessageUtils; @@ -37,13 +37,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.support.ServletUriComponentsBuilder; -import org.springframework.web.util.UriComponents; -import ru.sape.Sape; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; -import java.net.URI; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -65,8 +61,6 @@ public class MessagesWWW { @Inject private MessagesService messagesService; @Inject - private Optional<Sape> sape; - @Inject private PMQueriesService pmQueriesService; @Inject private CrosspostService crosspostService; @@ -98,7 +92,6 @@ public class MessagesWWW { @RequestParam(name = "before", required = false, defaultValue = "0") Integer paramBefore, @RequestParam(name = "to", required = false, defaultValue = "0") Long paramTo, @RequestParam(name = "page", required = false, defaultValue = "0") Integer page, - @CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie, ModelMap model) { if (tag != null) { return "redirect:/tag/" + URLEncoder.encode(tag, StandardCharsets.UTF_8); @@ -169,8 +162,6 @@ public class MessagesWWW { model.addAttribute("msgs", msgs); model.addAttribute("tags", tagService.getPopularTags()); model.addAttribute("headers", head); - model.addAttribute("showAdv", - paramShow == null && paramBefore == 0 && paramSearch == null && visitor.isAnonymous()); if (mids.size() >= 20) { String nextpage = paramSearch != null ? String.format("?page=%d", page + 1) : (paramShow == null) ? "?to=" + msgs.get(msgs.size() - 1).getUpdated().toEpochMilli() @@ -183,12 +174,6 @@ public class MessagesWWW { } model.addAttribute("nextpage", nextpage); } - UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequest().build(); - URI requestURI = builder.toUri(); - if (sape.isPresent() && visitor.isAnonymous()) { - String links = sape.get().getPageLinks(requestURI, sapeCookie).render(); - model.addAttribute("links", links); - } return "views/index"; } @@ -284,8 +269,6 @@ public class MessagesWWW { } model.addAttribute("msgs", msgs); model.addAttribute("headers", head); - model.addAttribute("showAdv", - paramShow == null && before == 0 && paramSearch == null && visitor.getUid() == 0); if (mids.size() >= 20) { String nextpage = paramSearch != null ? String.format("?page=%d", page + 1) : "?before=" + mids.get(mids.size() - 1); if (paramShow != null) { @@ -299,12 +282,6 @@ public class MessagesWWW { } model.addAttribute("nextpage", nextpage); } - UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequest().build(); - URI requestURI = builder.toUri(); - if (sape.isPresent() && visitor.isAnonymous()) { - String links = sape.get().getPageLinks(requestURI, sapeCookie).render(); - model.addAttribute("links", links); - } return "views/blog"; } @@ -383,7 +360,6 @@ public class MessagesWWW { @Visitor User visitor, HttpServletRequest request, @PathVariable String tagName, - @CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie, @RequestParam(required = false, defaultValue = "0") int before, ModelMap model) { visitor.setAvatar(webApp.getAvatarWebPath(visitor)); @@ -435,19 +411,12 @@ public class MessagesWWW { model.addAttribute("msgs", msgs); model.addAttribute("tags", tagService.getPopularTags()); model.addAttribute("noindex", before > 0); - model.addAttribute("showAdv", before == 0 && visitor.isAnonymous()); model.addAttribute("isSubscribed", tagService.isSubscribed(visitor, paramTag)); model.addAttribute("isInBL", tagService.isInBL(visitor, paramTag)); if (mids.size() >= 20) { String nextpage = "/tag/" + URLEncoder.encode(paramTag.getName(), StandardCharsets.UTF_8) + "?before=" + mids.get(mids.size() - 1); model.addAttribute("nextpage", nextpage); } - UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequest().build(); - URI requestURI = builder.toUri(); - if (sape.isPresent() && visitor.isAnonymous()) { - String links = sape.get().getPageLinks(requestURI, sapeCookie).render(); - model.addAttribute("links", links); - } return "views/index"; } @GetMapping("/pm/inbox") @@ -585,13 +554,6 @@ public class MessagesWWW { } } model.addAttribute("replies", replies); - model.addAttribute("showAdv", visitor.isAnonymous()); - UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequest().build(); - URI requestURI = builder.toUri(); - if (sape.isPresent() && visitor.isAnonymous()) { - String links = sape.get().getPageLinks(requestURI, sapeCookie).render(); - model.addAttribute("links", links); - } return "views/thread"; } diff --git a/src/main/java/com/juick/server/www/controllers/Settings.java b/src/main/java/com/juick/www/controllers/Settings.java index e535eef0..851e576b 100644 --- a/src/main/java/com/juick/server/www/controllers/Settings.java +++ b/src/main/java/com/juick/www/controllers/Settings.java @@ -14,13 +14,13 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package com.juick.server.www.controllers; +package com.juick.www.controllers; import com.juick.model.User; import com.juick.model.NotifyOpts; import com.juick.server.util.HttpBadRequestException; import com.juick.server.util.HttpUtils; -import com.juick.server.www.WebApp; +import com.juick.www.WebApp; import com.juick.service.*; import com.juick.service.security.annotation.Visitor; import org.apache.commons.lang3.RandomStringUtils; diff --git a/src/main/java/com/juick/server/www/controllers/SignUp.java b/src/main/java/com/juick/www/controllers/SignUp.java index cc2101a3..4e74d4c4 100644 --- a/src/main/java/com/juick/server/www/controllers/SignUp.java +++ b/src/main/java/com/juick/www/controllers/SignUp.java @@ -14,12 +14,12 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package com.juick.server.www.controllers; +package com.juick.www.controllers; import com.juick.model.User; import com.juick.server.util.HttpBadRequestException; import com.juick.server.util.HttpForbiddenException; -import com.juick.server.www.WebApp; +import com.juick.www.WebApp; import com.juick.service.CrosspostService; import com.juick.service.EmailService; import com.juick.service.UserService; diff --git a/src/main/java/com/juick/server/www/controllers/SocialLogin.java b/src/main/java/com/juick/www/controllers/SocialLogin.java index e3b7a33b..2bd89587 100644 --- a/src/main/java/com/juick/server/www/controllers/SocialLogin.java +++ b/src/main/java/com/juick/www/controllers/SocialLogin.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package com.juick.server.www.controllers; +package com.juick.www.controllers; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.apis.*; diff --git a/src/main/java/com/juick/server/www/filters/AnythingFilter.java b/src/main/java/com/juick/www/filters/AnythingFilter.java index 9a012089..8f9af7f6 100644 --- a/src/main/java/com/juick/server/www/filters/AnythingFilter.java +++ b/src/main/java/com/juick/www/filters/AnythingFilter.java @@ -15,7 +15,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package com.juick.server.www.filters; +package com.juick.www.filters; import com.juick.model.User; import com.juick.server.util.WebUtils; |