Skip to content

Commit def0552

Browse files
authored
fix pipelines via changing to service (#3358)
# Description of Changes Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(issue_number) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
1 parent de9e3ed commit def0552

File tree

5 files changed

+62
-64
lines changed

5 files changed

+62
-64
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ext {
2929
}
3030

3131
group = "stirling.software"
32-
version = "0.45.5"
32+
version = "0.45.6"
3333

3434
java {
3535
// 17 is lowest but we support and recommend 21

src/main/java/stirling/software/SPDF/config/AppConfig.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,33 +109,6 @@ public boolean rateLimit() {
109109
return (rateLimit != null) ? Boolean.valueOf(rateLimit) : false;
110110
}
111111

112-
@Bean(name = "uploadLimit")
113-
public long uploadLimit() {
114-
String maxUploadSize =
115-
applicationProperties.getSystem().getFileUploadLimit() != null
116-
? applicationProperties.getSystem().getFileUploadLimit()
117-
: "";
118-
119-
if (maxUploadSize.isEmpty()) {
120-
return 0;
121-
} else if (!new Regex("^[1-9][0-9]{0,2}[KMGkmg][Bb]$").matches(maxUploadSize)) {
122-
log.error(
123-
"Invalid maxUploadSize format. Expected format: [1-9][0-9]{0,2}[KMGkmg][Bb], but got: {}",
124-
maxUploadSize);
125-
return 0;
126-
} else {
127-
String unit = maxUploadSize.replaceAll("[1-9][0-9]{0,2}", "").toUpperCase();
128-
String number = maxUploadSize.replaceAll("[KMGkmg][Bb]", "");
129-
long size = Long.parseLong(number);
130-
return switch (unit) {
131-
case "KB" -> size * 1024;
132-
case "MB" -> size * 1024 * 1024;
133-
case "GB" -> size * 1024 * 1024 * 1024;
134-
default -> 0;
135-
};
136-
}
137-
}
138-
139112
@Bean(name = "RunningInDocker")
140113
public boolean runningInDocker() {
141114
return Files.exists(Paths.get("/.dockerenv"));

src/main/java/stirling/software/SPDF/controller/web/GlobalUploadLimitWebController.java

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package stirling.software.SPDF.controller.web;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.stereotype.Service;
5+
6+
import lombok.extern.slf4j.Slf4j;
7+
import stirling.software.SPDF.model.ApplicationProperties;
8+
9+
import java.util.regex.Pattern;
10+
11+
@Service
12+
@Slf4j
13+
public class UploadLimitService {
14+
15+
@Autowired
16+
private ApplicationProperties applicationProperties;
17+
18+
public long getUploadLimit() {
19+
String maxUploadSize =
20+
applicationProperties.getSystem().getFileUploadLimit() != null
21+
? applicationProperties.getSystem().getFileUploadLimit()
22+
: "";
23+
24+
if (maxUploadSize.isEmpty()) {
25+
return 0;
26+
} else if (!Pattern.compile("^[1-9][0-9]{0,2}[KMGkmg][Bb]$").matcher(maxUploadSize).matches()) {
27+
log.error(
28+
"Invalid maxUploadSize format. Expected format: [1-9][0-9]{0,2}[KMGkmg][Bb], but got: {}",
29+
maxUploadSize);
30+
return 0;
31+
} else {
32+
String unit = maxUploadSize.replaceAll("[1-9][0-9]{0,2}", "").toUpperCase();
33+
String number = maxUploadSize.replaceAll("[KMGkmg][Bb]", "");
34+
long size = Long.parseLong(number);
35+
return switch (unit) {
36+
case "KB" -> size * 1024;
37+
case "MB" -> size * 1024 * 1024;
38+
case "GB" -> size * 1024 * 1024 * 1024;
39+
default -> 0;
40+
};
41+
}
42+
}
43+
44+
//TODO: why do this server side not client?
45+
public String getReadableUploadLimit() {
46+
return humanReadableByteCount(getUploadLimit());
47+
}
48+
49+
private String humanReadableByteCount(long bytes) {
50+
if (bytes < 1024) return bytes + " B";
51+
int exp = (int) (Math.log(bytes) / Math.log(1024));
52+
String pre = "KMGTPE".charAt(exp - 1) + "B";
53+
return String.format("%.1f %s", bytes / Math.pow(1024, exp), pre);
54+
}
55+
}

src/main/resources/templates/fragments/common.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@
240240
window.stirlingPDF.sessionExpired = /*[[#{session.expired}]]*/ '';
241241
window.stirlingPDF.refreshPage = /*[[#{session.refreshPage}]]*/ 'Refresh Page';
242242
window.stirlingPDF.error = /*[[#{error}]]*/ "Error";
243-
window.stirlingPDF.uploadLimit = /*[[${uploadLimit}]]*/ 0;
244-
window.stirlingPDF.uploadLimitReadable = /*[[${uploadLimitReadable}]]*/ 'Unlimited';
243+
window.stirlingPDF.uploadLimitReadable = /*[[${@uploadLimitService.getReadableUploadLimit()}]]*/ 'Unlimited';
244+
window.stirlingPDF.uploadLimit = /*[[${@uploadLimitService.getUploadLimit()}]]*/ 0;
245245
window.stirlingPDF.uploadLimitExceededSingular = /*[[#{uploadLimitExceededSingular}]]*/ 'is too large. Maximum allowed size is';
246246
window.stirlingPDF.uploadLimitExceededPlural = /*[[#{uploadLimitExceededPlural}]]*/ 'are too large. Maximum allowed size is';
247247
})();
@@ -292,10 +292,10 @@
292292
</div>
293293
</div>
294294
<div class="selected-files flex-wrap"></div>
295-
<div class="text-muted small mt-0 text-end w-100" th:if="${uploadLimit != 0}">
296-
<span th:text="#{uploadLimit}">Maximum file size: </span>
297-
<span th:text="${uploadLimitReadable}"></span>
298-
</div>
295+
<div class="text-muted small mt-0 text-end w-100" th:if="${@uploadLimitService.getUploadLimit() != 0}">
296+
<span th:text="#{uploadLimit}">Maximum file size: </span>
297+
<span th:text="${@uploadLimitService.getReadableUploadLimit()}"></span>
298+
</div>
299299
</div>
300300
<div class="progressBarContainer" style="display: none; position: relative;">
301301
<div class="progress" style="height: 1rem;">

0 commit comments

Comments
 (0)