|
|
@@ -1,5 +1,7 @@
|
|
|
package cn.reghao.oss.store.rpc;
|
|
|
|
|
|
+import cn.reghao.jutil.jdk.security.RandomString;
|
|
|
+import cn.reghao.oss.api.constant.ChannelAction;
|
|
|
import cn.reghao.oss.api.constant.ObjectScope;
|
|
|
import cn.reghao.oss.api.dto.*;
|
|
|
import cn.reghao.oss.api.dto.media.AudioInfo;
|
|
|
@@ -7,6 +9,7 @@ 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.oss.api.util.AuthContext;
|
|
|
+import cn.reghao.oss.api.util.JwtUtil;
|
|
|
import cn.reghao.oss.store.db.repository.ObjectRepository;
|
|
|
import cn.reghao.oss.store.model.po.FileMeta;
|
|
|
import cn.reghao.oss.store.service.FileStoreService;
|
|
|
@@ -15,6 +18,7 @@ import cn.reghao.oss.api.iface.StoreService;
|
|
|
import cn.reghao.oss.store.service.SignService;
|
|
|
import cn.reghao.oss.store.service.StoreLocalService;
|
|
|
import cn.reghao.oss.store.task.MediaFileProcessor;
|
|
|
+import com.github.benmanes.caffeine.cache.Cache;
|
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -39,15 +43,17 @@ public class StoreServiceImpl implements StoreService {
|
|
|
private final ObjectRepository objectRepository;
|
|
|
private final SignService signService;
|
|
|
private final MediaFileProcessor mediaFileProcessor;
|
|
|
+ private final Cache<String, String> cache;
|
|
|
|
|
|
public StoreServiceImpl(ObjectNameService objectNameService, FileStoreService fileStoreService,
|
|
|
ObjectRepository objectRepository, SignService signService,
|
|
|
- MediaFileProcessor mediaFileProcessor) {
|
|
|
+ MediaFileProcessor mediaFileProcessor, Cache<String, String> cache) {
|
|
|
this.objectNameService = objectNameService;
|
|
|
this.fileStoreService = fileStoreService;
|
|
|
this.objectRepository = objectRepository;
|
|
|
this.signService = signService;
|
|
|
this.mediaFileProcessor = mediaFileProcessor;
|
|
|
+ this.cache = cache;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -63,6 +69,17 @@ public class StoreServiceImpl implements StoreService {
|
|
|
return new StoreInfo(diskDtos);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String getUploadToken(int channelId, int loginUser) {
|
|
|
+ String secretKey = RandomString.getString(128);
|
|
|
+ String action = ChannelAction.upload.getName();
|
|
|
+ long expireAt = System.currentTimeMillis() + 3600*1000;
|
|
|
+ OssPayload ossPayload = new OssPayload(action, channelId, loginUser);
|
|
|
+ String uploadToken = JwtUtil.createToken(ossPayload, expireAt, secretKey);
|
|
|
+ cache.put(uploadToken, secretKey);
|
|
|
+ return uploadToken;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void setObjectScope(String objectId, int scope) {
|
|
|
FileMeta fileMeta = objectRepository.getByObjectId(objectId);
|