From e7ff159b6ded695bf3d7a802f38f0186a753796e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=BF=8A?= <873019219@qq.com> Date: Sun, 11 Apr 2021 19:15:50 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=9C=B0=E5=9D=80=E5=B8=A6=E5=AF=86=E9=92=A5?= =?UTF-8?q?=E7=9A=84=E5=AD=98=E5=82=A8=E7=AD=96=E7=95=A5=EF=BC=8Cm3u8=20?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/home/DirectLinkController.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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) {