|
|
@@ -146,11 +146,23 @@ function bytesToGB(bytes: number): number {
|
|
|
return Math.round((bytes / (1024 * 1024 * 1024)) * 100) / 100;
|
|
|
}
|
|
|
|
|
|
-function gbToBytes(gb: number): number {
|
|
|
+export function gbToBytes(gb: number): number {
|
|
|
if (!gb || gb <= 0) return 0;
|
|
|
return Math.round(gb * 1024 * 1024 * 1024);
|
|
|
}
|
|
|
|
|
|
+// The quota field displays whole/2-decimal GB, so a byte total that isn't
|
|
|
+// aligned to 0.01 GB (e.g. one set via the API or an import) would drift on a
|
|
|
+// save that never touched the field. Keep the original byte total when the
|
|
|
+// displayed GB still matches it, and only re-derive from GB when the user
|
|
|
+// actually changed the value.
|
|
|
+export function resolveTotalBytes(originalBytes: number | null | undefined, displayedGB: number): number {
|
|
|
+ if (originalBytes != null && displayedGB === bytesToGB(originalBytes)) {
|
|
|
+ return originalBytes;
|
|
|
+ }
|
|
|
+ return gbToBytes(displayedGB);
|
|
|
+}
|
|
|
+
|
|
|
export default function ClientFormModal({
|
|
|
open,
|
|
|
mode,
|
|
|
@@ -491,6 +503,7 @@ export default function ClientFormModal({
|
|
|
const expiryTime = values.delayedStart
|
|
|
? -86400000 * (Number(values.delayedDays) || 0)
|
|
|
: (values.expiryDate || 0);
|
|
|
+ const totalBytes = resolveTotalBytes(client ? (client.totalGB ?? 0) : null, values.totalGB);
|
|
|
const clientPayload: Record<string, unknown> = {
|
|
|
email: values.email.trim(),
|
|
|
subId: values.subId,
|
|
|
@@ -499,7 +512,7 @@ export default function ClientFormModal({
|
|
|
auth: values.auth,
|
|
|
flow: showFlow ? (values.flow || '') : '',
|
|
|
security: showSecurity ? (values.security || 'auto') : 'auto',
|
|
|
- totalGB: gbToBytes(values.totalGB),
|
|
|
+ totalGB: totalBytes,
|
|
|
expiryTime,
|
|
|
reset: Number(values.reset) || 0,
|
|
|
limitIp: Number(values.limitIp) || 0,
|