feat: govern knowledge assets and source citations
This commit is contained in:
+3
@@ -68,6 +68,9 @@ public interface ISysOssService {
|
||||
*/
|
||||
void download(Long ossId, HttpServletResponse response) throws IOException;
|
||||
|
||||
/** Streams a validated HTTP byte range for media playback. */
|
||||
void downloadRange(Long ossId, String range, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除OSS对象存储
|
||||
*
|
||||
|
||||
+32
@@ -34,6 +34,7 @@ import org.dromara.system.service.ISysOssService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.MediaTypeFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -184,6 +185,37 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
||||
storage.download(sysOss.getFileName(), response.getOutputStream(), response::setContentLengthLong);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadRange(Long ossId, String range, HttpServletResponse response) throws IOException {
|
||||
SysOssVo sysOss = SpringUtils.getAopProxy(this).getById(ossId);
|
||||
if (ObjectUtil.isNull(sysOss)) throw new ServiceException("文件数据不存在!");
|
||||
response.setHeader("Accept-Ranges", "bytes");
|
||||
response.setHeader("Content-Disposition", "inline");
|
||||
response.setContentType(MediaTypeFactory.getMediaType(sysOss.getOriginalName())
|
||||
.orElse(MediaType.APPLICATION_OCTET_STREAM).toString());
|
||||
if (range == null || range.isBlank()) {
|
||||
OssFactory.instance(sysOss.getService()).download(
|
||||
sysOss.getFileName(), response.getOutputStream(), response::setContentLengthLong);
|
||||
return;
|
||||
}
|
||||
if (!range.matches("bytes=\\d+-\\d*")) {
|
||||
response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
|
||||
return;
|
||||
}
|
||||
String[] bounds = range.substring(6).split("-", -1);
|
||||
if (!bounds[1].isEmpty() && Long.parseLong(bounds[1]) < Long.parseLong(bounds[0])) {
|
||||
response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
|
||||
return;
|
||||
}
|
||||
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
|
||||
OssFactory.instance(sysOss.getService()).downloadRange(sysOss.getFileName(), range,
|
||||
response.getOutputStream(), metadata -> {
|
||||
response.setContentLengthLong(metadata.contentLength());
|
||||
if (metadata.contentRange() != null) response.setHeader("Content-Range", metadata.contentRange());
|
||||
if (metadata.contentType() != null) response.setContentType(metadata.contentType());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传 MultipartFile 到对象存储服务,并保存文件信息到数据库
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user