|
|
@@ -3,6 +3,7 @@ package cn.reghao.tnb.file.app.service;
|
|
|
import cn.reghao.tnb.file.app.config.DfsProperties;
|
|
|
import cn.reghao.tnb.file.app.config.PathUrl;
|
|
|
import cn.reghao.tnb.file.app.util.LoadBalancer;
|
|
|
+import cn.reghao.tnb.file.app.util.StoreDir;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
@@ -25,28 +26,37 @@ public class FileUrlService {
|
|
|
@Deprecated
|
|
|
public PathUrl genPathAndUrl(String sha256sum, String fileId, String suffix)
|
|
|
throws IOException, NoSuchAlgorithmException {
|
|
|
- String storeDir = loadBalancer.getStoreDir(0, sha256sum);
|
|
|
- String filePath = String.format("%s/%s.%s", storeDir, fileId, suffix);
|
|
|
+ StoreDir storeDir = loadBalancer.getStoreDir(0, sha256sum);
|
|
|
+ String blockId = storeDir.getBlockId();
|
|
|
+ String fileDir = storeDir.getFileDir();
|
|
|
+
|
|
|
+ String filePath = String.format("%s/%s.%s", fileDir, fileId, suffix);
|
|
|
String path = String.format("video/%s.%s", fileId, suffix);
|
|
|
String url = String.format("//%s/video/%s.%s", domain, fileId, suffix);
|
|
|
- return new PathUrl(filePath, url, path);
|
|
|
+ return new PathUrl(blockId, filePath, url, path);
|
|
|
}
|
|
|
|
|
|
public PathUrl genVideoPathAndUrl(String sha256sum, String uploadId, long fileSize, String fileId, String suffix)
|
|
|
throws IOException, NoSuchAlgorithmException {
|
|
|
- String storeDir = loadBalancer.getStoreDir(fileSize, sha256sum);
|
|
|
- String filePath = String.format("%s/%s.%s", storeDir, fileId, suffix);
|
|
|
- String path = String.format("video/%s.%s", uploadId, suffix);
|
|
|
+ StoreDir storeDir = loadBalancer.getStoreDir(fileSize, sha256sum);
|
|
|
+ String blockId = storeDir.getBlockId();
|
|
|
+ String fileDir = storeDir.getFileDir();
|
|
|
+
|
|
|
+ String filePath = String.format("%s%s.%s", fileDir, fileId, suffix);
|
|
|
String url = String.format("//%s/video/%s.%s", domain, uploadId, suffix);
|
|
|
- return new PathUrl(filePath, url, path);
|
|
|
+ String path = String.format("video/%s.%s", uploadId, suffix);
|
|
|
+ return new PathUrl(blockId, filePath, url, path);
|
|
|
}
|
|
|
|
|
|
public PathUrl getImagePathAndUrl(String sha256sum, String uploadId, long fileSize, String fileId, String suffix,
|
|
|
int width, int height) throws IOException, NoSuchAlgorithmException {
|
|
|
- String storeDir = loadBalancer.getStoreDir(fileSize, sha256sum);
|
|
|
- String filePath = String.format("%s/%s_%sx%s.%s", storeDir, fileId, width, height, suffix);
|
|
|
+ StoreDir storeDir = loadBalancer.getStoreDir(fileSize, sha256sum);
|
|
|
+ String blockId = storeDir.getBlockId();
|
|
|
+ String fileDir = storeDir.getFileDir();
|
|
|
+
|
|
|
+ String filePath = String.format("%s/%s_%sx%s.%s", fileDir, fileId, width, height, suffix);
|
|
|
String path = String.format("video/%s.%s", uploadId, suffix);
|
|
|
String url = String.format("//%s/image/%s.%s", domain, uploadId, suffix);
|
|
|
- return new PathUrl(filePath, url, path);
|
|
|
+ return new PathUrl(blockId, filePath, url, path);
|
|
|
}
|
|
|
}
|