|
|
@@ -2,19 +2,17 @@ package cn.reghao.tnb.file.app.rpc;
|
|
|
|
|
|
import cn.reghao.file.api.iface.OssService;
|
|
|
import cn.reghao.oss.api.constant.ObjectAction;
|
|
|
-import cn.reghao.oss.sdk.OssClient;
|
|
|
import cn.reghao.oss.api.constant.ObjectScope;
|
|
|
+import cn.reghao.oss.api.dto.ObjectChannel;
|
|
|
import cn.reghao.oss.api.dto.ObjectInfo;
|
|
|
import cn.reghao.oss.api.dto.ServerInfo;
|
|
|
-import cn.reghao.oss.api.dto.media.AudioInfo;
|
|
|
-import cn.reghao.oss.api.dto.media.ConvertedImageInfo;
|
|
|
-import cn.reghao.oss.api.dto.media.ImageInfo;
|
|
|
import cn.reghao.oss.api.dto.media.VideoInfo;
|
|
|
-import cn.reghao.tnb.file.app.db.mapper.OssConfigMapper;
|
|
|
+import cn.reghao.oss.api.dto.rest.UploadFileRet;
|
|
|
+import cn.reghao.oss.api.dto.rest.UploadPrepare;
|
|
|
+import cn.reghao.oss.api.dto.rest.UploadPrepareRet;
|
|
|
+import cn.reghao.oss.api.dto.rest.UploadSample;
|
|
|
import cn.reghao.tnb.file.app.model.constant.OssType;
|
|
|
-import cn.reghao.tnb.file.app.model.po.OssConfig;
|
|
|
-import cn.reghao.tnb.file.app.service.StoreConfigService;
|
|
|
-import jakarta.annotation.PostConstruct;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -22,160 +20,87 @@ import org.springframework.stereotype.Service;
|
|
|
* @author reghao
|
|
|
* @date 2024-07-03 14:40:25
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@DubboService
|
|
|
@Service
|
|
|
public class StoreServiceWrapperRouter implements OssService {
|
|
|
private final int ossType = 1;
|
|
|
- private final StoreConfigService storeConfigService;
|
|
|
- private final OssConfigMapper ossConfigMapper;
|
|
|
- private OssClient ossClient;
|
|
|
+ private final OssClientManager ossClientManager;
|
|
|
|
|
|
- public StoreServiceWrapperRouter(StoreConfigService storeConfigService, OssConfigMapper ossConfigMapper) {
|
|
|
- this.storeConfigService = storeConfigService;
|
|
|
- this.ossConfigMapper = ossConfigMapper;
|
|
|
- }
|
|
|
-
|
|
|
- @PostConstruct
|
|
|
- public void init() {
|
|
|
- OssConfig ossConfig = ossConfigMapper.findByOssType(ossType);
|
|
|
- String endpoint = ossConfig.getEndpoint();
|
|
|
- String ak = ossConfig.getAccessKeyId();
|
|
|
- String sk = ossConfig.getAccessKeySecret();
|
|
|
- this.ossClient = new OssClient(endpoint, ak, sk);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public ServerInfo getUploadStore(String channelName) throws Exception {
|
|
|
- /*int ossUser = storeConfigService.getLocalOssUser();
|
|
|
- UploadChannel uploadChannel = storeRepository.getUploadChannel(ossUser, channelName);*/
|
|
|
- int channelCode = 101;
|
|
|
- return ossClient.getServerInfo();
|
|
|
+ public StoreServiceWrapperRouter(OssClientManager ossClientManager) {
|
|
|
+ this.ossClientManager = ossClientManager;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Integer getChannelScope(int channelCode) {
|
|
|
- /*try {
|
|
|
- if (ossType == OssType.localOss.getCode()) {
|
|
|
- OssConsoleClient ossConsoleClient = ossConsoleClientFactory.getOssConsoleClient();
|
|
|
- return ossConsoleClient.getChannelScope(channelCode);
|
|
|
- } else if (ossType == OssType.aliyunOss.getCode()) {
|
|
|
- }
|
|
|
+ public ServerInfo getUploadStore(int channelCode) {
|
|
|
+ try {
|
|
|
+ return ossClientManager.getOssClient().getServerInfo(channelCode);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }*/
|
|
|
- return ObjectScope.PRIVATE.getCode();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void setObjectUpload(int channelCode, String objectId) throws Exception {
|
|
|
- int ossUser = storeConfigService.getLocalOssUser();
|
|
|
- if (ossType == OssType.localOss.getCode()) {
|
|
|
- //storeServiceWrapper.setObjectUpload(channelCode, objectId, ossUser);
|
|
|
- } else if (ossType == OssType.aliyunOss.getCode()) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void setObjectScope(int channelCode, String objectId, int scope) throws Exception {
|
|
|
- int ossUser = storeConfigService.getLocalOssUser();
|
|
|
- if (ossType == OssType.localOss.getCode()) {
|
|
|
- //storeServiceWrapper.setObjectScope(channelCode, objectId, scope, ossUser);
|
|
|
- ossClient.setObjectScope(objectId);
|
|
|
- } else if (ossType == OssType.aliyunOss.getCode()) {
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void deleteByObjectId(int channelCode, String objectId) throws Exception {
|
|
|
- int ossUser = storeConfigService.getLocalOssUser();
|
|
|
- if (ossType == OssType.localOss.getCode()) {
|
|
|
- //storeServiceWrapper.deleteByObjectId(channelCode, objectId, ossUser);
|
|
|
- ossClient.deleteObject(objectId);
|
|
|
- } else if (ossType == OssType.aliyunOss.getCode()) {
|
|
|
+ public UploadPrepareRet prepareUpload(UploadPrepare uploadPrepare) {
|
|
|
+ try {
|
|
|
+ return ossClientManager.getOssClient().prepareUpload(uploadPrepare);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void deleteByObjectUrl(String objectUrl) throws Exception {
|
|
|
- int ossUser = storeConfigService.getLocalOssUser();
|
|
|
- if (ossType == OssType.localOss.getCode()) {
|
|
|
- //storeServiceWrapper.deleteByObjectUrl(objectUrl, ossUser);
|
|
|
- } else if (ossType == OssType.aliyunOss.getCode()) {
|
|
|
+ public UploadFileRet checkSample(UploadSample uploadSample) {
|
|
|
+ try {
|
|
|
+ return ossClientManager.getOssClient().checkSample(uploadSample);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ObjectInfo getObjectInfo(int channelCode, String objectId) throws Exception {
|
|
|
- int ossUser = storeConfigService.getLocalOssUser();
|
|
|
- if (ossType == OssType.localOss.getCode()) {
|
|
|
- //storeServiceWrapper.getObjectInfo(channelCode, objectId, ossUser);
|
|
|
- return ossClient.getObjectInfo(objectId);
|
|
|
- } else if (ossType == OssType.aliyunOss.getCode()) {
|
|
|
+ public ObjectChannel getChannel(int channelCode) {
|
|
|
+ try {
|
|
|
+ return ossClientManager.getOssClient().getChannel(channelCode);
|
|
|
+ /*if (ossType == OssType.localOss.getCode()) {
|
|
|
+ return ossClientManager.getOssClient().getChannel(channelCode);
|
|
|
+ } else if (ossType == OssType.aliyunOss.getCode()) {
|
|
|
+ }*/
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
-
|
|
|
- throw new Exception("OSSType not found");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String getSignedUrl(int channelCode, String objectId) throws Exception {
|
|
|
- int ossUser = storeConfigService.getLocalOssUser();
|
|
|
+ public void setObjectScope(String objectId, int scope) {
|
|
|
if (ossType == OssType.localOss.getCode()) {
|
|
|
- //return storeServiceWrapper.getSignedUrl(channelCode, objectId, ossUser);
|
|
|
- return ossClient.getSignedUrl(objectId, ObjectAction.access.getName());
|
|
|
+ ossClientManager.getOssClient().setObjectScope(objectId, ObjectScope.PUBLIC);
|
|
|
} else if (ossType == OssType.aliyunOss.getCode()) {
|
|
|
}
|
|
|
-
|
|
|
- throw new Exception("OSSType not found");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String getSignedUrlByUrl(int channelCode, String objectUrl) throws Exception {
|
|
|
- int ossUser = storeConfigService.getLocalOssUser();
|
|
|
- if (ossType == OssType.localOss.getCode()) {
|
|
|
- //return storeServiceWrapper.getSignedUrlByUrl(channelCode, objectUrl, ossUser);
|
|
|
- } else if (ossType == OssType.aliyunOss.getCode()) {
|
|
|
- }
|
|
|
-
|
|
|
- throw new Exception("OSSType not found");
|
|
|
+ public void deleteByObjectId(String objectId) {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public VideoInfo getVideoInfo(int channelCode, String videoFileId) throws Exception {
|
|
|
- int ossUser = storeConfigService.getLocalOssUser();
|
|
|
- //storeServiceWrapper.getVideoInfo(channelCode, videoFileId, ossUser);
|
|
|
- return ossClient.getVideoInfo(videoFileId);
|
|
|
+ public void deleteByObjectUrl(String objectUrl) {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ImageInfo getImageInfo(int channelCode, String imageFileId) throws Exception {
|
|
|
- int ossUser = storeConfigService.getLocalOssUser();
|
|
|
- if (ossType == OssType.localOss.getCode()) {
|
|
|
- //return storeServiceWrapper.getImageInfo(channelCode, imageFileId, ossUser);
|
|
|
- return ossClient.getImageInfo(imageFileId);
|
|
|
- } else if (ossType == OssType.aliyunOss.getCode()) {
|
|
|
+ public String getSignedUrl(String objectId) {
|
|
|
+ try {
|
|
|
+ return ossClientManager.getOssClient().getSignedUrl(objectId, ObjectAction.access.getName());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
-
|
|
|
- throw new Exception("OSSType not found");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ConvertedImageInfo getWebpInfo(int channelCode, String imageFileId) throws Exception {
|
|
|
- int ossUser = storeConfigService.getLocalOssUser();
|
|
|
- if (ossType == OssType.localOss.getCode()) {
|
|
|
- //return storeServiceWrapper.getWebpInfo(channelCode, imageFileId, ossUser);
|
|
|
- } else if (ossType == OssType.aliyunOss.getCode()) {
|
|
|
- }
|
|
|
- throw new Exception("OSSType not found");
|
|
|
+ public ObjectInfo getObjectInfo(String objectId) {
|
|
|
+ return ossClientManager.getOssClient().getObjectInfo(objectId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public AudioInfo getAudioInfo(int channelCode, String audioFileId) throws Exception {
|
|
|
- int ossUser = storeConfigService.getLocalOssUser();
|
|
|
- if (ossType == OssType.localOss.getCode()) {
|
|
|
- //return storeServiceWrapper.getAudioInfo(channelCode, audioFileId, ossUser);
|
|
|
- } else if (ossType == OssType.aliyunOss.getCode()) {
|
|
|
- }
|
|
|
-
|
|
|
- throw new Exception("OSSType not found");
|
|
|
+ public VideoInfo getVideoInfo(String videoFileId) {
|
|
|
+ return ossClientManager.getOssClient().getVideoInfo(videoFileId);
|
|
|
}
|
|
|
}
|