Fix zip entry names in path

This commit is contained in:
2026-04-18 20:24:27 +02:00
parent 46b6f4867e
commit 3cc928ebc8
2 changed files with 13 additions and 14 deletions

View File

@@ -8,7 +8,6 @@ import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
import sh.rhiobet.lalafin.api.configuration.FileApiConfiguration;
@@ -34,11 +33,7 @@ public class PathFactory {
if (zipIndex >= 0 && zipIndex < names.size() - 1) {
FileSystemPath zipFilePath =
new FileSystemPath(names.subList(0, zipIndex + 1), rootFolderPath);
String zipEntryName = names.stream()
.skip(zipIndex + 1)
.map(PathSegment::getPath)
.collect(Collectors.joining("/"));
return new ZipEntryPath(zipFilePath, zipEntryName);
return new ZipEntryPath(zipFilePath, names.subList(zipIndex + 1, names.size()));
} else {
return new FileSystemPath(names, rootFolderPath);
}

View File

@@ -4,8 +4,9 @@ import jakarta.ws.rs.core.PathSegment;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -17,20 +18,23 @@ public final class ZipEntryPath implements Path {
FileSystemPath zipFilePath;
List<String> segments;
String entryName;
ZipEntryPath(List<PathSegment> names, java.nio.file.Path rootFolderPath) {
this(new FileSystemPath(names.subList(0, names.size() - 1), rootFolderPath),
names.getLast().getPath());
ZipEntryPath(FileSystemPath parent, List<PathSegment> entryName) {
this.zipFilePath = parent;
this.segments = entryName.stream().map(PathSegment::getPath).toList();
this.entryName = this.segments.stream().collect(Collectors.joining("/"));
}
ZipEntryPath(FileSystemPath parent, String entryName) {
this.segments = Stream.concat(parent.segments.stream(), Stream.of(entryName)).toList();
this.zipFilePath = parent;
this.segments = Arrays.asList(entryName.split("/"));
this.entryName = entryName;
}
@Override
public String getURI() {
return this.segments.stream()
return this.zipFilePath.getURI() + this.segments.stream()
.map(s -> "/" + Encode.encodePathSegment(s))
.reduce("", String::concat);
}
@@ -70,12 +74,12 @@ public final class ZipEntryPath implements Path {
public InputStream getInputStream() throws IOException {
ZipFile zipFile = new ZipFile(this.zipFilePath.absolutePath.toFile());
return new ZipEntryInputStream(zipFile,
zipFile.getInputStream(zipFile.getEntry(this.segments.getLast())));
zipFile.getInputStream(zipFile.getEntry(this.entryName)));
}
private void fetchEntryData() {
try (ZipFile zipFile = new ZipFile(this.zipFilePath.absolutePath.toFile())) {
ZipEntry zipEntry = zipFile.getEntry(this.segments.getLast());
ZipEntry zipEntry = zipFile.getEntry(this.entryName);
this.exists = zipEntry != null;
if (this.exists) {