This commit is contained in:
2025-04-09 16:18:58 +08:00
parent 73d393b436
commit d0d4e37526
23 changed files with 344 additions and 58 deletions

View File

@ -3,7 +3,6 @@ package com.ycwl.basic.controller.pc;
import com.ycwl.basic.model.pc.broker.entity.BrokerEntity;
import com.ycwl.basic.model.pc.broker.req.BrokerRecordReqQuery;
import com.ycwl.basic.model.pc.broker.req.BrokerReqQuery;
import com.ycwl.basic.model.pc.broker.resp.BrokerRecordRespVO;
import com.ycwl.basic.model.pc.broker.resp.BrokerRespVO;
import com.ycwl.basic.model.pc.broker.resp.DailySummaryRespVO;
import com.ycwl.basic.service.pc.BrokerRecordService;
@ -131,7 +130,7 @@ public class BrokerController {
try {
WxMpUtil.generateWXAQRCode(appId, appSecret, appState, path, filePath);
File file = new File(filePath);
String s = adapter.uploadFile(file, filePath);
String s = adapter.uploadFile(null, file, filePath);
file.delete();
adapter.setAcl(StorageAcl.PUBLIC_READ, filePath);
return ApiResponse.success(s);

View File

@ -121,7 +121,7 @@ public class ScenicController {
try {
WxMpUtil.generateWXAQRCode(appId, appSecret, appState, path, filePath);
File file = new File(filePath);
String s = adapter.uploadFile(file, filePath);
String s = adapter.uploadFile(null, file, filePath);
file.delete();
adapter.setAcl(StorageAcl.PUBLIC_READ, filePath);
return ApiResponse.success(s);

View File

@ -0,0 +1,75 @@
package com.ycwl.basic.controller.proxy;
import com.ycwl.basic.annotation.IgnoreToken;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
@RestController
public class ProxyController {
@IgnoreToken
@RequestMapping(value = "/proxy", method = RequestMethod.GET)
public void proxy(@RequestParam(value = "url") String url,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "http://" + url; // 或根据业务逻辑选择默认协议
}
// 新增User-Agent检测逻辑
String userAgent = request.getHeader("User-Agent");
if (userAgent != null && userAgent.contains("Lavf/")) {
response.sendRedirect(url);
return;
}
// 创建HTTP连接
URL urlObj = new URL(url);
HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
// 设置请求方法和请求头
connection.setRequestMethod("GET");
for (Enumeration<String> headers = request.getHeaderNames(); headers.hasMoreElements();) {
String headerName = headers.nextElement();
connection.addRequestProperty(headerName, request.getHeader(headerName));
}
// 处理响应
int responseCode = connection.getResponseCode();
response.setStatus(responseCode);
// 转发响应头
Map<String, List<String>> headerFields = connection.getHeaderFields();
for (Map.Entry<String, List<String>> entry : headerFields.entrySet()) {
if (entry.getKey() != null) {
for (String value : entry.getValue()) {
response.addHeader(entry.getKey(), value);
}
}
}
// 流式传输响应体
try (InputStream inputStream = connection.getInputStream();
OutputStream outputStream = response.getOutputStream()) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
} catch (IOException e) {
return;
}
}
}

View File

@ -40,7 +40,7 @@ public class VptController {
}
@PostMapping("/scenic/{scenicId}/{taskId}/uploadUrl")
public String uploadUrl(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId) {
IStorageAdapter adapter = scenicService.getScenicStorageAdapter(scenicId);
IStorageAdapter adapter = scenicService.getScenicTmpStorageAdapter(scenicId);
String filename = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, taskId.toString() + ".mp4");
String urlForUpload = adapter.getUrlForUpload(new Date(System.currentTimeMillis() + 1000 * 60 * 60), "video/mp4", filename);
urlForUpload = urlForUpload.replace("-internal.aliyuncs.com", ".aliyuncs.com");
@ -48,7 +48,7 @@ public class VptController {
}
@PostMapping("/scenic/{scenicId}/{taskId}/success")
public ApiResponse<String> success(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId, @RequestBody FileObject fileObject) {
IStorageAdapter adapter = scenicService.getScenicStorageAdapter(scenicId);
IStorageAdapter adapter = scenicService.getScenicTmpStorageAdapter(scenicId);
String filename = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, taskId.toString() + ".mp4");
fileObject.setUrl(adapter.getUrl(filename));
adapter.setAcl(StorageAcl.PUBLIC_READ, filename);

View File

@ -45,7 +45,7 @@ public class WvpController {
@PostMapping("/scenic/{scenicId}/{taskId}/uploadUrl")
public String uploadUrl(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId) {
IStorageAdapter adapter = scenicService.getScenicStorageAdapter(scenicId);
IStorageAdapter adapter = scenicService.getScenicTmpStorageAdapter(scenicId);
String filename = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, taskId.toString() + ".mp4");
String urlForUpload = adapter.getUrlForUpload(new Date(System.currentTimeMillis() + 1000 * 60 * 60), "video/mp4", filename);
urlForUpload = urlForUpload.replace("-internal.aliyuncs.com", ".aliyuncs.com");
@ -53,7 +53,7 @@ public class WvpController {
}
@PostMapping("/scenic/{scenicId}/{taskId}/success")
public ApiResponse<String> success(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId, @RequestBody FileObject fileObject) {
IStorageAdapter adapter = scenicService.getScenicStorageAdapter(scenicId);
IStorageAdapter adapter = scenicService.getScenicTmpStorageAdapter(scenicId);
String filename = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, taskId.toString() + ".mp4");
fileObject.setUrl(adapter.getUrl(filename));
adapter.setAcl(StorageAcl.PUBLIC_READ, filename);