mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 11:49:25 +00:00
Specify proper env vars
This commit is contained in:
@@ -40,11 +40,14 @@ public class SystemEnvironmentValidator {
|
||||
@Value("${IMGFLOAT_INITIAL_TWITCH_USERNAME_SYSADMIN:#{null}}")
|
||||
private String initialSysadmin;
|
||||
|
||||
@Value("${IMGFLOAT_GITHUB_OWNER:#{null}}")
|
||||
private String githubOwner;
|
||||
@Value("${IMGFLOAT_GITHUB_CLIENT_OWNER:#{null}}")
|
||||
private String githubClientOwner;
|
||||
|
||||
@Value("${IMGFLOAT_GITHUB_REPO:#{null}}")
|
||||
private String githubRepo;
|
||||
@Value("${IMGFLOAT_GITHUB_CLIENT_REPO:#{null}}")
|
||||
private String githubClientRepo;
|
||||
|
||||
@Value("${IMGFLOAT_GITHUB_CLIENT_VERSION:#{null}}")
|
||||
private String githubClientVersion;
|
||||
|
||||
private long maxUploadBytes;
|
||||
private long maxRequestBytes;
|
||||
@@ -76,8 +79,9 @@ public class SystemEnvironmentValidator {
|
||||
checkString(twitchClientSecret, "TWITCH_CLIENT_SECRET", missing);
|
||||
checkString(assetsPath, "IMGFLOAT_ASSETS_PATH", missing);
|
||||
checkString(previewsPath, "IMGFLOAT_PREVIEWS_PATH", missing);
|
||||
checkString(githubOwner, "IMGFLOAT_GITHUB_OWNER", missing);
|
||||
checkString(githubRepo, "IMGFLOAT_GITHUB_REPO", missing);
|
||||
checkString(githubClientOwner, "IMGFLOAT_GITHUB_CLIENT_OWNER", missing);
|
||||
checkString(githubClientRepo, "IMGFLOAT_GITHUB_CLIENT_REPO", missing);
|
||||
checkString(githubClientVersion, "IMGFLOAT_GITHUB_CLIENT_VERSION", missing);
|
||||
|
||||
if (!missing.isEmpty()) {
|
||||
throw new IllegalStateException("Missing or invalid environment variables:\n" + missing);
|
||||
@@ -92,8 +96,9 @@ public class SystemEnvironmentValidator {
|
||||
log.info(" - IMGFLOAT_INITIAL_TWITCH_USERNAME_SYSADMIN: {}", initialSysadmin);
|
||||
log.info(" - IMGFLOAT_ASSETS_PATH: {}", assetsPath);
|
||||
log.info(" - IMGFLOAT_PREVIEWS_PATH: {}", previewsPath);
|
||||
log.info(" - IMGFLOAT_GITHUB_OWNER: {}", githubOwner);
|
||||
log.info(" - IMGFLOAT_GITHUB_REPO: {}", githubRepo);
|
||||
log.info(" - IMGFLOAT_GITHUB_CLIENT_OWNER: {}", githubClientOwner);
|
||||
log.info(" - IMGFLOAT_GITHUB_CLIENT_REPO: {}", githubClientRepo);
|
||||
log.info(" - IMGFLOAT_GITHUB_CLIENT_VERSION: {}", githubClientVersion);
|
||||
}
|
||||
|
||||
private void checkString(String value, String name, StringBuilder missing) {
|
||||
|
||||
@@ -154,7 +154,7 @@ public class ViewController {
|
||||
|
||||
private void addVersionAttributes(Model model) {
|
||||
model.addAttribute("version", versionService.getVersion());
|
||||
model.addAttribute("releaseVersion", versionService.getReleaseVersion());
|
||||
model.addAttribute("releaseVersion", githubReleaseService.getClientReleaseVersion());
|
||||
model.addAttribute("downloadBaseUrl", githubReleaseService.getDownloadBaseUrl());
|
||||
model.addAttribute("buildCommitShort", gitInfoService.getShortCommitSha());
|
||||
model.addAttribute("buildCommitUrl", gitInfoService.getCommitUrl());
|
||||
|
||||
@@ -11,35 +11,65 @@ public class GithubReleaseService {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GithubReleaseService.class);
|
||||
|
||||
private final VersionService versionService;
|
||||
private final String githubOwner;
|
||||
private final String githubRepo;
|
||||
private final String githubClientOwner;
|
||||
private final String githubClientRepo;
|
||||
private final String githubClientVersion;
|
||||
|
||||
public GithubReleaseService(
|
||||
VersionService versionService,
|
||||
@Value("${IMGFLOAT_GITHUB_OWNER:#{null}}") String githubOwner,
|
||||
@Value("${IMGFLOAT_GITHUB_REPO:#{null}}") String githubRepo
|
||||
@Value("${IMGFLOAT_GITHUB_CLIENT_OWNER:#{null}}") String githubClientOwner,
|
||||
@Value("${IMGFLOAT_GITHUB_CLIENT_REPO:#{null}}") String githubClientRepo,
|
||||
@Value("${IMGFLOAT_GITHUB_CLIENT_VERSION:#{null}}") String githubClientVersion
|
||||
) {
|
||||
this.versionService = versionService;
|
||||
this.githubOwner = githubOwner;
|
||||
this.githubRepo = githubRepo;
|
||||
this.githubClientOwner = githubClientOwner;
|
||||
this.githubClientRepo = githubClientRepo;
|
||||
this.githubClientVersion = githubClientVersion;
|
||||
}
|
||||
|
||||
public String getDownloadBaseUrl() {
|
||||
validateConfiguration();
|
||||
String releaseTag = versionService.getReleaseTag();
|
||||
String releaseTag = getClientReleaseTag();
|
||||
return String.format(
|
||||
"https://github.com/%s/%s/releases/download/%s/",
|
||||
githubOwner.trim(),
|
||||
githubRepo.trim(),
|
||||
githubClientOwner.trim(),
|
||||
githubClientRepo.trim(),
|
||||
releaseTag
|
||||
);
|
||||
}
|
||||
|
||||
public String getClientReleaseVersion() {
|
||||
validateConfiguration();
|
||||
return normalizeReleaseVersion(githubClientVersion);
|
||||
}
|
||||
|
||||
private String getClientReleaseTag() {
|
||||
String normalized = getClientReleaseVersion();
|
||||
String normalizedVersion = normalized.startsWith("v") ? normalized.substring(1) : normalized;
|
||||
return "v" + normalizedVersion;
|
||||
}
|
||||
|
||||
private void validateConfiguration() {
|
||||
if (!StringUtils.hasText(githubOwner) || !StringUtils.hasText(githubRepo)) {
|
||||
LOG.error("GitHub download configuration is missing (owner={}, repo={})", githubOwner, githubRepo);
|
||||
throw new IllegalStateException("Missing GitHub owner or repo configuration for download links");
|
||||
if (
|
||||
!StringUtils.hasText(githubClientOwner) ||
|
||||
!StringUtils.hasText(githubClientRepo) ||
|
||||
!StringUtils.hasText(githubClientVersion)
|
||||
) {
|
||||
LOG.error(
|
||||
"GitHub client download configuration is missing (owner={}, repo={}, version={})",
|
||||
githubClientOwner,
|
||||
githubClientRepo,
|
||||
githubClientVersion
|
||||
);
|
||||
throw new IllegalStateException("Missing GitHub client configuration for download links");
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizeReleaseVersion(String baseVersion) {
|
||||
String normalized = baseVersion.trim();
|
||||
normalized = normalized.replaceFirst("(?i)^v", "");
|
||||
normalized = normalized.replaceFirst("-SNAPSHOT$", "");
|
||||
if (normalized.isBlank()) {
|
||||
throw new IllegalStateException("Invalid client version: " + baseVersion);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user