mirror of
https://github.com/imgfloat/server.git
synced 2026-05-08 10:19:35 +00:00
refactor: migrate remaining Locale.ROOT toLowerCaseRoot calls to StringNormalizer in service layer
This commit is contained in:
@@ -3,6 +3,7 @@ package dev.kruhlmann.imgfloat.service;
|
|||||||
import dev.kruhlmann.imgfloat.model.api.response.ScriptMarketplaceEntry;
|
import dev.kruhlmann.imgfloat.model.api.response.ScriptMarketplaceEntry;
|
||||||
import dev.kruhlmann.imgfloat.service.media.AssetContent;
|
import dev.kruhlmann.imgfloat.service.media.AssetContent;
|
||||||
import dev.kruhlmann.imgfloat.util.AllowedDomainNormalizer;
|
import dev.kruhlmann.imgfloat.util.AllowedDomainNormalizer;
|
||||||
|
import dev.kruhlmann.imgfloat.util.StringNormalizer;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.DirectoryStream;
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -10,7 +11,6 @@ import java.nio.file.Path;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
@@ -61,7 +61,7 @@ public class MarketplaceScriptSeedLoader {
|
|||||||
if (scripts.isEmpty()) {
|
if (scripts.isEmpty()) {
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
String normalized = query == null ? null : query.toLowerCase(Locale.ROOT);
|
String normalized = query == null ? null : StringNormalizer.toLowerCaseRoot(query);
|
||||||
return scripts
|
return scripts
|
||||||
.stream()
|
.stream()
|
||||||
.filter((script) -> script.matchesQuery(normalized))
|
.filter((script) -> script.matchesQuery(normalized))
|
||||||
@@ -104,8 +104,8 @@ public class MarketplaceScriptSeedLoader {
|
|||||||
if (normalized == null || normalized.isBlank()) {
|
if (normalized == null || normalized.isBlank()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String entryName = Optional.ofNullable(name).orElse("").toLowerCase(Locale.ROOT);
|
String entryName = StringNormalizer.toLowerCaseRoot(Optional.ofNullable(name).orElse(""));
|
||||||
String entryDescription = Optional.ofNullable(description).orElse("").toLowerCase(Locale.ROOT);
|
String entryDescription = StringNormalizer.toLowerCaseRoot(Optional.ofNullable(description).orElse(""));
|
||||||
return entryName.contains(normalized) || entryDescription.contains(normalized);
|
return entryName.contains(normalized) || entryDescription.contains(normalized);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ public class MarketplaceScriptSeedLoader {
|
|||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LOG.warn("Failed to detect media type for {}", attachment, ex);
|
LOG.warn("Failed to detect media type for {}", attachment, ex);
|
||||||
}
|
}
|
||||||
String filename = attachment.getFileName().toString().toLowerCase(Locale.ROOT);
|
String filename = StringNormalizer.toLowerCaseRoot(attachment.getFileName().toString());
|
||||||
int dot = filename.lastIndexOf('.');
|
int dot = filename.lastIndexOf('.');
|
||||||
if (dot > -1 && dot < filename.length() - 1) {
|
if (dot > -1 && dot < filename.length() - 1) {
|
||||||
String extension = filename.substring(dot + 1);
|
String extension = filename.substring(dot + 1);
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ import dev.kruhlmann.imgfloat.repository.ScriptAssetFileRepository;
|
|||||||
import dev.kruhlmann.imgfloat.repository.ScriptAssetRepository;
|
import dev.kruhlmann.imgfloat.repository.ScriptAssetRepository;
|
||||||
import dev.kruhlmann.imgfloat.service.media.AssetContent;
|
import dev.kruhlmann.imgfloat.service.media.AssetContent;
|
||||||
import dev.kruhlmann.imgfloat.util.AllowedDomainNormalizer;
|
import dev.kruhlmann.imgfloat.util.AllowedDomainNormalizer;
|
||||||
|
import dev.kruhlmann.imgfloat.util.StringNormalizer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -64,7 +64,7 @@ public class MarketplaceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<ScriptMarketplaceEntry> listScripts(String query, String sessionUsername) {
|
public List<ScriptMarketplaceEntry> listScripts(String query, String sessionUsername) {
|
||||||
String normalized = query == null ? null : query.strip().toLowerCase(Locale.ROOT);
|
String normalized = query == null ? null : StringNormalizer.normalize(query);
|
||||||
if (normalized != null && normalized.isBlank()) {
|
if (normalized != null && normalized.isBlank()) {
|
||||||
normalized = null;
|
normalized = null;
|
||||||
}
|
}
|
||||||
@@ -85,8 +85,8 @@ public class MarketplaceService {
|
|||||||
.filter(script -> {
|
.filter(script -> {
|
||||||
String name = Optional.ofNullable(script.getName()).orElse("");
|
String name = Optional.ofNullable(script.getName()).orElse("");
|
||||||
String desc = Optional.ofNullable(script.getDescription()).orElse("");
|
String desc = Optional.ofNullable(script.getDescription()).orElse("");
|
||||||
return name.toLowerCase(Locale.ROOT).contains(queryFilter)
|
return StringNormalizer.toLowerCaseRoot(name).contains(queryFilter)
|
||||||
|| desc.toLowerCase(Locale.ROOT).contains(queryFilter);
|
|| StringNormalizer.toLowerCaseRoot(desc).contains(queryFilter);
|
||||||
})
|
})
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import dev.kruhlmann.imgfloat.util.StringNormalizer;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -71,7 +71,7 @@ public class SevenTvEmoteService {
|
|||||||
if (channelLogin == null || channelLogin.isBlank()) {
|
if (channelLogin == null || channelLogin.isBlank()) {
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
String normalized = channelLogin.toLowerCase(Locale.ROOT);
|
String normalized = StringNormalizer.toLowerCaseRoot(channelLogin);
|
||||||
List<CachedEmote> emotes = channelEmoteCache.computeIfAbsent(normalized, this::fetchChannelEmotes);
|
List<CachedEmote> emotes = channelEmoteCache.computeIfAbsent(normalized, this::fetchChannelEmotes);
|
||||||
return emotes.stream().map(CachedEmote::descriptor).toList();
|
return emotes.stream().map(CachedEmote::descriptor).toList();
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ public class SevenTvEmoteService {
|
|||||||
if (channelLogin == null || channelLogin.isBlank()) {
|
if (channelLogin == null || channelLogin.isBlank()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String normalized = channelLogin.toLowerCase(Locale.ROOT);
|
String normalized = StringNormalizer.toLowerCaseRoot(channelLogin);
|
||||||
channelEmoteCache.put(normalized, fetchChannelEmotes(normalized));
|
channelEmoteCache.put(normalized, fetchChannelEmotes(normalized));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,7 +260,7 @@ public class SevenTvEmoteService {
|
|||||||
if (path == null) {
|
if (path == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String name = path.getFileName().toString().toLowerCase(Locale.ROOT);
|
String name = StringNormalizer.toLowerCaseRoot(path.getFileName().toString());
|
||||||
if (name.endsWith(".gif")) {
|
if (name.endsWith(".gif")) {
|
||||||
return MediaType.IMAGE_GIF;
|
return MediaType.IMAGE_GIF;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import dev.kruhlmann.imgfloat.util.StringNormalizer;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@@ -89,7 +89,7 @@ public class TwitchEmoteService {
|
|||||||
if (channelLogin == null || channelLogin.isBlank()) {
|
if (channelLogin == null || channelLogin.isBlank()) {
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
String normalized = channelLogin.toLowerCase(Locale.ROOT);
|
String normalized = StringNormalizer.toLowerCaseRoot(channelLogin);
|
||||||
List<CachedEmote> emotes = channelEmoteCache.computeIfAbsent(normalized, this::fetchChannelEmotes);
|
List<CachedEmote> emotes = channelEmoteCache.computeIfAbsent(normalized, this::fetchChannelEmotes);
|
||||||
return emotes.stream().map(CachedEmote::descriptor).toList();
|
return emotes.stream().map(CachedEmote::descriptor).toList();
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ public class TwitchEmoteService {
|
|||||||
if (channelLogin == null || channelLogin.isBlank()) {
|
if (channelLogin == null || channelLogin.isBlank()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String normalized = channelLogin.toLowerCase(Locale.ROOT);
|
String normalized = StringNormalizer.toLowerCaseRoot(channelLogin);
|
||||||
channelEmoteCache.put(normalized, fetchChannelEmotes(normalized));
|
channelEmoteCache.put(normalized, fetchChannelEmotes(normalized));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,7 +329,7 @@ public class TwitchEmoteService {
|
|||||||
if (path == null) {
|
if (path == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String name = path.getFileName().toString().toLowerCase(Locale.ROOT);
|
String name = StringNormalizer.toLowerCaseRoot(path.getFileName().toString());
|
||||||
if (name.endsWith(".gif")) {
|
if (name.endsWith(".gif")) {
|
||||||
return MediaType.IMAGE_GIF;
|
return MediaType.IMAGE_GIF;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user