Add quota changes to frontend usage bar
This commit is contained in:
parent
5c479c9b58
commit
58e48a449e
@ -90,9 +90,9 @@
|
|||||||
v-if="isFiles && !disableUsedPercentage"
|
v-if="isFiles && !disableUsedPercentage"
|
||||||
style="width: 90%; margin: 2em 2.5em 3em 2.5em"
|
style="width: 90%; margin: 2em 2.5em 3em 2.5em"
|
||||||
>
|
>
|
||||||
<progress-bar :val="usage.usedPercentage" size="small"></progress-bar>
|
<progress-bar :val="usagePercentage" size="small"></progress-bar>
|
||||||
<br />
|
<br />
|
||||||
{{ usage.used }} of {{ usage.total }} used
|
{{ usedFormatted }} of {{ totalFormatted }} used
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p class="credits">
|
<p class="credits">
|
||||||
@ -161,6 +161,37 @@ export default {
|
|||||||
disableExternal: () => disableExternal,
|
disableExternal: () => disableExternal,
|
||||||
disableUsedPercentage: () => disableUsedPercentage,
|
disableUsedPercentage: () => disableUsedPercentage,
|
||||||
canLogout: () => !noAuth && (loginPage || logoutPage !== "/login"),
|
canLogout: () => !noAuth && (loginPage || logoutPage !== "/login"),
|
||||||
|
hasQuotaData() {
|
||||||
|
return this.user?.quotaLimit && this.user.quotaLimit > 0;
|
||||||
|
},
|
||||||
|
quotaLimitBytes() {
|
||||||
|
// QuotaLimit is already stored in bytes in the backend
|
||||||
|
return this.user?.quotaLimit || 0;
|
||||||
|
},
|
||||||
|
quotaUsedBytes() {
|
||||||
|
// QuotaUsed is already in bytes
|
||||||
|
return this.user?.quotaUsed || 0;
|
||||||
|
},
|
||||||
|
// Unified properties that use quota if available, otherwise disk usage
|
||||||
|
usagePercentage() {
|
||||||
|
if (this.hasQuotaData) {
|
||||||
|
if (this.quotaLimitBytes === 0) return 0;
|
||||||
|
return Math.min(Math.round((this.quotaUsedBytes / this.quotaLimitBytes) * 100), 100);
|
||||||
|
}
|
||||||
|
return this.usage.usedPercentage;
|
||||||
|
},
|
||||||
|
usedFormatted() {
|
||||||
|
if (this.hasQuotaData) {
|
||||||
|
return prettyBytes(this.quotaUsedBytes, { binary: true });
|
||||||
|
}
|
||||||
|
return this.usage.used;
|
||||||
|
},
|
||||||
|
totalFormatted() {
|
||||||
|
if (this.hasQuotaData) {
|
||||||
|
return prettyBytes(this.quotaLimitBytes, { binary: true });
|
||||||
|
}
|
||||||
|
return this.usage.total;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(useLayoutStore, ["closeHovers", "showHover"]),
|
...mapActions(useLayoutStore, ["closeHovers", "showHover"]),
|
||||||
@ -168,6 +199,11 @@ export default {
|
|||||||
this.usageAbortController.abort();
|
this.usageAbortController.abort();
|
||||||
},
|
},
|
||||||
async fetchUsage() {
|
async fetchUsage() {
|
||||||
|
// If user has quota, don't fetch disk usage
|
||||||
|
if (this.hasQuotaData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const path = this.$route.path.endsWith("/")
|
const path = this.$route.path.endsWith("/")
|
||||||
? this.$route.path
|
? this.$route.path
|
||||||
: this.$route.path + "/";
|
: this.$route.path + "/";
|
||||||
|
|||||||
21
http/auth.go
21
http/auth.go
@ -34,6 +34,10 @@ type userInfo struct {
|
|||||||
DateFormat bool `json:"dateFormat"`
|
DateFormat bool `json:"dateFormat"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
AceEditorTheme string `json:"aceEditorTheme"`
|
AceEditorTheme string `json:"aceEditorTheme"`
|
||||||
|
QuotaLimit uint64 `json:"quotaLimit"`
|
||||||
|
QuotaUnit string `json:"quotaUnit"`
|
||||||
|
EnforceQuota bool `json:"enforceQuota"`
|
||||||
|
QuotaUsed uint64 `json:"quotaUsed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type authToken struct {
|
type authToken struct {
|
||||||
@ -202,6 +206,19 @@ func renewHandler(tokenExpireTime time.Duration) handleFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printToken(w http.ResponseWriter, _ *http.Request, d *data, user *users.User, tokenExpirationTime time.Duration) (int, error) {
|
func printToken(w http.ResponseWriter, _ *http.Request, d *data, user *users.User, tokenExpirationTime time.Duration) (int, error) {
|
||||||
|
// Calculate current quota usage if quota is enabled
|
||||||
|
var quotaUsed uint64
|
||||||
|
if user.QuotaLimit > 0 {
|
||||||
|
used, err := users.CalculateUserQuota(user.Fs, user.Scope)
|
||||||
|
if err != nil {
|
||||||
|
// Log error but don't fail login - just set usage to 0
|
||||||
|
log.Printf("Failed to calculate quota for user %s: %v", user.Username, err)
|
||||||
|
quotaUsed = 0
|
||||||
|
} else {
|
||||||
|
quotaUsed = used
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
claims := &authToken{
|
claims := &authToken{
|
||||||
User: userInfo{
|
User: userInfo{
|
||||||
ID: user.ID,
|
ID: user.ID,
|
||||||
@ -215,6 +232,10 @@ func printToken(w http.ResponseWriter, _ *http.Request, d *data, user *users.Use
|
|||||||
DateFormat: user.DateFormat,
|
DateFormat: user.DateFormat,
|
||||||
Username: user.Username,
|
Username: user.Username,
|
||||||
AceEditorTheme: user.AceEditorTheme,
|
AceEditorTheme: user.AceEditorTheme,
|
||||||
|
QuotaLimit: user.QuotaLimit,
|
||||||
|
QuotaUnit: user.QuotaUnit,
|
||||||
|
EnforceQuota: user.EnforceQuota,
|
||||||
|
QuotaUsed: quotaUsed,
|
||||||
},
|
},
|
||||||
RegisteredClaims: jwt.RegisteredClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user