|
|
@@ -1,17 +1,17 @@
|
|
|
package cn.reghao.oss.store.rpc;
|
|
|
|
|
|
-import cn.reghao.jutil.media.ImageOps;
|
|
|
+import cn.reghao.oss.store.api.constant.ObjectScope;
|
|
|
import cn.reghao.oss.store.api.dto.*;
|
|
|
import cn.reghao.oss.store.db.repository.ObjectRepository;
|
|
|
import cn.reghao.oss.store.model.po.FileMeta;
|
|
|
import cn.reghao.oss.store.service.ObjectNameService;
|
|
|
import cn.reghao.oss.store.api.iface.ObjectService;
|
|
|
import cn.reghao.oss.store.db.mapper.FileMetaMapper;
|
|
|
+import cn.reghao.oss.store.service.SignService;
|
|
|
+import cn.reghao.oss.store.service.StoreLocalCache;
|
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -25,13 +25,15 @@ public class ObjectServiceImpl implements ObjectService {
|
|
|
private final ObjectNameService objectNameService;
|
|
|
private final ObjectRepository objectRepository;
|
|
|
private final SignService signService;
|
|
|
+ private final StoreLocalCache storeLocalCache;
|
|
|
|
|
|
public ObjectServiceImpl(FileMetaMapper fileMetaMapper, ObjectNameService objectNameService,
|
|
|
- ObjectRepository objectRepository, SignService signService) {
|
|
|
+ ObjectRepository objectRepository, SignService signService, StoreLocalCache storeLocalCache) {
|
|
|
this.fileMetaMapper = fileMetaMapper;
|
|
|
this.objectNameService = objectNameService;
|
|
|
this.objectRepository = objectRepository;
|
|
|
this.signService = signService;
|
|
|
+ this.storeLocalCache = storeLocalCache;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -60,7 +62,7 @@ public class ObjectServiceImpl implements ObjectService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ObjectInfo getObjectInfo(String objectId) {
|
|
|
+ public ObjectInfo getObjectInfo(int loginUser, String objectId, int expireSecond) {
|
|
|
FileMeta fileMeta = fileMetaMapper.findByObjectId(objectId);
|
|
|
if (fileMeta == null) {
|
|
|
return null;
|
|
|
@@ -69,9 +71,17 @@ public class ObjectServiceImpl implements ObjectService {
|
|
|
String objectName = fileMeta.getObjectName();
|
|
|
int fileType = fileMeta.getFileType();
|
|
|
String filename = fileMeta.getFilename();
|
|
|
- long size = fileMeta.getSize();
|
|
|
- ObjectInfo objectInfo = new ObjectInfo(objectId, objectName, fileType, filename, size);
|
|
|
- if (fileType == 1001) {
|
|
|
+ ObjectInfo objectInfo = new ObjectInfo(objectId, objectName, fileType, filename);
|
|
|
+ String url = String.format("//%s/%s", storeLocalCache.getDomain(), objectName);
|
|
|
+ int scope = fileMeta.getScope();
|
|
|
+ if (scope != ObjectScope.PUBLIC.getCode()) {
|
|
|
+ String signedUrl = signService.getSignedUrl(loginUser, url, expireSecond);
|
|
|
+ objectInfo.setUrl(signedUrl);
|
|
|
+ } else {
|
|
|
+ objectInfo.setUrl(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*if (fileType == 1001) {
|
|
|
ObjectMeta objectMeta = objectRepository.getObjectMetaById(objectId);
|
|
|
String absolutePath = objectMeta.getAbsolutePath();
|
|
|
try {
|
|
|
@@ -81,7 +91,7 @@ public class ObjectServiceImpl implements ObjectService {
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
return objectInfo;
|
|
|
}
|