Skip to content

Commit

Permalink
Revert "Add dynamic content type for more than .jar downloads"
Browse files Browse the repository at this point in the history
This reverts commit be23752.
  • Loading branch information
rtm516 committed Feb 16, 2024
1 parent 842b3be commit 11b025e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import io.papermc.bibliothek.exception.DownloadNotFound;
import io.papermc.bibliothek.exception.ProjectNotFound;
import io.papermc.bibliothek.exception.VersionNotFound;
import io.papermc.bibliothek.util.CustomFileNameMap;
import io.papermc.bibliothek.util.HTTP;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -54,7 +53,6 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -66,7 +64,6 @@
public class DownloadController {
private static final CacheControl CACHE_LATEST = HTTP.sMaxAgePublicCache(Duration.ofMinutes(1));
private static final CacheControl CACHE_SPECIFIC = HTTP.sMaxAgePublicCache(Duration.ofDays(14));
private static final CustomFileNameMap FILE_NAME_MAP = new CustomFileNameMap();
private final AppConfiguration configuration;
private final ProjectCollection projects;
private final VersionCollection versions;
Expand Down Expand Up @@ -142,7 +139,7 @@ public ResponseEntity<?> downloadLatest(
value = "/v2/projects/{project:[a-z]+}/versions/{version:" + Version.PATTERN + "}/builds/{build:\\d+}/downloads/{download:[a-z]+}",
produces = {
MediaType.APPLICATION_JSON_VALUE,
MimeTypeUtils.ALL_VALUE
HTTP.APPLICATION_JAVA_ARCHIVE_VALUE
}
)
@Operation(summary = "Downloads the given file from a build's data.")
Expand Down Expand Up @@ -181,7 +178,7 @@ public ResponseEntity<?> downloadSpecific(
}

try {
return new DownloadFile(
return new JavaArchive(
this.configuration.getStoragePath()
.resolve(project.name())
.resolve(version.name())
Expand All @@ -194,16 +191,16 @@ public ResponseEntity<?> downloadSpecific(
}
}

private static class DownloadFile extends ResponseEntity<FileSystemResource> {
DownloadFile(final Path path, final CacheControl cache) throws IOException {
private static class JavaArchive extends ResponseEntity<FileSystemResource> {
JavaArchive(final Path path, final CacheControl cache) throws IOException {
super(new FileSystemResource(path), headersFor(path, cache), HttpStatus.OK);
}

private static HttpHeaders headersFor(final Path path, final CacheControl cache) throws IOException {
final HttpHeaders headers = new HttpHeaders();
headers.setCacheControl(cache);
headers.setContentDisposition(HTTP.attachmentDisposition(path.getFileName()));
headers.setContentType(MediaType.valueOf(FILE_NAME_MAP.getContentTypeFor(path.getFileName().toString())));
headers.setContentType(HTTP.APPLICATION_JAVA_ARCHIVE);
headers.setLastModified(Files.getLastModifiedTime(path).toInstant());
return headers;
}
Expand Down
49 changes: 0 additions & 49 deletions src/main/java/io/papermc/bibliothek/util/CustomFileNameMap.java

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/java/io/papermc/bibliothek/util/HTTP.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import org.springframework.http.ResponseEntity;

public final class HTTP {
public static final String APPLICATION_JAVA_ARCHIVE_VALUE = "application/java-archive";
public static final MediaType APPLICATION_JAVA_ARCHIVE = new MediaType("application", "java-archive");

private HTTP() {
}

Expand Down

0 comments on commit 11b025e

Please sign in to comment.