diff --git a/frontend/src/components/prompts/UploadFiles.vue b/frontend/src/components/prompts/UploadFiles.vue
index 883fffe3..4d96d5bb 100644
--- a/frontend/src/components/prompts/UploadFiles.vue
+++ b/frontend/src/components/prompts/UploadFiles.vue
@@ -14,7 +14,7 @@
}}
-
{{ speedMbytes }}/s
+
{{ speedText }}/s
{{ formattedETA }} remaining
{{ sentPercent }}% Completed
@@ -88,6 +88,7 @@ const uploadStore = useUploadStore();
const { sentBytes, totalBytes } = storeToRefs(uploadStore);
const byteToMbyte = partial({ exponent: 2 });
+const byteToKbyte = partial({ exponent: 1 });
const sentPercent = computed(() =>
((uploadStore.sentBytes / uploadStore.totalBytes) * 100).toFixed(2)
@@ -95,11 +96,33 @@ const sentPercent = computed(() =>
const sentMbytes = computed(() => byteToMbyte(uploadStore.sentBytes));
const totalMbytes = computed(() => byteToMbyte(uploadStore.totalBytes));
-const speedMbytes = computed(() => byteToMbyte(speed.value));
+const speedText = computed(() => {
+ const bytes = speed.value;
+
+ if (bytes < 1024 * 1024) {
+ const kb = parseFloat(byteToKbyte(bytes));
+ return `${kb.toFixed(2)} KB`;
+ } else {
+ const mb = parseFloat(byteToMbyte(bytes));
+ return `${mb.toFixed(2)} MB`;
+ }
+});
let lastSpeedUpdate: number = 0;
let recentSpeeds: number[] = [];
+let lastThrottleTime = 0;
+
+const throttledCalculateSpeed = (sentBytes: number, oldSentBytes: number) => {
+ const now = Date.now();
+ if (now - lastThrottleTime < 100) {
+ return;
+ }
+
+ lastThrottleTime = now;
+ calculateSpeed(sentBytes, oldSentBytes);
+};
+
const calculateSpeed = (sentBytes: number, oldSentBytes: number) => {
// Reset the state when the uploads batch is complete
if (sentBytes === 0) {
@@ -149,7 +172,7 @@ const calculateEta = () => {
eta.value = remainingSize / speedBytesPerSecond;
};
-watch(sentBytes, calculateSpeed);
+watch(sentBytes, throttledCalculateSpeed);
watch(totalBytes, (totalBytes, oldTotalBytes) => {
if (oldTotalBytes !== 0) {
diff --git a/http/auth.go b/http/auth.go
index 62d6779e..18d10025 100644
--- a/http/auth.go
+++ b/http/auth.go
@@ -21,16 +21,16 @@ const (
)
type userInfo struct {
- ID uint `json:"id"`
- Locale string `json:"locale"`
- ViewMode users.ViewMode `json:"viewMode"`
- SingleClick bool `json:"singleClick"`
- Perm users.Permissions `json:"perm"`
- Commands []string `json:"commands"`
- LockPassword bool `json:"lockPassword"`
- HideDotfiles bool `json:"hideDotfiles"`
- DateFormat bool `json:"dateFormat"`
- Username string `json:"username"`
+ ID uint `json:"id"`
+ Locale string `json:"locale"`
+ ViewMode users.ViewMode `json:"viewMode"`
+ SingleClick bool `json:"singleClick"`
+ Perm users.Permissions `json:"perm"`
+ Commands []string `json:"commands"`
+ LockPassword bool `json:"lockPassword"`
+ HideDotfiles bool `json:"hideDotfiles"`
+ DateFormat bool `json:"dateFormat"`
+ Username string `json:"username"`
AceEditorTheme string `json:"aceEditorTheme"`
}
@@ -191,16 +191,16 @@ func renewHandler(tokenExpireTime time.Duration) handleFunc {
func printToken(w http.ResponseWriter, _ *http.Request, d *data, user *users.User, tokenExpirationTime time.Duration) (int, error) {
claims := &authToken{
User: userInfo{
- ID: user.ID,
- Locale: user.Locale,
- ViewMode: user.ViewMode,
- SingleClick: user.SingleClick,
- Perm: user.Perm,
- LockPassword: user.LockPassword,
- Commands: user.Commands,
- HideDotfiles: user.HideDotfiles,
- DateFormat: user.DateFormat,
- Username: user.Username,
+ ID: user.ID,
+ Locale: user.Locale,
+ ViewMode: user.ViewMode,
+ SingleClick: user.SingleClick,
+ Perm: user.Perm,
+ LockPassword: user.LockPassword,
+ Commands: user.Commands,
+ HideDotfiles: user.HideDotfiles,
+ DateFormat: user.DateFormat,
+ Username: user.Username,
AceEditorTheme: user.AceEditorTheme,
},
RegisteredClaims: jwt.RegisteredClaims{