mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: server CDR files under /cdr/FILE.log. REST GET /cdr
parent
02f49e0467
commit
3ca64d9cca
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* (C) Copyright 2017-2019 OpenVidu (https://openvidu.io/)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.openvidu.server.cdr;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import io.openvidu.server.config.OpenviduConfig;
|
||||
|
||||
@Configuration
|
||||
public class CDRHttpHandler implements WebMvcConfigurer {
|
||||
|
||||
@Autowired
|
||||
OpenviduConfig openviduConfig;
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
String cdrPath = openviduConfig.getOpenviduCdrPath();
|
||||
cdrPath = cdrPath.endsWith("/") ? cdrPath : cdrPath + "/";
|
||||
registry.addResourceHandler("/cdr/**.log").addResourceLocations("file:" + cdrPath);
|
||||
}
|
||||
|
||||
}
|
|
@ -50,9 +50,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||
.antMatchers(HttpMethod.POST, "/api/recordings/start").authenticated()
|
||||
.antMatchers(HttpMethod.POST, "/api/recordings/stop").authenticated()
|
||||
.antMatchers(HttpMethod.DELETE, "/api/recordings/**").authenticated()
|
||||
// /api/config
|
||||
// /config
|
||||
.antMatchers(HttpMethod.GET, "/config/openvidu-publicurl").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/config/**").authenticated()
|
||||
// /cdr
|
||||
.antMatchers(HttpMethod.GET, "/cdr/**").authenticated()
|
||||
// Dashboard
|
||||
.antMatchers("/").authenticated();
|
||||
|
||||
|
@ -71,7 +73,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||
|
||||
@Autowired
|
||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.inMemoryAuthentication().withUser("OPENVIDUAPP").password("{noop}" + openviduConf.getOpenViduSecret()).roles("ADMIN");
|
||||
auth.inMemoryAuthentication().withUser("OPENVIDUAPP").password("{noop}" + openviduConf.getOpenViduSecret())
|
||||
.roles("ADMIN");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* (C) Copyright 2017-2019 OpenVidu (https://openvidu.io/)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.openvidu.server.rest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
|
||||
import io.openvidu.server.config.OpenviduConfig;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Pablo Fuente (pablofuenteperez@gmail.com)
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/cdr")
|
||||
public class CDRRestController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(CDRRestController.class);
|
||||
|
||||
@Autowired
|
||||
protected OpenviduConfig openviduConfig;
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public ResponseEntity<String> listCdrFiles() {
|
||||
|
||||
log.info("REST API: GET /cdr");
|
||||
|
||||
String cdrPath = openviduConfig.getOpenviduCdrPath();
|
||||
JsonArray cdrFiles = new JsonArray();
|
||||
|
||||
try (Stream<Path> walk = Files.walk(Paths.get(cdrPath))) {
|
||||
List<String> result = walk.filter(Files::isRegularFile).map(x -> x.getFileName().toString())
|
||||
.collect(Collectors.toList());
|
||||
result.forEach(fileName -> cdrFiles.add(fileName));
|
||||
} catch (IOException e) {
|
||||
log.error("Error listing CDR files in path {}: {}", cdrPath, e.getMessage());
|
||||
}
|
||||
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
return new ResponseEntity<>(cdrFiles.toString(), responseHeaders, HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue