mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Specify proper env vars
This commit is contained in:
10
Makefile
10
Makefile
@@ -4,8 +4,9 @@
|
||||
.DEFAULT_GOAL := build
|
||||
|
||||
IMGFLOAT_DB_PATH ?= ./imgfloat.db
|
||||
IMGFLOAT_GITHUB_OWNER ?= imgfloat
|
||||
IMGFLOAT_GITHUB_REPO ?= client
|
||||
IMGFLOAT_GITHUB_CLIENT_OWNER ?= imgfloat
|
||||
IMGFLOAT_GITHUB_CLIENT_REPO ?= client
|
||||
IMGFLOAT_GITHUB_CLIENT_VERSION ?= 1.0.0
|
||||
IMGFLOAT_ASSETS_PATH ?= ./assets
|
||||
IMGFLOAT_PREVIEWS_PATH ?= ./previews
|
||||
SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE ?= 10MB
|
||||
@@ -13,8 +14,9 @@ SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE ?= 10MB
|
||||
WATCHDIR = ./src/main
|
||||
RUNTIME_ENV = IMGFLOAT_ASSETS_PATH=$(IMGFLOAT_ASSETS_PATH) \
|
||||
IMGFLOAT_PREVIEWS_PATH=$(IMGFLOAT_PREVIEWS_PATH) \
|
||||
IMGFLOAT_GITHUB_OWNER=$(IMGFLOAT_GITHUB_OWNER) \
|
||||
IMGFLOAT_GITHUB_REPO=$(IMGFLOAT_GITHUB_REPO) \
|
||||
IMGFLOAT_GITHUB_CLIENT_OWNER=$(IMGFLOAT_GITHUB_CLIENT_OWNER) \
|
||||
IMGFLOAT_GITHUB_CLIENT_REPO=$(IMGFLOAT_GITHUB_CLIENT_REPO) \
|
||||
IMGFLOAT_GITHUB_CLIENT_VERSION=$(IMGFLOAT_GITHUB_CLIENT_VERSION) \
|
||||
IMGFLOAT_DB_PATH=$(IMGFLOAT_DB_PATH) \
|
||||
SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE=$(SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE) \
|
||||
SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE=$(SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE)
|
||||
|
||||
12
README.md
12
README.md
@@ -14,12 +14,11 @@ Define the following required environment variables:
|
||||
| `IMGFLOAT_PREVIEWS_PATH` | Filesystem path to store generated image previews | /var/imgfloat/previews |
|
||||
| `IMGFLOAT_DB_PATH` | Filesystem path to the SQLite database file | /var/imgfloat/imgfloat.db |
|
||||
| `IMGFLOAT_INITIAL_TWITCH_USERNAME_SYSADMIN` | Twitch username of the initial sysadmin user | example_broadcaster |
|
||||
| `IMGFLOAT_GITHUB_OWNER` | Github user or org which has the client repository | Kruhlmann |
|
||||
| `IMGFLOAT_GITHUB_REPO` | Client repository name | imgfloat-j |
|
||||
| `IMGFLOAT_GITHUB_CLIENT_OWNER` | GitHub user or org which has the client repository | imgfloat |
|
||||
| `IMGFLOAT_GITHUB_CLIENT_REPO` | Client repository name | client |
|
||||
| `IMGFLOAT_GITHUB_CLIENT_VERSION` | Client release version used for download links | 1.2.3 |
|
||||
| `SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE` | Maximum upload file size | 10MB |
|
||||
| `SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE` | Maximum upload request size | 10MB |
|
||||
| `IMGFLOAT_GITHUB_OWNER` | GitHub owner used to build desktop download links | Kruhlmann |
|
||||
| `IMGFLOAT_GITHUB_REPO` | GitHub repo used to build desktop download links | imgfloat-j |
|
||||
| `TWITCH_CLIENT_ID` | Oauth2 client id | i1bjnh4whieht5kzn307nvu3rn5pqi |
|
||||
| `TWITCH_CLIENT_SECRET` | Oauth2 client secret | vpkn8cp7ona65l121j6q78l9gkmed3 |
|
||||
|
||||
@@ -36,8 +35,9 @@ If you want to use the default development setup your `.env` file should look li
|
||||
```sh
|
||||
TWITCH_CLIENT_ID=...
|
||||
TWITCH_CLIENT_SECRET=...
|
||||
IMGFLOAT_GITHUB_OWNER=...
|
||||
IMGFLOAT_GITHUB_REPO=...
|
||||
IMGFLOAT_GITHUB_CLIENT_OWNER=...
|
||||
IMGFLOAT_GITHUB_CLIENT_REPO=...
|
||||
IMGFLOAT_GITHUB_CLIENT_VERSION=...
|
||||
IMGFLOAT_INITIAL_TWITCH_USERNAME_SYSADMIN=...
|
||||
```
|
||||
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
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");
|
||||
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(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