|
@@ -6,6 +6,7 @@ import cn.reghao.dfs.store.db.mapper.FileMetaMapper;
|
|
|
import cn.reghao.dfs.store.model.po.ContentRange;
|
|
import cn.reghao.dfs.store.model.po.ContentRange;
|
|
|
import cn.reghao.dfs.store.model.po.DataBlock;
|
|
import cn.reghao.dfs.store.model.po.DataBlock;
|
|
|
import cn.reghao.dfs.store.model.po.FileMeta;
|
|
import cn.reghao.dfs.store.model.po.FileMeta;
|
|
|
|
|
+import cn.reghao.dfs.store.model.vo.ObjectMeta;
|
|
|
import cn.reghao.dfs.store.redis.ds.RedisStringObj;
|
|
import cn.reghao.dfs.store.redis.ds.RedisStringObj;
|
|
|
import cn.reghao.jutil.jdk.security.DigestUtil;
|
|
import cn.reghao.jutil.jdk.security.DigestUtil;
|
|
|
import cn.reghao.jutil.tool.id.IdGenerator;
|
|
import cn.reghao.jutil.tool.id.IdGenerator;
|
|
@@ -150,14 +151,17 @@ public class ObjectBasicService {
|
|
|
HttpServletResponse response = ServletUtil.getResponse();
|
|
HttpServletResponse response = ServletUtil.getResponse();
|
|
|
Object object = redisStringObj.get(objectName);
|
|
Object object = redisStringObj.get(objectName);
|
|
|
FileMeta fileMeta;
|
|
FileMeta fileMeta;
|
|
|
|
|
+ ObjectMeta objectMeta;
|
|
|
if (object != null) {
|
|
if (object != null) {
|
|
|
fileMeta = (FileMeta) object;
|
|
fileMeta = (FileMeta) object;
|
|
|
|
|
+ objectMeta = (ObjectMeta) object;
|
|
|
} else {
|
|
} else {
|
|
|
fileMeta = fileMetaMapper.findByObjectName(objectName);
|
|
fileMeta = fileMetaMapper.findByObjectName(objectName);
|
|
|
|
|
+ objectMeta = fileMetaMapper.findObjectMeta(objectName);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// FileMeta fileMeta = fileMetaMapper.findByObjectName(objectName);
|
|
// FileMeta fileMeta = fileMetaMapper.findByObjectName(objectName);
|
|
|
- if (fileMeta == null) {
|
|
|
|
|
|
|
+ if (objectMeta == null) {
|
|
|
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
|
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
|
|
|
|
|
|
|
OutputStream outputStream = response.getOutputStream();
|
|
OutputStream outputStream = response.getOutputStream();
|
|
@@ -166,11 +170,11 @@ public class ObjectBasicService {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String objectId = fileMeta.getObjectId();
|
|
|
|
|
- String contentType = fileMeta.getContentType();
|
|
|
|
|
|
|
+ String objectId = objectMeta.getObjectId();
|
|
|
|
|
+ String contentType = objectMeta.getContentType();
|
|
|
long len = fileMeta.getSize();
|
|
long len = fileMeta.getSize();
|
|
|
if (len < partLength) {
|
|
if (len < partLength) {
|
|
|
- writeWholeContent(objectId, contentType, len);
|
|
|
|
|
|
|
+ writeWholeContent(objectId, contentType, len, objectMeta.getAbsolutePath());
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -180,10 +184,10 @@ public class ObjectBasicService {
|
|
|
String[] arr = rangeStr.replace("bytes=", "").split("-");
|
|
String[] arr = rangeStr.replace("bytes=", "").split("-");
|
|
|
long start = Long.parseLong(arr[0]);
|
|
long start = Long.parseLong(arr[0]);
|
|
|
if (arr.length == 1) {
|
|
if (arr.length == 1) {
|
|
|
- writePartialContent(objectId, contentType, start, len);
|
|
|
|
|
|
|
+ writePartialContent(objectId, contentType, start, len, objectMeta.getAbsolutePath());
|
|
|
} else {
|
|
} else {
|
|
|
ContentRange contentRange = parseContentRange(range, len);
|
|
ContentRange contentRange = parseContentRange(range, len);
|
|
|
- byte[] bytes = range1(objectId, contentRange.getStart(), contentRange.getEnd());
|
|
|
|
|
|
|
+ byte[] bytes = range1(objectId, contentRange.getStart(), contentRange.getEnd(), objectMeta.getAbsolutePath());
|
|
|
writePartialContent(bytes, contentType, contentRange, len);
|
|
writePartialContent(bytes, contentType, contentRange, len);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -237,7 +241,7 @@ public class ObjectBasicService {
|
|
|
outputStream.close();
|
|
outputStream.close();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void writePartialContent(String objectId, String contentType, long start, long len) throws IOException {
|
|
|
|
|
|
|
+ private void writePartialContent(String objectId, String contentType, long start, long len, String filePath) throws IOException {
|
|
|
HttpServletResponse response = ServletUtil.getResponse();
|
|
HttpServletResponse response = ServletUtil.getResponse();
|
|
|
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
|
|
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
|
|
|
response.setContentType(contentType);
|
|
response.setContentType(contentType);
|
|
@@ -251,12 +255,12 @@ public class ObjectBasicService {
|
|
|
if (cachePath != null && Files.exists(Path.of(cachePath))) {
|
|
if (cachePath != null && Files.exists(Path.of(cachePath))) {
|
|
|
raf = new RandomAccessFile(cachePath, "r");
|
|
raf = new RandomAccessFile(cachePath, "r");
|
|
|
} else {
|
|
} else {
|
|
|
- List<DataBlock> list = dataBlockMapper.findByObjectId(objectId);
|
|
|
|
|
|
|
+ /*List<DataBlock> list = dataBlockMapper.findByObjectId(objectId);
|
|
|
DataBlock dataBlock = list.get(0);
|
|
DataBlock dataBlock = list.get(0);
|
|
|
String blockId = dataBlock.getBlockId();
|
|
String blockId = dataBlock.getBlockId();
|
|
|
- String absolutePath = dataBlock.getAbsolutePath();
|
|
|
|
|
- localCache.putCache(objectId, absolutePath);
|
|
|
|
|
- raf = new RandomAccessFile(absolutePath, "r");
|
|
|
|
|
|
|
+ String absolutePath = dataBlock.getAbsolutePath();*/
|
|
|
|
|
+ //localCache.putCache(objectId, filePath);
|
|
|
|
|
+ raf = new RandomAccessFile(filePath, "r");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*List<DataBlock> list = dataBlockMapper.findByObjectId(objectId);
|
|
/*List<DataBlock> list = dataBlockMapper.findByObjectId(objectId);
|
|
@@ -279,6 +283,13 @@ public class ObjectBasicService {
|
|
|
raf.close();
|
|
raf.close();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 下载内容
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @date 2023-04-30 1:12 AM
|
|
|
|
|
+ */
|
|
|
private void writeDownloadContent(String objectName, String objectId, long start, long len) {
|
|
private void writeDownloadContent(String objectName, String objectId, long start, long len) {
|
|
|
HttpServletResponse response = ServletUtil.getResponse();
|
|
HttpServletResponse response = ServletUtil.getResponse();
|
|
|
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
|
|
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
|
|
@@ -314,18 +325,25 @@ public class ObjectBasicService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void writeWholeContent(String objectId, String contentType, long len) throws IOException {
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 返回内容
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @date 2023-04-30 1:12 AM
|
|
|
|
|
+ */
|
|
|
|
|
+ private void writeWholeContent(String objectId, String contentType, long len, String filePath) throws IOException {
|
|
|
HttpServletResponse response = ServletUtil.getResponse();
|
|
HttpServletResponse response = ServletUtil.getResponse();
|
|
|
response.setStatus(HttpServletResponse.SC_OK);
|
|
response.setStatus(HttpServletResponse.SC_OK);
|
|
|
response.setContentType(contentType);
|
|
response.setContentType(contentType);
|
|
|
//response.setHeader("Content-Length", ""+len);
|
|
//response.setHeader("Content-Length", ""+len);
|
|
|
|
|
|
|
|
OutputStream outputStream = response.getOutputStream();
|
|
OutputStream outputStream = response.getOutputStream();
|
|
|
- List<DataBlock> list = dataBlockMapper.findByObjectId(objectId);
|
|
|
|
|
|
|
+ /*List<DataBlock> list = dataBlockMapper.findByObjectId(objectId);
|
|
|
DataBlock dataBlock = list.get(0);
|
|
DataBlock dataBlock = list.get(0);
|
|
|
String blockId = dataBlock.getBlockId();
|
|
String blockId = dataBlock.getBlockId();
|
|
|
- String absolutePath = dataBlock.getAbsolutePath();
|
|
|
|
|
- RandomAccessFile raf = new RandomAccessFile(absolutePath, "r");
|
|
|
|
|
|
|
+ String absolutePath = dataBlock.getAbsolutePath();*/
|
|
|
|
|
+ RandomAccessFile raf = new RandomAccessFile(filePath, "r");
|
|
|
|
|
|
|
|
// 1MiB
|
|
// 1MiB
|
|
|
int bufSize = 1024*1024;
|
|
int bufSize = 1024*1024;
|
|
@@ -339,9 +357,9 @@ public class ObjectBasicService {
|
|
|
raf.close();
|
|
raf.close();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private byte[] range1(String objectId, long start, long end) throws IOException {
|
|
|
|
|
- String absolutePath = dataBlockMapper.findByObjectId(objectId).get(0).getAbsolutePath();
|
|
|
|
|
- RandomAccessFile raf = new RandomAccessFile(absolutePath, "r");
|
|
|
|
|
|
|
+ private byte[] range1(String objectId, long start, long end, String filePath) throws IOException {
|
|
|
|
|
+ // String absolutePath = dataBlockMapper.findByObjectId(objectId).get(0).getAbsolutePath();
|
|
|
|
|
+ RandomAccessFile raf = new RandomAccessFile(filePath, "r");
|
|
|
raf.seek(start);
|
|
raf.seek(start);
|
|
|
long bufSize = end - start;
|
|
long bufSize = end - start;
|
|
|
byte[] bytes = new byte[(int) bufSize];
|
|
byte[] bytes = new byte[(int) bufSize];
|