|
|
@@ -1,5 +1,6 @@
|
|
|
package cn.reghao.oss.store.handler;
|
|
|
|
|
|
+import cn.reghao.jutil.jdk.web.result.WebResult;
|
|
|
import cn.reghao.oss.api.dto.FastUploadResult;
|
|
|
import cn.reghao.oss.api.dto.UploadResult;
|
|
|
import cn.reghao.oss.api.dto.WebBody;
|
|
|
@@ -87,12 +88,16 @@ public class OssUploadHandler extends SimpleChannelInboundHandler<HttpObject> {
|
|
|
String suffix = "mp4";
|
|
|
String objectName = String.format("%s/%s.%s", channelPrefix, objectId, suffix);
|
|
|
long uploadBy = (Long) ctx.channel().attr(AttributeKey.valueOf("uploadBy")).get();
|
|
|
- //FastUploadResult fastUploadResult = new FastUploadResult(clientSha256, filename, objectId, objectName, uploadBy);
|
|
|
- FastUploadResult fastUploadResult = new FastUploadResult();
|
|
|
if (clientSha256 != null && consoleService.checkExists(clientSha256)) {
|
|
|
log.info("触发秒传: {}", clientSha256);
|
|
|
+ FastUploadResult fastUploadResult = new FastUploadResult(clientSha256, filename, objectId, objectName, uploadBy);
|
|
|
consoleService.bindOnly(fastUploadResult);
|
|
|
- sendResponse(ctx, "{\"status\":\"success\", \"msg\":\"Fast Uploaded\"}");
|
|
|
+ String uploadId = fastUploadResult.getObjectId();
|
|
|
+ // 返回成功响应
|
|
|
+ String url = "";
|
|
|
+ UploadFileRet uploadFileRet = new UploadFileRet(uploadId, url, true);
|
|
|
+ String webResult = WebResult.success(uploadFileRet);
|
|
|
+ ResponseHelper.sendJsonResponse(ctx, webResult);
|
|
|
ctx.channel().attr(SKIP_BODY).set(true);
|
|
|
return;
|
|
|
}
|
|
|
@@ -106,19 +111,6 @@ public class OssUploadHandler extends SimpleChannelInboundHandler<HttpObject> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void sendResponse(ChannelHandlerContext ctx, String json) {
|
|
|
- FullHttpResponse response = new DefaultFullHttpResponse(
|
|
|
- HttpVersion.HTTP_1_1, HttpResponseStatus.OK,
|
|
|
- Unpooled.copiedBuffer(json, StandardCharsets.UTF_8));
|
|
|
-
|
|
|
- response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json; charset=UTF-8");
|
|
|
- response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
|
|
|
-
|
|
|
- // 如果是秒传,建议不要直接加 .addListener(ChannelFutureListener.CLOSE)
|
|
|
- // 除非你前端配合在收到响应后立即断开上传流
|
|
|
- ctx.writeAndFlush(response);
|
|
|
- }
|
|
|
-
|
|
|
private void handleUploadContent(ChannelHandlerContext ctx, HttpContent content) throws Exception {
|
|
|
// 1. 获取 JWT 授权的最大值
|
|
|
Long maxSize = ctx.channel().attr(StorageConstants.MAX_SIZE_KEY).get();
|