|
@@ -4,7 +4,6 @@ import cn.reghao.jutil.jdk.thread.ThreadFactoryBuilder;
|
|
|
import cn.reghao.oss.api.dto.rest.UploadDoneResult;
|
|
import cn.reghao.oss.api.dto.rest.UploadDoneResult;
|
|
|
import cn.reghao.oss.api.iface.ConsoleService;
|
|
import cn.reghao.oss.api.iface.ConsoleService;
|
|
|
import cn.reghao.oss.store.config.OssStoreConfig;
|
|
import cn.reghao.oss.store.config.OssStoreConfig;
|
|
|
-import cn.reghao.oss.store.util.FileUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
@@ -75,7 +74,6 @@ public class HddFlushService {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String contentType = flushResult.contentType;
|
|
|
|
|
Path tmpFile = Path.of(hddTempPath);
|
|
Path tmpFile = Path.of(hddTempPath);
|
|
|
String filePath = diskService.getHddDataPath(sha256sum);
|
|
String filePath = diskService.getHddDataPath(sha256sum);
|
|
|
Path finalPath = Path.of(filePath);
|
|
Path finalPath = Path.of(filePath);
|
|
@@ -142,15 +140,7 @@ public class HddFlushService {
|
|
|
private FlushResult moveAndChecksum(String src, String dest) throws Exception {
|
|
private FlushResult moveAndChecksum(String src, String dest) throws Exception {
|
|
|
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
|
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
|
|
Path srcPath = Paths.get(src);
|
|
Path srcPath = Paths.get(src);
|
|
|
- String detectedType = FileUtil.getContentType(src);
|
|
|
|
|
-
|
|
|
|
|
- // 1. Tika 识别:利用 Path 获取,它内部会按需打开 Channel
|
|
|
|
|
- // 只读文件头,速度极快,不影响后续搬运
|
|
|
|
|
- /*try (TikaInputStream tikaStream = TikaInputStream.get(srcPath)) {
|
|
|
|
|
- detectedType = TIKA.detect(tikaStream, new Metadata());
|
|
|
|
|
- }*/
|
|
|
|
|
-
|
|
|
|
|
- // 2. 核心搬运:使用 FileChannel + DirectBuffer
|
|
|
|
|
|
|
+ // 核心搬运:使用 FileChannel + DirectBuffer
|
|
|
try (FileChannel srcChannel = FileChannel.open(srcPath, StandardOpenOption.READ);
|
|
try (FileChannel srcChannel = FileChannel.open(srcPath, StandardOpenOption.READ);
|
|
|
FileChannel destChannel = FileChannel.open(Paths.get(dest),
|
|
FileChannel destChannel = FileChannel.open(Paths.get(dest),
|
|
|
StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.READ)) {
|
|
StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.READ)) {
|
|
@@ -177,7 +167,7 @@ public class HddFlushService {
|
|
|
|
|
|
|
|
// 3. 转换为十六进制字符串
|
|
// 3. 转换为十六进制字符串
|
|
|
String hex = bytesToHex(digest.digest());
|
|
String hex = bytesToHex(digest.digest());
|
|
|
- return new FlushResult(hex, detectedType);
|
|
|
|
|
|
|
+ return new FlushResult(hex);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private String bytesToHex(byte[] bytes) {
|
|
private String bytesToHex(byte[] bytes) {
|
|
@@ -194,5 +184,5 @@ public class HddFlushService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// --- 结果包装 ---
|
|
// --- 结果包装 ---
|
|
|
- public record FlushResult(String sha256sum, String contentType) {}
|
|
|
|
|
|
|
+ public record FlushResult(String sha256sum) {}
|
|
|
}
|
|
}
|