diff --git a/src/main/java/im/zhaojun/zfile/controller/home/DirectLinkController.java b/src/main/java/im/zhaojun/zfile/controller/home/DirectLinkController.java index c2d8e30..2fe22a5 100644 --- a/src/main/java/im/zhaojun/zfile/controller/home/DirectLinkController.java +++ b/src/main/java/im/zhaojun/zfile/controller/home/DirectLinkController.java @@ -1,6 +1,7 @@ package im.zhaojun.zfile.controller.home; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.URLUtil; import im.zhaojun.zfile.context.DriveContext; import im.zhaojun.zfile.exception.NotEnabledDriveException; @@ -10,6 +11,7 @@ import im.zhaojun.zfile.model.entity.DriveConfig; import im.zhaojun.zfile.model.enums.FileTypeEnum; import im.zhaojun.zfile.service.DriveConfigService; import im.zhaojun.zfile.service.base.AbstractBaseFileService; +import im.zhaojun.zfile.util.HttpUtil; import org.springframework.stereotype.Controller; import org.springframework.util.AntPathMatcher; import org.springframework.web.bind.annotation.GetMapping; @@ -18,6 +20,9 @@ import org.springframework.web.servlet.HandlerMapping; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; import java.util.Objects; /** @@ -30,6 +35,9 @@ public class DirectLinkController { @Resource private DriveContext driveContext; + @Resource + private DriveConfigService driveConfigService; + /** * 获取指定驱动器, 某个文件的直链, 然后重定向过去. * @param driveId @@ -57,15 +65,21 @@ public class DirectLinkController { filePath = "/" + filePath; } - if (Objects.equals(FileUtil.getName(filePath), ZFileConstant.PASSWORD_FILE_NAME)) { - throw new NotAllowedDownloadException("不允许下载此文件"); - } - AbstractBaseFileService fileService = driveContext.get(driveId); FileItemDTO fileItem = fileService.getFileItem(filePath); String url = fileItem.getUrl(); + if (StrUtil.equalsIgnoreCase(FileUtil.extName(fileItem.getName()), "m3u8")) { + String textContent = HttpUtil.getTextContent(url); + response.setContentType("application/json;charset=utf-8"); + PrintWriter out = response.getWriter(); + out.write(textContent); + out.flush(); + out.close(); + return null; + } + int queryIndex = url.indexOf('?'); if (queryIndex != -1) {