|
@@ -1,8 +1,11 @@
|
|
|
package cn.reghao.oss.store.controller;
|
|
package cn.reghao.oss.store.controller;
|
|
|
|
|
|
|
|
import cn.reghao.oss.store.api.constant.ChannelAction;
|
|
import cn.reghao.oss.store.api.constant.ChannelAction;
|
|
|
|
|
+import cn.reghao.oss.store.api.constant.ObjectScope;
|
|
|
import cn.reghao.oss.store.api.dto.ObjectChannel;
|
|
import cn.reghao.oss.store.api.dto.ObjectChannel;
|
|
|
|
|
+import cn.reghao.oss.store.api.dto.ObjectMeta;
|
|
|
import cn.reghao.oss.store.config.OssProperties;
|
|
import cn.reghao.oss.store.config.OssProperties;
|
|
|
|
|
+import cn.reghao.oss.store.db.repository.ObjectRepository;
|
|
|
import cn.reghao.oss.store.service.GetObjectService;
|
|
import cn.reghao.oss.store.service.GetObjectService;
|
|
|
import cn.reghao.oss.store.service.ObjectChannelService;
|
|
import cn.reghao.oss.store.service.ObjectChannelService;
|
|
|
import cn.reghao.oss.store.util.JwtUtil;
|
|
import cn.reghao.oss.store.util.JwtUtil;
|
|
@@ -15,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
-import java.util.List;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -28,13 +30,15 @@ public class ObjectGetController {
|
|
|
private final Cache<String, String> cache;
|
|
private final Cache<String, String> cache;
|
|
|
private final OssProperties ossProperties;
|
|
private final OssProperties ossProperties;
|
|
|
private final ObjectChannelService objectChannelService;
|
|
private final ObjectChannelService objectChannelService;
|
|
|
|
|
+ private final ObjectRepository objectRepository;
|
|
|
|
|
|
|
|
public ObjectGetController(GetObjectService getObjectService, OssProperties ossProperties,
|
|
public ObjectGetController(GetObjectService getObjectService, OssProperties ossProperties,
|
|
|
- ObjectChannelService objectChannelService) {
|
|
|
|
|
|
|
+ ObjectChannelService objectChannelService, ObjectRepository objectRepository) {
|
|
|
this.getObjectService = getObjectService;
|
|
this.getObjectService = getObjectService;
|
|
|
this.cache = Caffeine.newBuilder().maximumSize(10_000).expireAfterAccess(1, TimeUnit.HOURS).build();
|
|
this.cache = Caffeine.newBuilder().maximumSize(10_000).expireAfterAccess(1, TimeUnit.HOURS).build();
|
|
|
this.ossProperties = ossProperties;
|
|
this.ossProperties = ossProperties;
|
|
|
this.objectChannelService = objectChannelService;
|
|
this.objectChannelService = objectChannelService;
|
|
|
|
|
+ this.objectRepository = objectRepository;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/**", method = RequestMethod.HEAD)
|
|
@RequestMapping(value = "/**", method = RequestMethod.HEAD)
|
|
@@ -54,19 +58,16 @@ public class ObjectGetController {
|
|
|
@RequestParam(value = "sign", required = false) String sign,
|
|
@RequestParam(value = "sign", required = false) String sign,
|
|
|
@RequestParam(value = "client", required = false) String client) throws IOException {
|
|
@RequestParam(value = "client", required = false) String client) throws IOException {
|
|
|
String objectName = ObjectUtil.getObjectName();
|
|
String objectName = ObjectUtil.getObjectName();
|
|
|
- if (client != null && !client.isBlank()) {
|
|
|
|
|
- getObjectService.getObject(objectName);
|
|
|
|
|
|
|
+ ObjectMeta objectMeta = objectRepository.getObjectMeta(objectName);
|
|
|
|
|
+ if (objectMeta == null) {
|
|
|
|
|
+ getObjectService.writeResponse(HttpServletResponse.SC_NOT_FOUND);
|
|
|
|
|
+ return;
|
|
|
|
|
+ } else if (client != null && !client.isBlank()) {
|
|
|
|
|
+ getObjectService.getObject(objectMeta);
|
|
|
|
|
+ return;
|
|
|
|
|
+ } else if (objectMeta.getScope() == ObjectScope.PUBLIC.getCode()) {
|
|
|
|
|
+ getObjectService.getObject(objectMeta);
|
|
|
return;
|
|
return;
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- List<String> list = objectChannelService.getPublicChannels();
|
|
|
|
|
- if (!list.isEmpty()) {
|
|
|
|
|
- for (String prefix : list) {
|
|
|
|
|
- if (objectName.startsWith(prefix)) {
|
|
|
|
|
- getObjectService.getObject(objectName);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String queryString = String.format("token=%s&t=%s&nonce=%s", token, timestamp, nonce);
|
|
String queryString = String.format("token=%s&t=%s&nonce=%s", token, timestamp, nonce);
|
|
@@ -114,9 +115,9 @@ public class ObjectGetController {
|
|
|
|
|
|
|
|
String action = ossPayload.getAction();
|
|
String action = ossPayload.getAction();
|
|
|
if (ChannelAction.access.getName().equals(action)) {
|
|
if (ChannelAction.access.getName().equals(action)) {
|
|
|
- getObjectService.getObject(objectName);
|
|
|
|
|
|
|
+ getObjectService.getObject(objectMeta);
|
|
|
} else if (ChannelAction.download.getName().equals(action)) {
|
|
} else if (ChannelAction.download.getName().equals(action)) {
|
|
|
- getObjectService.downloadObject(objectName);
|
|
|
|
|
|
|
+ getObjectService.writeDownloadContent(objectMeta);
|
|
|
} else {
|
|
} else {
|
|
|
String payload = String.format("channel action %s not matched", action);
|
|
String payload = String.format("channel action %s not matched", action);
|
|
|
getObjectService.writeResponse(HttpServletResponse.SC_FORBIDDEN, payload);
|
|
getObjectService.writeResponse(HttpServletResponse.SC_FORBIDDEN, payload);
|