|
|
@@ -1,6 +1,5 @@
|
|
|
package cn.reghao.dfs.store.rpc;
|
|
|
|
|
|
-import cn.reghao.dfs.api.dto.EncryptParams;
|
|
|
import cn.reghao.dfs.api.iface.MediaUrlService;
|
|
|
import cn.reghao.dfs.store.db.mapper.VideoUrlMapper;
|
|
|
import cn.reghao.dfs.api.dto.VideoUrlDto;
|
|
|
@@ -10,8 +9,9 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
@@ -34,19 +34,30 @@ public class MediaUrlServiceImpl implements MediaUrlService {
|
|
|
|
|
|
@Override
|
|
|
public List<VideoUrlDto> getEncryptMp4Urls(String videoFileId, String key) throws NoSuchAlgorithmException {
|
|
|
- long timestamp = System.currentTimeMillis() + 8*3600*1000;
|
|
|
- byte[] bytes = (key + timestamp).getBytes(StandardCharsets.UTF_8);
|
|
|
- String sign = DigestUtil.md5sum(bytes);
|
|
|
- EncryptParams encryptParams = new EncryptParams(timestamp, sign);
|
|
|
- return Collections.emptyList();
|
|
|
+ List<VideoUrlDto> urls = videoUrlMapper.findByVideoFileId(videoFileId);
|
|
|
+ return urls.stream()
|
|
|
+ .map(videoUrlDto -> {
|
|
|
+ String url = videoUrlDto.getUrl();
|
|
|
+ try {
|
|
|
+ String encryptUrl = encryptUrl(videoFileId, url);
|
|
|
+ videoUrlDto.setUrl(encryptUrl);
|
|
|
+ return videoUrlDto;
|
|
|
+ } catch (NoSuchAlgorithmException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ })
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- private String encryptUrl(String url) throws NoSuchAlgorithmException {
|
|
|
+ private String encryptUrl(String videoFileId, String url) throws NoSuchAlgorithmException {
|
|
|
String key = "abcdABCD1234";
|
|
|
// 链接过期时间戳,8 小时后过期
|
|
|
long t = System.currentTimeMillis() + 8*3600*1000;
|
|
|
byte[] bytes = (key + t).getBytes(StandardCharsets.UTF_8);
|
|
|
String sign = DigestUtil.md5sum(bytes);
|
|
|
- return String.format("%s?t=%s&sign=%s", url, t, sign);
|
|
|
+ String encryptUrl = String.format("%s?t=%s&sign=%s", url, t, sign);
|
|
|
+ return encryptUrl;
|
|
|
}
|
|
|
}
|