mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 11:49:25 +00:00
Revert "Read package.json from classspath"
This reverts commit 44292eb39b.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package dev.kruhlmann.imgfloat.service;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -144,61 +145,12 @@ public class VersionService {
|
||||
}
|
||||
|
||||
private String resolveClientVersion() throws IOException {
|
||||
String classpathVersion = getClasspathPackageJsonVersion();
|
||||
if (classpathVersion != null) {
|
||||
return classpathVersion;
|
||||
}
|
||||
|
||||
String filesystemVersion = getFilesystemPackageJsonVersion();
|
||||
if (filesystemVersion != null) {
|
||||
return filesystemVersion;
|
||||
}
|
||||
|
||||
LOG.warn(
|
||||
"Unable to resolve client version from package.json; falling back to server version {}",
|
||||
serverVersion
|
||||
);
|
||||
return serverVersion;
|
||||
}
|
||||
|
||||
private String getClasspathPackageJsonVersion() {
|
||||
try (InputStream resource = getClass().getClassLoader().getResourceAsStream("package.json")) {
|
||||
if (resource == null) {
|
||||
return null;
|
||||
}
|
||||
String version = extractPackageJsonVersion(resource);
|
||||
if (version != null) {
|
||||
return version;
|
||||
}
|
||||
LOG.warn("Unable to parse client version from classpath package.json");
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Error while reading classpath package.json", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getFilesystemPackageJsonVersion() throws IOException {
|
||||
Path packageJsonPath = Paths.get("package.json");
|
||||
if (!Files.exists(packageJsonPath) || !Files.isRegularFile(packageJsonPath)) {
|
||||
LOG.warn("package.json not found at {}", packageJsonPath.toAbsolutePath());
|
||||
return null;
|
||||
throw new FileNotFoundException("package.json not found at " + packageJsonPath.toAbsolutePath());
|
||||
}
|
||||
|
||||
try (InputStream stream = Files.newInputStream(packageJsonPath)) {
|
||||
String version = extractPackageJsonVersion(stream);
|
||||
if (version != null) {
|
||||
return version;
|
||||
}
|
||||
LOG.warn(
|
||||
"Unable to parse client version from filesystem package.json at {}",
|
||||
packageJsonPath.toAbsolutePath()
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String extractPackageJsonVersion(InputStream packageJsonStream) throws IOException {
|
||||
String packageJson = new String(packageJsonStream.readAllBytes(), StandardCharsets.UTF_8);
|
||||
String packageJson = Files.readString(packageJsonPath, StandardCharsets.UTF_8);
|
||||
Matcher matcher = PACKAGE_VERSION_PATTERN.matcher(packageJson);
|
||||
if (matcher.find()) {
|
||||
String version = matcher.group(1);
|
||||
@@ -206,6 +158,7 @@ public class VersionService {
|
||||
return version.trim();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
throw new IllegalStateException("Version not found or invalid in package.json");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user