mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Add channels page
This commit is contained in:
@@ -29,9 +29,11 @@ public class SecurityConfig {
|
||||
"/actuator/health",
|
||||
"/v3/api-docs/**",
|
||||
"/swagger-ui.html",
|
||||
"/swagger-ui/**"
|
||||
"/swagger-ui/**",
|
||||
"/channels"
|
||||
).permitAll()
|
||||
.requestMatchers(HttpMethod.GET, "/view/*/broadcast").permitAll()
|
||||
.requestMatchers(HttpMethod.GET, "/api/channels").permitAll()
|
||||
.requestMatchers(HttpMethod.GET, "/api/channels/*/assets/visible").permitAll()
|
||||
.requestMatchers(HttpMethod.GET, "/api/channels/*/canvas").permitAll()
|
||||
.requestMatchers(HttpMethod.GET, "/api/channels/*/assets/*/content").permitAll()
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.imgfloat.app.controller;
|
||||
|
||||
import com.imgfloat.app.service.ChannelDirectoryService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/channels")
|
||||
public class ChannelDirectoryApiController {
|
||||
|
||||
private final ChannelDirectoryService channelDirectoryService;
|
||||
|
||||
public ChannelDirectoryApiController(ChannelDirectoryService channelDirectoryService) {
|
||||
this.channelDirectoryService = channelDirectoryService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<String> listChannels(@RequestParam(value = "q", required = false) String query) {
|
||||
return channelDirectoryService.searchBroadcasters(query);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,12 @@ public class ViewController {
|
||||
return "index";
|
||||
}
|
||||
|
||||
@org.springframework.web.bind.annotation.GetMapping("/channels")
|
||||
public String channelDirectory() {
|
||||
LOG.info("Rendering channel directory");
|
||||
return "channels";
|
||||
}
|
||||
|
||||
@org.springframework.web.bind.annotation.GetMapping("/view/{broadcaster}/admin")
|
||||
public String adminView(@org.springframework.web.bind.annotation.PathVariable("broadcaster") String broadcaster,
|
||||
OAuth2AuthenticationToken authentication,
|
||||
|
||||
@@ -39,6 +39,8 @@ import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
@@ -75,6 +77,18 @@ public class ChannelDirectoryService {
|
||||
.orElseGet(() -> channelRepository.save(new Channel(normalized)));
|
||||
}
|
||||
|
||||
public List<String> searchBroadcasters(String query) {
|
||||
String normalizedQuery = normalize(query);
|
||||
return channelRepository.findAll().stream()
|
||||
.map(Channel::getBroadcaster)
|
||||
.map(this::normalize)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(name -> normalizedQuery == null || normalizedQuery.isBlank() || name.contains(normalizedQuery))
|
||||
.sorted()
|
||||
.limit(50)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public boolean addAdmin(String broadcaster, String username) {
|
||||
Channel channel = getOrCreateChannel(broadcaster);
|
||||
boolean added = channel.addAdmin(username);
|
||||
@@ -298,7 +312,7 @@ public class ChannelDirectoryService {
|
||||
}
|
||||
|
||||
private String normalize(String value) {
|
||||
return value == null ? null : value.toLowerCase();
|
||||
return value == null ? null : value.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private List<AssetView> sortAndMapAssets(String broadcaster, Collection<Asset> assets) {
|
||||
|
||||
Reference in New Issue
Block a user