Skip to content

Commit

Permalink
Merge pull request #520 from slovensko-digital/fix/windows-assets-path
Browse files Browse the repository at this point in the history
Fix windows version
  • Loading branch information
celuchmarek authored Jan 27, 2025
2 parents b202e3b + 1b042de commit 5dfd656
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
import digital.slovensko.autogram.server.errors.InvalidUrlParamException;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import static java.util.Objects.requireNonNull;

public class AssetsEndpoint implements HttpHandler {
private static final List<String> assets;
private static final Path assetsPath;
static {
assetsPath = Path.of(requireNonNull(AssetsEndpoint.class.getResource("index.html")).getPath()).getParent().resolve("assets");
assets = List.of(
"swagger-ui-bundle-v5.11.0.js",
"swagger-ui-v5.11.0.css"
Expand All @@ -39,7 +35,7 @@ public void handle(HttpExchange exchange) throws IOException {
throw new InvalidUrlParamException("Asset with this name does not exist");

try (exchange) {
exchange.getResponseHeaders().set("Content-Type", Files.probeContentType(assetsPath.resolve(fileName)));
exchange.getResponseHeaders().set("Content-Type", getAssetMimeType(fileName));
exchange.sendResponseHeaders(200, 0);
requireNonNull(stream).transferTo(exchange.getResponseBody());
}
Expand All @@ -49,4 +45,14 @@ public void handle(HttpExchange exchange) throws IOException {
EndpointUtils.respondWithError(ErrorResponse.buildFromException(e), exchange);
}
}

private String getAssetMimeType(String fileName) {
if (fileName.endsWith(".js"))
return "application/javascript";

if (fileName.endsWith(".css"))
return "text/css";

return "applicaiton/octet-stream";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ win.menuGroup=
win.perUserInstall=
# Create a desktop shortcut for the application (1/0).
# Defaults to 0.
win.shortcut=
win.shortcut=1

### Linux specific ###

Expand Down
2 changes: 1 addition & 1 deletion src/main/scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ if [[ "${platform}" == "win" ]]; then

arguments+=(
"--name" "${properties_name}"
"--description" "${properties_name}"
"--type" "msi"
"--icon" "./Autogram.ico"
"--java-options" "${jvmOptions} --add-opens jdk.crypto.mscapi/sun.security.mscapi=ALL-UNNAMED"
"--win-shortcut-prompt"
"--win-menu"
"--add-launcher" "autogram-cli=$resourcesDir/windows-cli-build.properties"
)
Expand Down

0 comments on commit 5dfd656

Please sign in to comment.