mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2025-04-05 17:37:49 +08:00
优化:视频文件预览支持FTP
This commit is contained in:
parent
1a4748bbec
commit
c16116c7cd
@ -1,7 +1,11 @@
|
|||||||
package cn.keking.service.impl;
|
package cn.keking.service.impl;
|
||||||
|
|
||||||
import cn.keking.model.FileAttribute;
|
import cn.keking.model.FileAttribute;
|
||||||
|
import cn.keking.model.ReturnResponse;
|
||||||
import cn.keking.service.FilePreview;
|
import cn.keking.service.FilePreview;
|
||||||
|
import cn.keking.utils.DownloadUtils;
|
||||||
|
import cn.keking.utils.FileUtils;
|
||||||
|
import cn.keking.web.filter.BaseUrlFilter;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
/**
|
/**
|
||||||
@ -13,8 +17,31 @@ import org.springframework.ui.Model;
|
|||||||
@Service
|
@Service
|
||||||
public class MediaFilePreviewImpl implements FilePreview {
|
public class MediaFilePreviewImpl implements FilePreview {
|
||||||
|
|
||||||
|
private final DownloadUtils downloadUtils;
|
||||||
|
|
||||||
|
private final FileUtils fileUtils;
|
||||||
|
|
||||||
|
public MediaFilePreviewImpl(DownloadUtils downloadUtils,
|
||||||
|
FileUtils fileUtils) {
|
||||||
|
this.downloadUtils = downloadUtils;
|
||||||
|
this.fileUtils = fileUtils;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
||||||
|
// 不是http开头,浏览器不能直接访问,需下载到本地
|
||||||
|
if (url != null && !url.toLowerCase().startsWith("http")) {
|
||||||
|
ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, fileAttribute.getName());
|
||||||
|
if (0 != response.getCode()) {
|
||||||
|
model.addAttribute("fileType", fileAttribute.getSuffix());
|
||||||
|
model.addAttribute("msg", response.getMsg());
|
||||||
|
return "fileNotSupported";
|
||||||
|
} else {
|
||||||
|
model.addAttribute("mediaUrl", BaseUrlFilter.getBaseUrl() + fileUtils.getRelativePath(response.getContent()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
model.addAttribute("mediaUrl", url);
|
||||||
|
}
|
||||||
model.addAttribute("mediaUrl", url);
|
model.addAttribute("mediaUrl", url);
|
||||||
String suffix=fileAttribute.getSuffix();
|
String suffix=fileAttribute.getSuffix();
|
||||||
if ("flv".equalsIgnoreCase(suffix)) {
|
if ("flv".equalsIgnoreCase(suffix)) {
|
||||||
|
@ -24,7 +24,9 @@ import java.util.Map;
|
|||||||
@Component
|
@Component
|
||||||
public class FileUtils {
|
public class FileUtils {
|
||||||
|
|
||||||
public static final String DEFAULT_CONVERTER_CHARSET = System.getProperty("sun.jnu.encoding");
|
private static final String DEFAULT_CONVERTER_CHARSET = System.getProperty("sun.jnu.encoding");
|
||||||
|
|
||||||
|
private final String fileDir = ConfigConstants.getFileDir();
|
||||||
|
|
||||||
private final CacheService cacheService;
|
private final CacheService cacheService;
|
||||||
|
|
||||||
@ -32,8 +34,6 @@ public class FileUtils {
|
|||||||
this.cacheService = cacheService;
|
this.cacheService = cacheService;
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileDir = ConfigConstants.getFileDir();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 已转换过的文件集合(缓存)
|
* @return 已转换过的文件集合(缓存)
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user