From a97a28c00f306772f4cf4588fc11ff5838a53841 Mon Sep 17 00:00:00 2001 From: itning Date: Tue, 13 Feb 2024 11:45:56 +0800 Subject: [PATCH] feat: optimization --- .../itning/yunshunas/video/controller/VideoController.java | 2 +- .../src/main/java/top/itning/yunshunas/video/entity/Link.java | 4 ++-- .../itning/yunshunas/video/service/impl/VideoServiceImpl.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nas-video/src/main/java/top/itning/yunshunas/video/controller/VideoController.java b/nas-video/src/main/java/top/itning/yunshunas/video/controller/VideoController.java index 4cde5ceb..0daaf892 100644 --- a/nas-video/src/main/java/top/itning/yunshunas/video/controller/VideoController.java +++ b/nas-video/src/main/java/top/itning/yunshunas/video/controller/VideoController.java @@ -74,7 +74,7 @@ public void ts(@PathVariable String name, @PathVariable String index, HttpServle */ @GetMapping("/video/{path}") public void videoForPath(@PathVariable String path, HttpServletRequest request, HttpServletResponse response) throws Exception { - byte[] decode = Base64.getDecoder().decode(path.getBytes(StandardCharsets.UTF_8)); + byte[] decode = Base64.getUrlDecoder().decode(path.getBytes(StandardCharsets.UTF_8)); Path p = Paths.get(new String(decode, StandardCharsets.UTF_8)); MultipartFileSender.fromPath(p) .with(request) diff --git a/nas-video/src/main/java/top/itning/yunshunas/video/entity/Link.java b/nas-video/src/main/java/top/itning/yunshunas/video/entity/Link.java index 4d7cb060..1736e0bc 100644 --- a/nas-video/src/main/java/top/itning/yunshunas/video/entity/Link.java +++ b/nas-video/src/main/java/top/itning/yunshunas/video/entity/Link.java @@ -31,7 +31,7 @@ public class Link { } public static List build(String location) throws UnsupportedEncodingException { - byte[] decode = Base64.getDecoder().decode(location.getBytes(StandardCharsets.UTF_8)); + byte[] decode = Base64.getUrlDecoder().decode(location.getBytes(StandardCharsets.UTF_8)); String decodeLocation = new String(decode, StandardCharsets.UTF_8); String[] locationArray = decodeLocation.split(SPLIT_REGEX); List linkList = new ArrayList<>(locationArray.length); @@ -46,7 +46,7 @@ public static List build(String location) throws UnsupportedEncodingExcept for (int i = 0; i < locationArray.length; i++) { Link link = new Link(); link.setName(locationArray[i]); - link.setLink(Base64.getEncoder().encodeToString(last.toString().getBytes(StandardCharsets.UTF_8))); + link.setLink(Base64.getUrlEncoder().encodeToString(last.toString().getBytes(StandardCharsets.UTF_8))); if ((i + 1) != locationArray.length) { last.append(File.separator).append(locationArray[i + 1]); } diff --git a/nas-video/src/main/java/top/itning/yunshunas/video/service/impl/VideoServiceImpl.java b/nas-video/src/main/java/top/itning/yunshunas/video/service/impl/VideoServiceImpl.java index 8bf4bc2f..a7cecb61 100644 --- a/nas-video/src/main/java/top/itning/yunshunas/video/service/impl/VideoServiceImpl.java +++ b/nas-video/src/main/java/top/itning/yunshunas/video/service/impl/VideoServiceImpl.java @@ -44,7 +44,7 @@ public List getFileEntities(String location) { if (StringUtils.isBlank(location)) { files = File.listRoots(); } else { - byte[] decode = Base64.getDecoder().decode(location); + byte[] decode = Base64.getUrlDecoder().decode(location); File file = new File(new String(decode, StandardCharsets.UTF_8)); files = file.listFiles(); } @@ -57,7 +57,7 @@ public List getFileEntities(String location) { fileEntity.setSize(FileUtils.byteCountToDisplaySize(f.length())); fileEntity.setFile(f.isFile()); fileEntity.setCanPlay(isVideoFile(f.getName())); - fileEntity.setLocation(Base64.getEncoder().encodeToString(f.getPath().getBytes(StandardCharsets.UTF_8))); + fileEntity.setLocation(Base64.getUrlEncoder().encodeToString(f.getPath().getBytes(StandardCharsets.UTF_8))); fileEntities.add(fileEntity); } } else {