mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-06 18:30:57 +00:00
Create the global upload limit controller
This controller will allow for every page and template to load the variables used for upload limit displaying and enforcing
This commit is contained in:
parent
b3ff105343
commit
d973cde255
@ -0,0 +1,30 @@
|
|||||||
|
package stirling.software.SPDF.controller.web;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@ControllerAdvice
|
||||||
|
public class GlobalUploadLimitWebController {
|
||||||
|
|
||||||
|
@Autowired() private long uploadLimit;
|
||||||
|
|
||||||
|
@ModelAttribute("uploadLimit")
|
||||||
|
public long populateUploadLimit() {
|
||||||
|
return uploadLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("uploadLimitReadable")
|
||||||
|
public String populateReadableLimit() {
|
||||||
|
return humanReadableByteCount(uploadLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String humanReadableByteCount(long bytes) {
|
||||||
|
if (bytes < 1024) return bytes + " B";
|
||||||
|
int exp = (int) (Math.log(bytes) / Math.log(1024));
|
||||||
|
String pre = "KMGTPE".charAt(exp - 1) + "B";
|
||||||
|
return String.format("%.1f %s", bytes / Math.pow(1024, exp), pre);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user