diff options
11 files changed, 31 insertions, 49 deletions
diff --git a/juick-api/src/main/java/com/juick/api/TGBot.java b/juick-api/src/main/java/com/juick/api/TGBot.java index 5bf9185b..e67e3161 100644 --- a/juick-api/src/main/java/com/juick/api/TGBot.java +++ b/juick-api/src/main/java/com/juick/api/TGBot.java @@ -53,17 +53,17 @@ import static com.juick.formatters.PlainTextFormatter.formatUrl; public class TGBot extends TextWebSocketHandler { private static final Logger logger = LoggerFactory.getLogger(TGBot.class); - TelegramBot bot; + private TelegramBot bot; private ObjectMapper ms; @Inject - TelegramService telegramService; + private TelegramService telegramService; @Inject - MessagesService messagesService; + private MessagesService messagesService; @Inject static WebSocketConnectionManager connectionManager; - WebSocketSession session; + private WebSocketSession session; private TGBot() { throw new IllegalStateException(); diff --git a/juick-api/src/main/java/com/juick/api/controllers/Messages.java b/juick-api/src/main/java/com/juick/api/controllers/Messages.java index d81db3b2..b11c39c5 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/Messages.java +++ b/juick-api/src/main/java/com/juick/api/controllers/Messages.java @@ -20,15 +20,12 @@ package com.juick.api.controllers; import com.juick.Status; import com.juick.Tag; import com.juick.User; -import com.juick.api.ApiServer; import com.juick.server.util.HttpBadRequestException; import com.juick.server.util.HttpForbiddenException; +import com.juick.server.util.UserUtils; import com.juick.service.MessagesService; import com.juick.service.TagService; import com.juick.service.UserService; -import com.juick.server.util.UserUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -45,7 +42,6 @@ import java.util.List; @RestController @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public class Messages { - private static final Logger logger = LoggerFactory.getLogger(Messages.class); private static final ResponseEntity<List<com.juick.Message>> NOT_FOUND = ResponseEntity .status(HttpStatus.NOT_FOUND) @@ -61,8 +57,6 @@ public class Messages { private UserService userService; @Inject private TagService tagService; - @Inject - private ApiServer apiServer; // TODO: serialize image urls diff --git a/juick-api/src/main/java/com/juick/api/controllers/Notifications.java b/juick-api/src/main/java/com/juick/api/controllers/Notifications.java index d2669253..c08689aa 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/Notifications.java +++ b/juick-api/src/main/java/com/juick/api/controllers/Notifications.java @@ -47,13 +47,13 @@ import java.util.stream.Collectors; public class Notifications { @Inject - PushQueriesService pushQueriesService; + private PushQueriesService pushQueriesService; @Inject - MessagesService messagesService; + private MessagesService messagesService; @Inject - SubscriptionService subscriptionService; + private SubscriptionService subscriptionService; @Inject - UserService userService; + private UserService userService; private User collectTokens(Integer uid) { diff --git a/juick-api/src/main/java/com/juick/api/controllers/Others.java b/juick-api/src/main/java/com/juick/api/controllers/Others.java index f9d78187..4245de81 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/Others.java +++ b/juick-api/src/main/java/com/juick/api/controllers/Others.java @@ -21,9 +21,8 @@ import com.juick.User; import com.juick.server.helpers.PrivateChats; import com.juick.server.util.HttpForbiddenException; import com.juick.server.util.HttpNotFoundException; -import com.juick.service.PMQueriesService; -import com.juick.service.UserService; import com.juick.server.util.UserUtils; +import com.juick.service.PMQueriesService; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -39,9 +38,7 @@ import java.util.List; @RestController public class Others { @Inject - PMQueriesService pmQueriesService; - @Inject - UserService userService; + private PMQueriesService pmQueriesService; @RequestMapping(value = "groups_pms", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public PrivateChats doGetGroupsPMs( diff --git a/juick-api/src/main/java/com/juick/api/controllers/PM.java b/juick-api/src/main/java/com/juick/api/controllers/PM.java index 9d985991..e909a4b5 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/PM.java +++ b/juick-api/src/main/java/com/juick/api/controllers/PM.java @@ -42,11 +42,11 @@ import java.util.List; @RestController public class PM { @Inject - UserService userService; + private UserService userService; @Inject - PMQueriesService pmQueriesService; + private PMQueriesService pmQueriesService; @Inject - ApiServer apiServer; + private ApiServer apiServer; @RequestMapping(value = "/pm", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public List<com.juick.Message> doGetPM( diff --git a/juick-api/src/main/java/com/juick/api/controllers/Post.java b/juick-api/src/main/java/com/juick/api/controllers/Post.java index 4654f48c..7696b7d8 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/Post.java +++ b/juick-api/src/main/java/com/juick/api/controllers/Post.java @@ -62,17 +62,17 @@ public class Post { private static Logger logger = LoggerFactory.getLogger(ApiServer.class); @Inject - UserService userService; + private UserService userService; @Inject - ApiServer apiServer; + private ApiServer apiServer; @Inject - MessagesService messagesService; + private MessagesService messagesService; @Inject - SubscriptionService subscriptionService; + private SubscriptionService subscriptionService; @Value("${upload_tmp_dir:/var/www/juick.com/i/tmp/}") - String tmpDir; + private String tmpDir; @Value("${img_path:/var/www/juick.com/i/}") - String imgDir; + private String imgDir; @RequestMapping(value = "/post", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseStatus(value = HttpStatus.OK) diff --git a/juick-api/src/main/java/com/juick/api/controllers/Subscriptions.java b/juick-api/src/main/java/com/juick/api/controllers/Subscriptions.java index a9452107..06ea9fcf 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/Subscriptions.java +++ b/juick-api/src/main/java/com/juick/api/controllers/Subscriptions.java @@ -21,10 +21,9 @@ import com.juick.Message; import com.juick.User; import com.juick.server.util.HttpBadRequestException; import com.juick.server.util.HttpForbiddenException; +import com.juick.server.util.UserUtils; import com.juick.service.MessagesService; import com.juick.service.SubscriptionService; -import com.juick.service.UserService; -import com.juick.server.util.UserUtils; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -41,11 +40,9 @@ import java.util.List; @RestController public class Subscriptions { @Inject - UserService userService; - @Inject - SubscriptionService subscriptionService; + private SubscriptionService subscriptionService; @Inject - MessagesService messagesService; + private MessagesService messagesService; @RequestMapping(value = "/subscriptions", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public List<User> doGet( diff --git a/juick-api/src/main/java/com/juick/api/controllers/Tags.java b/juick-api/src/main/java/com/juick/api/controllers/Tags.java index d980b95f..85bb1ba4 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/Tags.java +++ b/juick-api/src/main/java/com/juick/api/controllers/Tags.java @@ -19,9 +19,8 @@ package com.juick.api.controllers; import com.juick.User; import com.juick.server.helpers.TagStats; -import com.juick.service.TagService; -import com.juick.service.UserService; import com.juick.server.util.UserUtils; +import com.juick.service.TagService; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -37,9 +36,7 @@ import java.util.List; @RestController public class Tags { @Inject - UserService userService; - @Inject - TagService tagService; + private TagService tagService; @RequestMapping(value = "/tags", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public List<TagStats> tags( diff --git a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java b/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java index 718ea052..be29ee62 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java +++ b/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java @@ -46,11 +46,11 @@ import java.util.List; public class TelegramWebhook { private static Logger logger = LoggerFactory.getLogger(TelegramWebhook.class); @Inject - UserService usersService; + private UserService usersService; @Inject - TelegramService telegramService; + private TelegramService telegramService; @Inject - TGBot tgBot; + private TGBot tgBot; @RequestMapping(value = "/tlgmbtwbhk", method = RequestMethod.POST) diff --git a/juick-api/src/main/java/com/juick/api/controllers/Users.java b/juick-api/src/main/java/com/juick/api/controllers/Users.java index 6439c1cb..35bd229b 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/Users.java +++ b/juick-api/src/main/java/com/juick/api/controllers/Users.java @@ -39,7 +39,7 @@ import java.util.List; @RestController public class Users { @Inject - UserService userService; + private UserService userService; @RequestMapping(value = "/users", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public List<User> doGetUsers( diff --git a/juick-server-web/src/main/java/com/juick/server/util/HttpUtils.java b/juick-server-web/src/main/java/com/juick/server/util/HttpUtils.java index bf08f31e..971587a8 100644 --- a/juick-server-web/src/main/java/com/juick/server/util/HttpUtils.java +++ b/juick-server-web/src/main/java/com/juick/server/util/HttpUtils.java @@ -17,6 +17,7 @@ package com.juick.server.util; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -82,11 +83,7 @@ public class HttpUtils { attachmentFName = DigestUtils.md5Hex(UUID.randomUUID().toString()) + "." + attachmentType; fos = new FileOutputStream(Paths.get(tmpDir, attachmentFName).toString()); - byte[] buffer = new byte[10240]; - int len; - while ((len = is.read(buffer)) > 0) { - fos.write(buffer, 0, len); - } + IOUtils.copy(is, fos); } catch (Exception e) { ex = e; attachmentFName = null; |