Files
hls-proxy/src/main/java/com/backend/hls/proxy/controller/ProxyController.java

31 lines
1.2 KiB
Java

package com.backend.hls.proxy.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import com.backend.hls.proxy.exception.FetchFailException;
import com.backend.hls.proxy.exception.PlaylistParseException;
import com.backend.hls.proxy.service.PlaylistProxyService;
@RestController
public class ProxyController {
private final PlaylistProxyService playlistProxyService;
public ProxyController(PlaylistProxyService playlistProxyService) {
this.playlistProxyService = playlistProxyService;
}
@GetMapping("/proxy")
public ResponseEntity<?> proxy(@RequestParam("url") String url) throws FetchFailException, PlaylistParseException {
String fullUrl = ServletUriComponentsBuilder.fromCurrentRequestUri().build().toUriString();
String baseUrl = fullUrl.substring(0, fullUrl.indexOf("/", 8));
String result = playlistProxyService.proxyPlaylist(url, baseUrl);
return ResponseEntity.ok(result);
}
}