mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Fix code smells
This commit is contained in:
@@ -12,6 +12,7 @@ import org.springframework.security.oauth2.client.registration.ClientRegistratio
|
|||||||
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
|
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures Twitch token requests always include {@code client_id} and {@code client_secret} in the
|
* Ensures Twitch token requests always include {@code client_id} and {@code client_secret} in the
|
||||||
@@ -25,7 +26,7 @@ final class TwitchAuthorizationCodeGrantRequestEntityConverter
|
|||||||
new OAuth2AuthorizationCodeGrantRequestEntityConverter();
|
new OAuth2AuthorizationCodeGrantRequestEntityConverter();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RequestEntity<?> convert(OAuth2AuthorizationCodeGrantRequest request) {
|
public @Nullable RequestEntity<?> convert(@Nullable OAuth2AuthorizationCodeGrantRequest request) {
|
||||||
RequestEntity<?> entity = delegate.convert(request);
|
RequestEntity<?> entity = delegate.convert(request);
|
||||||
if (entity == null || !(entity.getBody() instanceof MultiValueMap<?, ?> existingBody)) {
|
if (entity == null || !(entity.getBody() instanceof MultiValueMap<?, ?> existingBody)) {
|
||||||
return entity;
|
return entity;
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class ChannelApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/admins")
|
@PostMapping("/admins")
|
||||||
public ResponseEntity<?> addAdmin(
|
public ResponseEntity<Boolean> addAdmin(
|
||||||
@PathVariable("broadcaster") String broadcaster,
|
@PathVariable("broadcaster") String broadcaster,
|
||||||
@Valid @RequestBody AdminRequest request,
|
@Valid @RequestBody AdminRequest request,
|
||||||
OAuth2AuthenticationToken oauthToken
|
OAuth2AuthenticationToken oauthToken
|
||||||
@@ -86,7 +86,7 @@ public class ChannelApiController {
|
|||||||
if (!added) {
|
if (!added) {
|
||||||
LOG.info("User {} already admin for {} or could not be added", logRequestUsername, logBroadcaster);
|
LOG.info("User {} already admin for {} or could not be added", logRequestUsername, logBroadcaster);
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok().body(added);
|
return ResponseEntity.ok(added);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/admins")
|
@GetMapping("/admins")
|
||||||
@@ -156,7 +156,7 @@ public class ChannelApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/admins/{username}")
|
@DeleteMapping("/admins/{username}")
|
||||||
public ResponseEntity<?> removeAdmin(
|
public ResponseEntity<Boolean> removeAdmin(
|
||||||
@PathVariable("broadcaster") String broadcaster,
|
@PathVariable("broadcaster") String broadcaster,
|
||||||
@PathVariable("username") String username,
|
@PathVariable("username") String username,
|
||||||
OAuth2AuthenticationToken oauthToken
|
OAuth2AuthenticationToken oauthToken
|
||||||
@@ -168,7 +168,7 @@ public class ChannelApiController {
|
|||||||
authorizationService.userMatchesSessionUsernameOrThrowHttpError(broadcaster, sessionUsername);
|
authorizationService.userMatchesSessionUsernameOrThrowHttpError(broadcaster, sessionUsername);
|
||||||
LOG.info("User {} removing admin {} from {}", logSessionUsername, logUsername, logBroadcaster);
|
LOG.info("User {} removing admin {} from {}", logSessionUsername, logUsername, logBroadcaster);
|
||||||
boolean removed = channelDirectoryService.removeAdmin(broadcaster, username);
|
boolean removed = channelDirectoryService.removeAdmin(broadcaster, username);
|
||||||
return ResponseEntity.ok().body(removed);
|
return ResponseEntity.ok(removed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/assets")
|
@GetMapping("/assets")
|
||||||
@@ -369,7 +369,7 @@ public class ChannelApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/assets/{assetId}")
|
@DeleteMapping("/assets/{assetId}")
|
||||||
public ResponseEntity<?> delete(
|
public ResponseEntity<Void> delete(
|
||||||
@PathVariable("broadcaster") String broadcaster,
|
@PathVariable("broadcaster") String broadcaster,
|
||||||
@PathVariable("assetId") String assetId,
|
@PathVariable("assetId") String assetId,
|
||||||
OAuth2AuthenticationToken oauthToken
|
OAuth2AuthenticationToken oauthToken
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import dev.kruhlmann.imgfloat.service.SettingsService;
|
|||||||
import dev.kruhlmann.imgfloat.service.VersionService;
|
import dev.kruhlmann.imgfloat.service.VersionService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
|
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
@@ -28,22 +27,22 @@ public class ViewController {
|
|||||||
private final SettingsService settingsService;
|
private final SettingsService settingsService;
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
private final AuthorizationService authorizationService;
|
private final AuthorizationService authorizationService;
|
||||||
|
private final long uploadLimitBytes;
|
||||||
@Autowired
|
|
||||||
private long uploadLimitBytes;
|
|
||||||
|
|
||||||
public ViewController(
|
public ViewController(
|
||||||
ChannelDirectoryService channelDirectoryService,
|
ChannelDirectoryService channelDirectoryService,
|
||||||
VersionService versionService,
|
VersionService versionService,
|
||||||
SettingsService settingsService,
|
SettingsService settingsService,
|
||||||
ObjectMapper objectMapper,
|
ObjectMapper objectMapper,
|
||||||
AuthorizationService authorizationService
|
AuthorizationService authorizationService,
|
||||||
|
long uploadLimitBytes
|
||||||
) {
|
) {
|
||||||
this.channelDirectoryService = channelDirectoryService;
|
this.channelDirectoryService = channelDirectoryService;
|
||||||
this.versionService = versionService;
|
this.versionService = versionService;
|
||||||
this.settingsService = settingsService;
|
this.settingsService = settingsService;
|
||||||
this.objectMapper = objectMapper;
|
this.objectMapper = objectMapper;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
|
this.uploadLimitBytes = uploadLimitBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@org.springframework.web.bind.annotation.GetMapping("/")
|
@org.springframework.web.bind.annotation.GetMapping("/")
|
||||||
|
|||||||
@@ -2,12 +2,8 @@ package dev.kruhlmann.imgfloat.service;
|
|||||||
|
|
||||||
import dev.kruhlmann.imgfloat.model.Asset;
|
import dev.kruhlmann.imgfloat.model.Asset;
|
||||||
import dev.kruhlmann.imgfloat.repository.AssetRepository;
|
import dev.kruhlmann.imgfloat.repository.AssetRepository;
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Stream;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -58,7 +57,7 @@ public class AssetStorageService {
|
|||||||
Files.createDirectories(this.assetRoot);
|
Files.createDirectories(this.assetRoot);
|
||||||
Files.createDirectories(this.previewRoot);
|
Files.createDirectories(this.previewRoot);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Failed to create asset storage directories", e);
|
throw new IllegalStateException("Failed to create asset storage directories", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +76,7 @@ public class AssetStorageService {
|
|||||||
StandardOpenOption.TRUNCATE_EXISTING,
|
StandardOpenOption.TRUNCATE_EXISTING,
|
||||||
StandardOpenOption.WRITE
|
StandardOpenOption.WRITE
|
||||||
);
|
);
|
||||||
logger.info("Wrote asset to {}", file.toString());
|
logger.info("Wrote asset to {}", file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void storePreview(String broadcaster, String assetId, byte[] previewBytes) throws IOException {
|
public void storePreview(String broadcaster, String assetId, byte[] previewBytes) throws IOException {
|
||||||
@@ -93,7 +92,7 @@ public class AssetStorageService {
|
|||||||
StandardOpenOption.TRUNCATE_EXISTING,
|
StandardOpenOption.TRUNCATE_EXISTING,
|
||||||
StandardOpenOption.WRITE
|
StandardOpenOption.WRITE
|
||||||
);
|
);
|
||||||
logger.info("Wrote asset to {}", file.toString());
|
logger.info("Wrote asset to {}", file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<AssetContent> loadAssetFile(Asset asset) {
|
public Optional<AssetContent> loadAssetFile(Asset asset) {
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ import static org.springframework.http.HttpStatus.FORBIDDEN;
|
|||||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||||
import static org.springframework.http.HttpStatus.UNAUTHORIZED;
|
import static org.springframework.http.HttpStatus.UNAUTHORIZED;
|
||||||
|
|
||||||
import dev.kruhlmann.imgfloat.model.OauthSessionUser;
|
|
||||||
import dev.kruhlmann.imgfloat.service.ChannelDirectoryService;
|
|
||||||
import dev.kruhlmann.imgfloat.service.SystemAdministratorService;
|
|
||||||
import dev.kruhlmann.imgfloat.util.LogSanitizer;
|
import dev.kruhlmann.imgfloat.util.LogSanitizer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|||||||
Reference in New Issue
Block a user