支持在线浏览图片, 文本, 视频, 使用 HistoryAPI 页面不刷新优化用户体验.

This commit is contained in:
zhaojun1998
2019-08-22 23:33:02 +08:00
parent a5120effcc
commit 476de0aef4
21 changed files with 12045 additions and 5461 deletions

View File

@@ -10,6 +10,7 @@ import im.zhaojun.common.model.SiteConfig;
import im.zhaojun.common.service.FileService;
import im.zhaojun.common.service.SystemConfigService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct;
@@ -17,6 +18,7 @@ import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
@RequestMapping("/api")
@RestController
public class FileController {
@@ -25,7 +27,7 @@ public class FileController {
@Resource
private SystemConfigService configService;
@GetMapping("/filelist")
@GetMapping("/list")
public ResultBean list(String path, String sortBy, boolean descending) throws Exception {
List<FileItem> fileItems = fileService.fileList(URLUtil.decode(path));
@@ -99,7 +101,7 @@ public class FileController {
return ResultBean.success();
}
@GetMapping("clearCache")
@GetMapping("/clearCache")
public ResultBean clearCache() throws Exception {
fileService.clearCache();
return ResultBean.success();

View File

@@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@Controller
public class IndexController {
@@ -14,7 +15,12 @@ public class IndexController {
private SystemConfigService systemConfigService;
@GetMapping("/")
public ModelAndView index(ModelAndView modelAndView) {
public String index() {
return "redirect:/file/";
}
@GetMapping("/file/**")
public ModelAndView index(ModelAndView modelAndView, HttpServletRequest request) {
modelAndView.setViewName("index");
modelAndView.addObject("systemConfig", systemConfigService.getSystemConfig());
return modelAndView;

View File

@@ -46,6 +46,9 @@ public interface FileService {
return siteConfig;
}
/**
* 获取文件内容.
*/
default String getTextContent(String path) throws Exception {
return HttpUtil.get(URLDecoder.decode(getDownloadUrl(path), "utf8"));
}
@@ -68,6 +71,9 @@ public interface FileService {
@Cacheable
default ImageInfo getImageInfo(String url) throws Exception {
url = URLUtil.decode(url);
URL urlObject = new URL(url);
String originPath = urlObject.getPath();
url = url.replace(originPath, URLUtil.encode(originPath));
InputStream inputStream = new URL(url).openStream();
BufferedImage sourceImg = ImageIO.read(inputStream);
return new ImageInfo(sourceImg.getWidth(), sourceImg.getHeight());

View File

@@ -30,7 +30,7 @@ public class StringUtils {
* @param path 路径
* @return URL
*/
public static String concatDomainAndPath(String domain, String path) {
public static String concatPath(String domain, String path) {
if (path != null && path.length() > 1 && path.charAt(0) != '/') {
path = '/' + path;
}