mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +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;
|
package dev.kruhlmann.imgfloat.service;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -144,61 +145,12 @@ public class VersionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String resolveClientVersion() throws IOException {
|
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");
|
Path packageJsonPath = Paths.get("package.json");
|
||||||
if (!Files.exists(packageJsonPath) || !Files.isRegularFile(packageJsonPath)) {
|
if (!Files.exists(packageJsonPath) || !Files.isRegularFile(packageJsonPath)) {
|
||||||
LOG.warn("package.json not found at {}", packageJsonPath.toAbsolutePath());
|
throw new FileNotFoundException("package.json not found at " + packageJsonPath.toAbsolutePath());
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try (InputStream stream = Files.newInputStream(packageJsonPath)) {
|
String packageJson = Files.readString(packageJsonPath, StandardCharsets.UTF_8);
|
||||||
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);
|
|
||||||
Matcher matcher = PACKAGE_VERSION_PATTERN.matcher(packageJson);
|
Matcher matcher = PACKAGE_VERSION_PATTERN.matcher(packageJson);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
String version = matcher.group(1);
|
String version = matcher.group(1);
|
||||||
@@ -206,6 +158,7 @@ public class VersionService {
|
|||||||
return version.trim();
|
return version.trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
throw new IllegalStateException("Version not found or invalid in package.json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user