优化截图获取接口

This commit is contained in:
648540858
2023-06-05 11:10:15 +08:00
parent 2ef4111297
commit db3240d918
5 changed files with 67 additions and 7 deletions

View File

@@ -466,10 +466,12 @@ public class DeviceQuery {
@Operation(summary = "请求截图")
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号", required = true)
public void getSnap(HttpServletResponse resp, @PathVariable String deviceId, @PathVariable String channelId) {
@Parameter(name = "mark", description = "标识", required = false)
public void getSnap(HttpServletResponse resp, @PathVariable String deviceId, @PathVariable String channelId, @RequestParam(required = false) String mark) {
try {
final InputStream in = Files.newInputStream(new File("snap" + File.separator + deviceId + "_" + channelId + ".jpg").toPath());
final InputStream in = Files.newInputStream(new File("snap" + File.separator + deviceId + "_" + channelId + (mark == null? ".jpg": ("_" + mark + ".jpg"))).toPath());
resp.setContentType(MediaType.IMAGE_PNG_VALUE);
IOUtils.copy(in, resp.getOutputStream());
} catch (IOException e) {

View File

@@ -26,6 +26,7 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.SnapPath;
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import io.swagger.v3.oas.annotations.Operation;
@@ -40,6 +41,7 @@ import org.springframework.web.context.request.async.DeferredResult;
import javax.servlet.http.HttpServletRequest;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import java.io.File;
import java.text.ParseException;
import java.util.List;
import java.util.UUID;
@@ -342,7 +344,7 @@ public class PlayController {
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号", required = true)
@GetMapping("/snap")
public DeferredResult<String> getSnap(String deviceId, String channelId) {
public DeferredResult<String> getSnap(HttpServletRequest request, String deviceId, String channelId) {
if (logger.isDebugEnabled()) {
logger.debug("获取截图: {}/{}", deviceId, channelId);
}
@@ -355,11 +357,16 @@ public class PlayController {
RequestMessage message = new RequestMessage();
message.setKey(key);
message.setId(uuid);
String nowForUrl = DateUtil.getNowForUrl();
String fileName = deviceId + "_" + channelId + "_" + nowForUrl + ".jpg";
String fileName = deviceId + "_" + channelId + "_" + DateUtil.getNowForUrl() + ".jpg";
playService.getSnap(deviceId, channelId, fileName, (code, msg, data) -> {
if (code == InviteErrorCode.SUCCESS.getCode()) {
message.setData(data);
File snapFile = new File((String)data);
String fileNameForUrl = deviceId + "/" + channelId + "?mark=" + nowForUrl;
String uri = request.getRequestURL().toString().replace(request.getRequestURI(), "/api/device/query/snap/" + fileNameForUrl);
SnapPath snapPath = SnapPath.getInstance((String) data, snapFile.getAbsolutePath(), uri);
message.setData(snapPath);
}else {
message.setData(WVPResult.fail(code, msg));
}